Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mysten/kiosk

Package Overview
Dependencies
Maintainers
4
Versions
326
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mysten/kiosk - npm Package Compare versions

Comparing version 0.0.0-experimental-20230531161644 to 0.0.0-experimental-20230602192304

dist/constants.d.ts

175

./dist/index.js

@@ -23,8 +23,16 @@ "use strict";

__export(src_exports, {
KIOSK_ITEM: () => KIOSK_ITEM,
KIOSK_LISTING: () => KIOSK_LISTING,
KIOSK_LOCK: () => KIOSK_LOCK,
KIOSK_LOCK_RULE: () => KIOSK_LOCK_RULE,
KIOSK_MODULE: () => KIOSK_MODULE,
KIOSK_OWNER_CAP: () => KIOSK_OWNER_CAP,
KIOSK_PURCHASE_CAP: () => KIOSK_PURCHASE_CAP,
KIOSK_TYPE: () => KIOSK_TYPE,
MAINNET_RULES_PACKAGE_ADDRESS: () => MAINNET_RULES_PACKAGE_ADDRESS,
ROYALTY_RULE: () => ROYALTY_RULE,
TESTNET_RULES_PACKAGE_ADDRESS: () => TESTNET_RULES_PACKAGE_ADDRESS,
TRANSFER_POLICY_CREATED_EVENT: () => TRANSFER_POLICY_CREATED_EVENT,
TRANSFER_POLICY_MODULE: () => TRANSFER_POLICY_MODULE,
TRANSFER_POLICY_RULES_PACKAGE_ADDRESS: () => TRANSFER_POLICY_RULES_PACKAGE_ADDRESS,
TRANSFER_POLICY_TYPE: () => TRANSFER_POLICY_TYPE,
attachListingsAndPrices: () => attachListingsAndPrices,

@@ -40,2 +48,3 @@ attachLockedItems: () => attachLockedItems,

createTransferPolicy: () => createTransferPolicy,
customEnvironment: () => customEnvironment,
delist: () => delist,

@@ -45,5 +54,7 @@ extractKioskData: () => extractKioskData,

getKioskObject: () => getKioskObject,
getRulePackageAddress: () => getRulePackageAddress,
getTypeWithoutPackageAddress: () => getTypeWithoutPackageAddress,
list: () => list,
lock: () => lock,
mainnetEnvironment: () => mainnetEnvironment,
objArg: () => objArg,

@@ -56,5 +67,8 @@ place: () => place,

removeTransferPolicyRule: () => removeTransferPolicyRule,
resolveKioskLockRule: () => resolveKioskLockRule,
resolveRoyaltyRule: () => resolveRoyaltyRule,
returnValue: () => returnValue,
rulesPackageAddresses: () => rulesPackageAddresses,
take: () => take,
testnetEnvironment: () => testnetEnvironment,
withdrawFromKiosk: () => withdrawFromKiosk,

@@ -70,3 +84,29 @@ withdrawFromPolicy: () => withdrawFromPolicy

var import_sui = require("@mysten/sui.js");
import_sui.bcs.registerStructType("0x2::kiosk::Kiosk", {
// src/types/kiosk.ts
var KIOSK_MODULE = "0x2::kiosk";
var KIOSK_TYPE = `${KIOSK_MODULE}::Kiosk`;
var KIOSK_OWNER_CAP = `${KIOSK_MODULE}::KioskOwnerCap`;
var KIOSK_ITEM = `${KIOSK_MODULE}::Item`;
var KIOSK_LISTING = `${KIOSK_MODULE}::Listing`;
var KIOSK_LOCK = `${KIOSK_MODULE}::Lock`;
var KIOSK_PURCHASE_CAP = `${KIOSK_MODULE}::PurchaseCap`;
// src/types/transfer-policy.ts
var TRANSFER_POLICY_MODULE = "0x2::transfer_policy";
var TRANSFER_POLICY_CREATED_EVENT = `${TRANSFER_POLICY_MODULE}::TransferPolicyCreated`;
var TRANSFER_POLICY_TYPE = `${TRANSFER_POLICY_MODULE}::TransferPolicy`;
var KIOSK_LOCK_RULE = "kiosk_lock_rule::Rule";
var ROYALTY_RULE = "royalty_rule::Rule";
// src/types/env.ts
var testnetEnvironment = { env: "testnet" };
var mainnetEnvironment = { env: "mainnet" };
var customEnvironment = (address) => ({
env: "custom",
address
});
// src/bcs.ts
import_sui.bcs.registerStructType(KIOSK_TYPE, {
id: "address",

@@ -78,3 +118,3 @@ profits: "u64",

});
import_sui.bcs.registerStructType("0x2::kiosk::PurchaseCap", {
import_sui.bcs.registerStructType(KIOSK_PURCHASE_CAP, {
id: "address",

@@ -85,6 +125,6 @@ kioskId: "address",

});
import_sui.bcs.registerStructType("0x2::transfer_policy::TransferPolicyCreated", {
import_sui.bcs.registerStructType(TRANSFER_POLICY_CREATED_EVENT, {
id: "address"
});
import_sui.bcs.registerStructType("0x2::transfer_policy::TransferPolicy", {
import_sui.bcs.registerStructType(TRANSFER_POLICY_TYPE, {
id: "address",

@@ -95,3 +135,13 @@ balance: "u64",

// src/constants.ts
var TESTNET_RULES_PACKAGE_ADDRESS = "bd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585";
var MAINNET_RULES_PACKAGE_ADDRESS = "0x434b5bd8f6a7b05fede0ff46c6e511d71ea326ed38056e3bcd681d2d7c2a7879";
// src/utils.ts
var rulesPackageAddresses = {
mainnet: MAINNET_RULES_PACKAGE_ADDRESS,
testnet: TESTNET_RULES_PACKAGE_ADDRESS,
devnet: "",
custom: null
};
function objArg(tx, arg) {

@@ -120,3 +170,3 @@ if (typeof arg === "string") {

}
return import_sui.bcs.de("0x2::kiosk::Kiosk", queryRes.data.bcs.bcsBytes, "base64");
return import_sui.bcs.de(KIOSK_TYPE, queryRes.data.bcs.bcsBytes, "base64");
}

@@ -153,6 +203,6 @@ function extractKioskData(data, listings, lockedItemIds) {

}
var getTypeWithoutPackageAddress = (type) => {
function getTypeWithoutPackageAddress(type) {
return type.split("::").slice(-2).join("::");
};
var attachListingsAndPrices = (kioskData, listings, listingObjects) => {
}
function attachListingsAndPrices(kioskData, listings, listingObjects) {
const itemListings = listings.reduce(

@@ -174,4 +224,4 @@ (acc, item, idx) => {

});
};
var attachLockedItems = (kioskData, lockedItemIds) => {
}
function attachLockedItems(kioskData, lockedItemIds) {
const lockedStatuses = lockedItemIds.reduce(

@@ -187,7 +237,13 @@ (acc, item) => {

});
};
}
function getRulePackageAddress(environment) {
if (environment.env === "custom") {
if (!environment.address)
throw new Error("Please supply the custom package address for rules.");
return environment.address;
}
return rulesPackageAddresses[environment.env];
}
// src/tx/transfer-policy.ts
var TRANSFER_POLICY_MODULE = "0x2::transfer_policy";
var TRANSFER_POLICY_RULES_PACKAGE_ADDRESS = "bd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585";
function createTransferPolicy(tx, itemType, publisher) {

@@ -207,3 +263,3 @@ let [transferPolicy, transferPolicyCap] = tx.moveCall({

function withdrawFromPolicy(tx, itemType, policy, policyCap, amount) {
let amountArg = amount !== null ? tx.pure(amount, "Option<u64>") : tx.pure({ None: true }, "Option<u64>");
let amountArg = amount !== null ? tx.pure({ Some: amount }, "Option<u64>") : tx.pure({ None: true }, "Option<u64>");
let [profits] = tx.moveCall({

@@ -230,6 +286,6 @@ target: `${TRANSFER_POLICY_MODULE}::withdraw`,

}
function resolveRoyaltyRule(tx, itemType, price, policyId, transferRequest) {
function resolveRoyaltyRule(tx, itemType, price, policyId, transferRequest, environment) {
const policyObj = objArg(tx, policyId);
const [amount] = tx.moveCall({
target: `${TRANSFER_POLICY_RULES_PACKAGE_ADDRESS}::royalty_rule::fee_amount`,
target: `${getRulePackageAddress(environment)}::royalty_rule::fee_amount`,
typeArguments: [itemType],

@@ -240,3 +296,3 @@ arguments: [policyObj, objArg(tx, price)]

tx.moveCall({
target: `${TRANSFER_POLICY_RULES_PACKAGE_ADDRESS}::royalty_rule::pay`,
target: `${getRulePackageAddress(environment)}::royalty_rule::pay`,
typeArguments: [itemType],

@@ -246,7 +302,12 @@ arguments: [policyObj, transferRequest, feeCoin]

}
function resolveKioskLockRule(tx, itemType, item, kiosk, kioskCap, policyId, transferRequest, environment) {
lock(tx, itemType, kiosk, kioskCap, policyId, item);
tx.moveCall({
target: `${getRulePackageAddress(environment)}::kiosk_lock_rule::prove`,
typeArguments: [itemType],
arguments: [transferRequest, objArg(tx, kiosk)]
});
}
// src/tx/kiosk.ts
var KIOSK_MODULE = "0x2::kiosk";
var KIOSK_TYPE = `${KIOSK_MODULE}::Kiosk`;
var KIOSK_OWNER_CAP = `${KIOSK_MODULE}::KioskOwnerCap`;
function createKiosk(tx) {

@@ -348,3 +409,8 @@ let [kiosk, kioskOwnerCap] = tx.moveCall({

function withdrawFromKiosk(tx, kiosk, kioskCap, amount) {
let amountArg = amount !== null ? tx.pure(amount, "Option<u64>") : tx.pure({ None: true }, "Option<u64>");
let amountArg = amount !== null ? tx.pure(
{
Some: amount
},
"Option<u64>"
) : tx.pure({ None: true }, "Option<u64>");
let [coin] = tx.moveCall({

@@ -399,25 +465,44 @@ target: `${KIOSK_MODULE}::withdraw`,

}
function purchaseAndResolvePolicies(tx, itemType, listing, kioskId, itemId, policy) {
if (!listing || listing?.price === void 0)
return null;
const coin = tx.splitCoins(tx.gas, [tx.pure(listing.price)]);
function purchaseAndResolvePolicies(tx, itemType, price, kiosk, itemId, policy, environment, extraParams) {
if (price === void 0 || typeof price !== "string")
throw new Error(`Price of the listing is not supplied.`);
const coin = tx.splitCoins(tx.gas, [tx.pure(price, "u64")]);
const [purchasedItem, transferRequest] = purchase(
tx,
itemType,
kioskId,
kiosk,
itemId,
coin
);
let hasKioskLockRule = false;
for (let rule of policy.rules) {
const ruleWithoutAddr = getTypeWithoutPackageAddress(rule);
switch (ruleWithoutAddr) {
case "royalty_rule::Rule":
case ROYALTY_RULE:
resolveRoyaltyRule(
tx,
itemType,
listing.price,
price,
policy.id,
transferRequest
transferRequest,
environment
);
break;
case KIOSK_LOCK_RULE:
if (!extraParams?.ownedKiosk || !extraParams?.ownedKioskCap)
throw new Error(
`This item type ${itemType} has a 'kiosk_lock_rule', but function call is missing user's kiosk and kioskCap params`
);
hasKioskLockRule = true;
resolveKioskLockRule(
tx,
itemType,
purchasedItem,
extraParams.ownedKiosk,
extraParams.ownedKioskCap,
policy.id,
transferRequest,
environment
);
break;
default:

@@ -428,3 +513,6 @@ break;

confirmRequest(tx, itemType, policy.id, transferRequest);
return purchasedItem;
return {
item: purchasedItem,
canTransfer: !hasKioskLockRule
};
}

@@ -462,3 +550,2 @@

// src/query/transfer-policy.ts
var TRANSFER_POLICY_CREATED_EVENT = `0x2::transfer_policy::TransferPolicyCreated`;
async function queryTransferPolicy(provider, type) {

@@ -481,10 +568,6 @@ const { data } = await provider.queryEvents({

}
let parsed = import_sui.bcs.de(
"0x2::transfer_policy::TransferPolicy",
policy.bcs.bcsBytes,
"base64"
);
let parsed = import_sui.bcs.de(TRANSFER_POLICY_TYPE, policy.bcs.bcsBytes, "base64");
return {
id: policy?.objectId,
type: `0x2::transfer_policy::TransferPolicy<${type}>`,
type: `${TRANSFER_POLICY_TYPE}<${type}>`,
owner: policy?.owner,

@@ -498,8 +581,16 @@ rules: parsed.rules,

0 && (module.exports = {
KIOSK_ITEM,
KIOSK_LISTING,
KIOSK_LOCK,
KIOSK_LOCK_RULE,
KIOSK_MODULE,
KIOSK_OWNER_CAP,
KIOSK_PURCHASE_CAP,
KIOSK_TYPE,
MAINNET_RULES_PACKAGE_ADDRESS,
ROYALTY_RULE,
TESTNET_RULES_PACKAGE_ADDRESS,
TRANSFER_POLICY_CREATED_EVENT,
TRANSFER_POLICY_MODULE,
TRANSFER_POLICY_RULES_PACKAGE_ADDRESS,
TRANSFER_POLICY_TYPE,
attachListingsAndPrices,

@@ -515,2 +606,3 @@ attachLockedItems,

createTransferPolicy,
customEnvironment,
delist,

@@ -520,5 +612,7 @@ extractKioskData,

getKioskObject,
getRulePackageAddress,
getTypeWithoutPackageAddress,
list,
lock,
mainnetEnvironment,
objArg,

@@ -531,5 +625,8 @@ place,

removeTransferPolicyRule,
resolveKioskLockRule,
resolveRoyaltyRule,
returnValue,
rulesPackageAddresses,
take,
testnetEnvironment,
withdrawFromKiosk,

@@ -536,0 +633,0 @@ withdrawFromPolicy

# @mysten/kiosk
## 0.0.0-experimental-20230531161644
## 0.0.0-experimental-20230602192304
### Minor Changes
- 968304368d: Support kiosk_lock_rule and environment support for rules package. Breaks `purchaseAndResolvePolicies` as it changes signature and return format.
## 0.2.0
### Minor Changes
- c322a230da: Fix fetchKiosk consistency/naming, include locked state in items
## 1.0.0
## 0.1.0
### Major Changes
### Minor Changes

@@ -13,0 +19,0 @@ - 4ea96d909a: Kiosk SDK for managing, querying and interacting with Kiosk and TransferPolicy objects

@@ -1,33 +0,2 @@

import { ObjectOwner, bcs } from '@mysten/sui.js';
/**
* The Kiosk object fields (for BCS queries).
*/
export type Kiosk = {
id: string;
profits: string;
owner: string;
itemCount: number;
allowExtensions: boolean;
};
/**
* PurchaseCap object fields (for BCS queries).
*/
export type PurchaseCap = {
id: string;
kioskId: string;
itemId: string;
minPrice: string;
};
/** Event emitted when a TransferPolicy is created. */
export type TransferPolicyCreated = {
id: string;
};
/** The `TransferPolicy` object */
export type TransferPolicy = {
id: string;
type: string;
balance: string;
rules: string[];
owner: ObjectOwner;
};
import { bcs } from '@mysten/sui.js';
export { bcs };

@@ -7,1 +7,3 @@ export * from './tx/kiosk';

export * from './query/transfer-policy';
export * from './types';
export * from './constants';

@@ -23,8 +23,16 @@ "use strict";

__export(src_exports, {
KIOSK_ITEM: () => KIOSK_ITEM,
KIOSK_LISTING: () => KIOSK_LISTING,
KIOSK_LOCK: () => KIOSK_LOCK,
KIOSK_LOCK_RULE: () => KIOSK_LOCK_RULE,
KIOSK_MODULE: () => KIOSK_MODULE,
KIOSK_OWNER_CAP: () => KIOSK_OWNER_CAP,
KIOSK_PURCHASE_CAP: () => KIOSK_PURCHASE_CAP,
KIOSK_TYPE: () => KIOSK_TYPE,
MAINNET_RULES_PACKAGE_ADDRESS: () => MAINNET_RULES_PACKAGE_ADDRESS,
ROYALTY_RULE: () => ROYALTY_RULE,
TESTNET_RULES_PACKAGE_ADDRESS: () => TESTNET_RULES_PACKAGE_ADDRESS,
TRANSFER_POLICY_CREATED_EVENT: () => TRANSFER_POLICY_CREATED_EVENT,
TRANSFER_POLICY_MODULE: () => TRANSFER_POLICY_MODULE,
TRANSFER_POLICY_RULES_PACKAGE_ADDRESS: () => TRANSFER_POLICY_RULES_PACKAGE_ADDRESS,
TRANSFER_POLICY_TYPE: () => TRANSFER_POLICY_TYPE,
attachListingsAndPrices: () => attachListingsAndPrices,

@@ -40,2 +48,3 @@ attachLockedItems: () => attachLockedItems,

createTransferPolicy: () => createTransferPolicy,
customEnvironment: () => customEnvironment,
delist: () => delist,

@@ -45,5 +54,7 @@ extractKioskData: () => extractKioskData,

getKioskObject: () => getKioskObject,
getRulePackageAddress: () => getRulePackageAddress,
getTypeWithoutPackageAddress: () => getTypeWithoutPackageAddress,
list: () => list,
lock: () => lock,
mainnetEnvironment: () => mainnetEnvironment,
objArg: () => objArg,

@@ -56,5 +67,8 @@ place: () => place,

removeTransferPolicyRule: () => removeTransferPolicyRule,
resolveKioskLockRule: () => resolveKioskLockRule,
resolveRoyaltyRule: () => resolveRoyaltyRule,
returnValue: () => returnValue,
rulesPackageAddresses: () => rulesPackageAddresses,
take: () => take,
testnetEnvironment: () => testnetEnvironment,
withdrawFromKiosk: () => withdrawFromKiosk,

@@ -70,3 +84,29 @@ withdrawFromPolicy: () => withdrawFromPolicy

var import_sui = require("@mysten/sui.js");
import_sui.bcs.registerStructType("0x2::kiosk::Kiosk", {
// src/types/kiosk.ts
var KIOSK_MODULE = "0x2::kiosk";
var KIOSK_TYPE = `${KIOSK_MODULE}::Kiosk`;
var KIOSK_OWNER_CAP = `${KIOSK_MODULE}::KioskOwnerCap`;
var KIOSK_ITEM = `${KIOSK_MODULE}::Item`;
var KIOSK_LISTING = `${KIOSK_MODULE}::Listing`;
var KIOSK_LOCK = `${KIOSK_MODULE}::Lock`;
var KIOSK_PURCHASE_CAP = `${KIOSK_MODULE}::PurchaseCap`;
// src/types/transfer-policy.ts
var TRANSFER_POLICY_MODULE = "0x2::transfer_policy";
var TRANSFER_POLICY_CREATED_EVENT = `${TRANSFER_POLICY_MODULE}::TransferPolicyCreated`;
var TRANSFER_POLICY_TYPE = `${TRANSFER_POLICY_MODULE}::TransferPolicy`;
var KIOSK_LOCK_RULE = "kiosk_lock_rule::Rule";
var ROYALTY_RULE = "royalty_rule::Rule";
// src/types/env.ts
var testnetEnvironment = { env: "testnet" };
var mainnetEnvironment = { env: "mainnet" };
var customEnvironment = (address) => ({
env: "custom",
address
});
// src/bcs.ts
import_sui.bcs.registerStructType(KIOSK_TYPE, {
id: "address",

@@ -78,3 +118,3 @@ profits: "u64",

});
import_sui.bcs.registerStructType("0x2::kiosk::PurchaseCap", {
import_sui.bcs.registerStructType(KIOSK_PURCHASE_CAP, {
id: "address",

@@ -85,6 +125,6 @@ kioskId: "address",

});
import_sui.bcs.registerStructType("0x2::transfer_policy::TransferPolicyCreated", {
import_sui.bcs.registerStructType(TRANSFER_POLICY_CREATED_EVENT, {
id: "address"
});
import_sui.bcs.registerStructType("0x2::transfer_policy::TransferPolicy", {
import_sui.bcs.registerStructType(TRANSFER_POLICY_TYPE, {
id: "address",

@@ -95,3 +135,13 @@ balance: "u64",

// src/constants.ts
var TESTNET_RULES_PACKAGE_ADDRESS = "bd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585";
var MAINNET_RULES_PACKAGE_ADDRESS = "0x434b5bd8f6a7b05fede0ff46c6e511d71ea326ed38056e3bcd681d2d7c2a7879";
// src/utils.ts
var rulesPackageAddresses = {
mainnet: MAINNET_RULES_PACKAGE_ADDRESS,
testnet: TESTNET_RULES_PACKAGE_ADDRESS,
devnet: "",
custom: null
};
function objArg(tx, arg) {

@@ -120,3 +170,3 @@ if (typeof arg === "string") {

}
return import_sui.bcs.de("0x2::kiosk::Kiosk", queryRes.data.bcs.bcsBytes, "base64");
return import_sui.bcs.de(KIOSK_TYPE, queryRes.data.bcs.bcsBytes, "base64");
}

@@ -153,6 +203,6 @@ function extractKioskData(data, listings, lockedItemIds) {

}
var getTypeWithoutPackageAddress = (type) => {
function getTypeWithoutPackageAddress(type) {
return type.split("::").slice(-2).join("::");
};
var attachListingsAndPrices = (kioskData, listings, listingObjects) => {
}
function attachListingsAndPrices(kioskData, listings, listingObjects) {
const itemListings = listings.reduce(

@@ -174,4 +224,4 @@ (acc, item, idx) => {

});
};
var attachLockedItems = (kioskData, lockedItemIds) => {
}
function attachLockedItems(kioskData, lockedItemIds) {
const lockedStatuses = lockedItemIds.reduce(

@@ -187,7 +237,13 @@ (acc, item) => {

});
};
}
function getRulePackageAddress(environment) {
if (environment.env === "custom") {
if (!environment.address)
throw new Error("Please supply the custom package address for rules.");
return environment.address;
}
return rulesPackageAddresses[environment.env];
}
// src/tx/transfer-policy.ts
var TRANSFER_POLICY_MODULE = "0x2::transfer_policy";
var TRANSFER_POLICY_RULES_PACKAGE_ADDRESS = "bd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585";
function createTransferPolicy(tx, itemType, publisher) {

@@ -207,3 +263,3 @@ let [transferPolicy, transferPolicyCap] = tx.moveCall({

function withdrawFromPolicy(tx, itemType, policy, policyCap, amount) {
let amountArg = amount !== null ? tx.pure(amount, "Option<u64>") : tx.pure({ None: true }, "Option<u64>");
let amountArg = amount !== null ? tx.pure({ Some: amount }, "Option<u64>") : tx.pure({ None: true }, "Option<u64>");
let [profits] = tx.moveCall({

@@ -230,6 +286,6 @@ target: `${TRANSFER_POLICY_MODULE}::withdraw`,

}
function resolveRoyaltyRule(tx, itemType, price, policyId, transferRequest) {
function resolveRoyaltyRule(tx, itemType, price, policyId, transferRequest, environment) {
const policyObj = objArg(tx, policyId);
const [amount] = tx.moveCall({
target: `${TRANSFER_POLICY_RULES_PACKAGE_ADDRESS}::royalty_rule::fee_amount`,
target: `${getRulePackageAddress(environment)}::royalty_rule::fee_amount`,
typeArguments: [itemType],

@@ -240,3 +296,3 @@ arguments: [policyObj, objArg(tx, price)]

tx.moveCall({
target: `${TRANSFER_POLICY_RULES_PACKAGE_ADDRESS}::royalty_rule::pay`,
target: `${getRulePackageAddress(environment)}::royalty_rule::pay`,
typeArguments: [itemType],

@@ -246,7 +302,12 @@ arguments: [policyObj, transferRequest, feeCoin]

}
function resolveKioskLockRule(tx, itemType, item, kiosk, kioskCap, policyId, transferRequest, environment) {
lock(tx, itemType, kiosk, kioskCap, policyId, item);
tx.moveCall({
target: `${getRulePackageAddress(environment)}::kiosk_lock_rule::prove`,
typeArguments: [itemType],
arguments: [transferRequest, objArg(tx, kiosk)]
});
}
// src/tx/kiosk.ts
var KIOSK_MODULE = "0x2::kiosk";
var KIOSK_TYPE = `${KIOSK_MODULE}::Kiosk`;
var KIOSK_OWNER_CAP = `${KIOSK_MODULE}::KioskOwnerCap`;
function createKiosk(tx) {

@@ -348,3 +409,8 @@ let [kiosk, kioskOwnerCap] = tx.moveCall({

function withdrawFromKiosk(tx, kiosk, kioskCap, amount) {
let amountArg = amount !== null ? tx.pure(amount, "Option<u64>") : tx.pure({ None: true }, "Option<u64>");
let amountArg = amount !== null ? tx.pure(
{
Some: amount
},
"Option<u64>"
) : tx.pure({ None: true }, "Option<u64>");
let [coin] = tx.moveCall({

@@ -399,25 +465,44 @@ target: `${KIOSK_MODULE}::withdraw`,

}
function purchaseAndResolvePolicies(tx, itemType, listing, kioskId, itemId, policy) {
if (!listing || listing?.price === void 0)
return null;
const coin = tx.splitCoins(tx.gas, [tx.pure(listing.price)]);
function purchaseAndResolvePolicies(tx, itemType, price, kiosk, itemId, policy, environment, extraParams) {
if (price === void 0 || typeof price !== "string")
throw new Error(`Price of the listing is not supplied.`);
const coin = tx.splitCoins(tx.gas, [tx.pure(price, "u64")]);
const [purchasedItem, transferRequest] = purchase(
tx,
itemType,
kioskId,
kiosk,
itemId,
coin
);
let hasKioskLockRule = false;
for (let rule of policy.rules) {
const ruleWithoutAddr = getTypeWithoutPackageAddress(rule);
switch (ruleWithoutAddr) {
case "royalty_rule::Rule":
case ROYALTY_RULE:
resolveRoyaltyRule(
tx,
itemType,
listing.price,
price,
policy.id,
transferRequest
transferRequest,
environment
);
break;
case KIOSK_LOCK_RULE:
if (!extraParams?.ownedKiosk || !extraParams?.ownedKioskCap)
throw new Error(
`This item type ${itemType} has a 'kiosk_lock_rule', but function call is missing user's kiosk and kioskCap params`
);
hasKioskLockRule = true;
resolveKioskLockRule(
tx,
itemType,
purchasedItem,
extraParams.ownedKiosk,
extraParams.ownedKioskCap,
policy.id,
transferRequest,
environment
);
break;
default:

@@ -428,3 +513,6 @@ break;

confirmRequest(tx, itemType, policy.id, transferRequest);
return purchasedItem;
return {
item: purchasedItem,
canTransfer: !hasKioskLockRule
};
}

@@ -462,3 +550,2 @@

// src/query/transfer-policy.ts
var TRANSFER_POLICY_CREATED_EVENT = `0x2::transfer_policy::TransferPolicyCreated`;
async function queryTransferPolicy(provider, type) {

@@ -481,10 +568,6 @@ const { data } = await provider.queryEvents({

}
let parsed = import_sui.bcs.de(
"0x2::transfer_policy::TransferPolicy",
policy.bcs.bcsBytes,
"base64"
);
let parsed = import_sui.bcs.de(TRANSFER_POLICY_TYPE, policy.bcs.bcsBytes, "base64");
return {
id: policy?.objectId,
type: `0x2::transfer_policy::TransferPolicy<${type}>`,
type: `${TRANSFER_POLICY_TYPE}<${type}>`,
owner: policy?.owner,

@@ -498,8 +581,16 @@ rules: parsed.rules,

0 && (module.exports = {
KIOSK_ITEM,
KIOSK_LISTING,
KIOSK_LOCK,
KIOSK_LOCK_RULE,
KIOSK_MODULE,
KIOSK_OWNER_CAP,
KIOSK_PURCHASE_CAP,
KIOSK_TYPE,
MAINNET_RULES_PACKAGE_ADDRESS,
ROYALTY_RULE,
TESTNET_RULES_PACKAGE_ADDRESS,
TRANSFER_POLICY_CREATED_EVENT,
TRANSFER_POLICY_MODULE,
TRANSFER_POLICY_RULES_PACKAGE_ADDRESS,
TRANSFER_POLICY_TYPE,
attachListingsAndPrices,

@@ -515,2 +606,3 @@ attachLockedItems,

createTransferPolicy,
customEnvironment,
delist,

@@ -520,5 +612,7 @@ extractKioskData,

getKioskObject,
getRulePackageAddress,
getTypeWithoutPackageAddress,
list,
lock,
mainnetEnvironment,
objArg,

@@ -531,5 +625,8 @@ place,

removeTransferPolicyRule,
resolveKioskLockRule,
resolveRoyaltyRule,
returnValue,
rulesPackageAddresses,
take,
testnetEnvironment,
withdrawFromKiosk,

@@ -536,0 +633,0 @@ withdrawFromPolicy

import { JsonRpcProvider, ObjectId, ObjectType, PaginationArguments, SuiAddress } from '@mysten/sui.js';
import { Kiosk } from '../bcs';
import { Kiosk } from '../types';
/**

@@ -4,0 +4,0 @@ * A dynamic field `Listing { ID, isExclusive }` attached to the Kiosk.

import { JsonRpcProvider } from '@mysten/sui.js';
import { TransferPolicy } from '../bcs';
/** Name of the event emitted when a TransferPolicy for T is created. */
export declare const TRANSFER_POLICY_CREATED_EVENT = "0x2::transfer_policy::TransferPolicyCreated";
import { TransferPolicy } from '../types';
/**

@@ -6,0 +4,0 @@ * Searches the `TransferPolicy`-s for the given type. The seach is performed via

import { SuiAddress, TransactionArgument, TransactionBlock } from '@mysten/sui.js';
import { ObjectArgument } from '../utils';
import { KioskListing } from '../query/kiosk';
import { TransferPolicy } from '../bcs';
/** The Kiosk module. */
export declare const KIOSK_MODULE = "0x2::kiosk";
/** The Kiosk type. */
export declare const KIOSK_TYPE: string;
/** The Kiosk Owner Cap Type */
export declare const KIOSK_OWNER_CAP: string;
import { ObjectArgument, PurchaseAndResolvePoliciesResponse, PurchaseOptionalParams, RulesEnvironmentParam, TransferPolicy } from '../types';
/**

@@ -90,4 +82,7 @@ * Create a new shared Kiosk and returns the [kiosk, kioskOwnerCap] tuple.

* 2. Resolving all the transfer policies (if any).
* 3. Returns the PurchasedItem OR places the item in the user's kiosk (if there's a kiosk lock policy).
* 3. Returns the item and whether the user can transfer it or not.
*
* If the item can be transferred, there's an extra transaction required by the user
* to transfer it to an address or place it in their kiosk.
*/
export declare function purchaseAndResolvePolicies(tx: TransactionBlock, itemType: string, listing: KioskListing, kioskId: string, itemId: string, policy: TransferPolicy): TransactionArgument | null;
export declare function purchaseAndResolvePolicies(tx: TransactionBlock, itemType: string, price: string, kiosk: ObjectArgument, itemId: SuiAddress, policy: TransferPolicy, environment: RulesEnvironmentParam, extraParams?: PurchaseOptionalParams): PurchaseAndResolvePoliciesResponse;
import { TransactionArgument, TransactionBlock } from '@mysten/sui.js';
import { ObjectArgument } from '../utils';
/** The Transfer Policy module. */
export declare const TRANSFER_POLICY_MODULE = "0x2::transfer_policy";
/** The Transer Policy Rules package address */
export declare const TRANSFER_POLICY_RULES_PACKAGE_ADDRESS = "bd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585";
import { ObjectArgument, RulesEnvironmentParam } from '../types';
/**

@@ -30,2 +26,8 @@ * Call the `transfer_policy::new` function to create a new transfer policy.

*/
export declare function resolveRoyaltyRule(tx: TransactionBlock, itemType: string, price: string, policyId: string, transferRequest: TransactionArgument): void;
export declare function resolveRoyaltyRule(tx: TransactionBlock, itemType: string, price: string, policyId: ObjectArgument, transferRequest: TransactionArgument, environment: RulesEnvironmentParam): void;
/**
* Locks the item in the supplied kiosk and
* proves to the `kiosk_lock` rule that the item was indeed locked,
* by calling the `kiosk_lock_rule::prove` function to resolve it.
*/
export declare function resolveKioskLockRule(tx: TransactionBlock, itemType: string, item: TransactionArgument, kiosk: ObjectArgument, kioskCap: ObjectArgument, policyId: ObjectArgument, transferRequest: TransactionArgument, environment: RulesEnvironmentParam): void;
import { JsonRpcProvider, ObjectId, SharedObjectRef, SuiObjectRef, SuiObjectResponse, TransactionArgument, TransactionBlock } from '@mysten/sui.js';
import { KioskData, KioskListing } from './query/kiosk';
import { DynamicFieldInfo } from '@mysten/sui.js/dist/types/dynamic_fields';
import { Kiosk } from './bcs';
import { Kiosk, RulesEnvironmentParam } from './types';
export declare const rulesPackageAddresses: {
mainnet: string;
testnet: string;
devnet: string;
custom: null;
};
/**
* A valid argument for any of the Kiosk functions.
*/
export type ObjectArgument = string | TransactionArgument | SharedObjectRef | SuiObjectRef;
/**
* Convert any valid input into a TransactionArgument.

@@ -19,10 +21,14 @@ *

export declare function extractKioskData(data: DynamicFieldInfo[], listings: KioskListing[], lockedItemIds: string[]): KioskData;
export declare const getTypeWithoutPackageAddress: (type: string) => string;
export declare function getTypeWithoutPackageAddress(type: string): string;
/**
* A helper that attaches the listing prices to kiosk listings.
*/
export declare const attachListingsAndPrices: (kioskData: KioskData, listings: KioskListing[], listingObjects: SuiObjectResponse[]) => void;
export declare function attachListingsAndPrices(kioskData: KioskData, listings: KioskListing[], listingObjects: SuiObjectResponse[]): void;
/**
* A Helper to attach locked state to items in Kiosk Data.
*/
export declare const attachLockedItems: (kioskData: KioskData, lockedItemIds: ObjectId[]) => void;
export declare function attachLockedItems(kioskData: KioskData, lockedItemIds: ObjectId[]): void;
/**
* A helper to get a rule's environment address.
*/
export declare function getRulePackageAddress(environment: RulesEnvironmentParam): string;

@@ -5,3 +5,3 @@ {

"description": "Sui Kiosk library",
"version": "0.0.0-experimental-20230531161644",
"version": "0.0.0-experimental-20230602192304",
"license": "Apache-2.0",

@@ -8,0 +8,0 @@ "main": "./dist/index.js",

@@ -56,6 +56,6 @@ # Kiosk SDK

<details>
<summary>Purchasing an item (currently supports royalty rule deployed on testnet or no rules)</summary>
<summary>Purchasing an item (currently supports royalty rule, kiosk_lock_rule, no rules, (combination works too))</summary>
```typescript
import { fetchKiosk } from '@mysten/kiosk';
import { queryTransferPolicy, purchaseAndResolvePolicies, place, testnetEnvironment } from '@mysten/kiosk';
import { Connection, JsonRpcProvider } from '@mysten/sui.js';

@@ -80,2 +80,5 @@

}
const ownedKiosk = `0xMyKioskAddress`;
const ownedKioskCap = `0xMyKioskOwnerCap`;
const purchaseItem = async (item, kioskId) => {

@@ -90,11 +93,22 @@

// Purchases the item. Right now it also resolves a royalty rule, if one exists.
// There will be some additional work to support further rules & custom ones soon.
const purchasedItem = purchaseAndResolvePolicies(tx, item.type, item.listing, kioskId, item.objectId, policy[0]);
// Both are required if you there is a `kiosk_lock_rule`.
// Optional otherwise. Function will throw an error if there's a kiosk_lock_rule and these are missing.
const extraParams = {
ownedKiosk,
ownedKioskCap
}
// Define the environment.
// To use a custom package address for rules, you could call:
// const environment = customEnvironment('<PackageAddress>');
const environment = testnetEnvironment;
// now we need to decide what to do with the item
// ... e.g. place() // places the item to the user's kiosk.
// (NOT YET SUPPORTED BUT WORTH MENTIONING if the item has the `kiosk_lock` rule, the resolver will place it in the kiosk automatically.
// For now, to support this rule, we need to manually resolve the `kiosk_lock` rule and place it in our owned kiosk.)
// Extra params. Optional, but required if the user tries to resolve a `kiosk_lock_rule`.
// Purchases the item. Supports `kiosk_lock_rule`, `royalty_rule` (accepts combination too).
const result = purchaseAndResolvePolicies(tx, item.type, item.listing.price, kioskId, item.objectId, policy[0], environment, extraParams);
// result = {item: <the_purchased_item>, canTransfer: true/false // depending on whether there was a kiosk lock rule }
// if the item didn't have a kiosk_lock_rule, we need to do something with it.
// for e..g place it in our own kiosk. (demonstrated below)
if(result.canTransfer) place(tx, item.type, ownedKiosk, ownedKioskCap , result.item);
// ...finally, sign PTB & execute it.

@@ -164,2 +178,3 @@

const kioskCap = 'KioskCapObjectId';
const address = '0xSomeAddressThatReceivesTheFunds';
const amount = '100000';

@@ -171,2 +186,5 @@

// transfer the Coin to self or any other address.
tx.transferObjects([coin], tx.pure(address, 'address'));
// ... continue to sign and execute the transaction

@@ -173,0 +191,0 @@ // ...

// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { ObjectOwner, bcs } from '@mysten/sui.js';
import { bcs } from '@mysten/sui.js';
import {
KIOSK_PURCHASE_CAP,
KIOSK_TYPE,
TRANSFER_POLICY_CREATED_EVENT,
TRANSFER_POLICY_TYPE,
} from './types';
/**
* The Kiosk object fields (for BCS queries).
*/
export type Kiosk = {
id: string;
profits: string;
owner: string;
itemCount: number;
allowExtensions: boolean;
};
// Register the `Kiosk` struct for faster queries.
bcs.registerStructType('0x2::kiosk::Kiosk', {
bcs.registerStructType(KIOSK_TYPE, {
id: 'address',

@@ -26,14 +21,4 @@ profits: 'u64',

/**
* PurchaseCap object fields (for BCS queries).
*/
export type PurchaseCap = {
id: string;
kioskId: string;
itemId: string;
minPrice: string;
};
// Register the `PurchaseCap` for faster queries.
bcs.registerStructType('0x2::kiosk::PurchaseCap', {
bcs.registerStructType(KIOSK_PURCHASE_CAP, {
id: 'address',

@@ -45,22 +30,8 @@ kioskId: 'address',

/** Event emitted when a TransferPolicy is created. */
export type TransferPolicyCreated = {
id: string;
};
// Register the `TransferPolicyCreated` event data.
bcs.registerStructType('0x2::transfer_policy::TransferPolicyCreated', {
bcs.registerStructType(TRANSFER_POLICY_CREATED_EVENT, {
id: 'address',
});
/** The `TransferPolicy` object */
export type TransferPolicy = {
id: string;
type: string;
balance: string;
rules: string[];
owner: ObjectOwner;
};
bcs.registerStructType('0x2::transfer_policy::TransferPolicy', {
bcs.registerStructType(TRANSFER_POLICY_TYPE, {
id: 'address',

@@ -67,0 +38,0 @@ balance: 'u64',

@@ -10,1 +10,3 @@ // Copyright (c) Mysten Labs, Inc.

export * from './query/transfer-policy';
export * from './types';
export * from './constants';

@@ -17,3 +17,3 @@ // Copyright (c) Mysten Labs, Inc.

} from '../utils';
import { Kiosk } from '../bcs';
import { Kiosk } from '../types';

@@ -20,0 +20,0 @@ /**

@@ -5,7 +5,9 @@ // Copyright (c) Mysten Labs, Inc.

import { JsonRpcProvider } from '@mysten/sui.js';
import { TransferPolicy, bcs } from '../bcs';
import { bcs } from '../bcs';
import {
TRANSFER_POLICY_CREATED_EVENT,
TRANSFER_POLICY_TYPE,
TransferPolicy,
} from '../types';
/** Name of the event emitted when a TransferPolicy for T is created. */
export const TRANSFER_POLICY_CREATED_EVENT = `0x2::transfer_policy::TransferPolicyCreated`;
/**

@@ -48,11 +50,7 @@ * Searches the `TransferPolicy`-s for the given type. The seach is performed via

let parsed = bcs.de(
'0x2::transfer_policy::TransferPolicy',
policy.bcs.bcsBytes,
'base64',
);
let parsed = bcs.de(TRANSFER_POLICY_TYPE, policy.bcs.bcsBytes, 'base64');
return {
id: policy?.objectId,
type: `0x2::transfer_policy::TransferPolicy<${type}>`,
type: `${TRANSFER_POLICY_TYPE}<${type}>`,
owner: policy?.owner!,

@@ -59,0 +57,0 @@ rules: parsed.rules,

@@ -10,16 +10,20 @@ // Copyright (c) Mysten Labs, Inc.

import { ObjectArgument, getTypeWithoutPackageAddress, objArg } from '../utils';
import { KioskListing } from '../query/kiosk';
import { TransferPolicy } from '../bcs';
import { confirmRequest, resolveRoyaltyRule } from './transfer-policy';
import { getTypeWithoutPackageAddress, objArg } from '../utils';
import {
confirmRequest,
resolveKioskLockRule,
resolveRoyaltyRule,
} from './transfer-policy';
import {
KIOSK_LOCK_RULE,
KIOSK_MODULE,
KIOSK_TYPE,
ObjectArgument,
PurchaseAndResolvePoliciesResponse,
PurchaseOptionalParams,
ROYALTY_RULE,
RulesEnvironmentParam,
TransferPolicy,
} from '../types';
/** The Kiosk module. */
export const KIOSK_MODULE = '0x2::kiosk';
/** The Kiosk type. */
export const KIOSK_TYPE = `${KIOSK_MODULE}::Kiosk`;
/** The Kiosk Owner Cap Type */
export const KIOSK_OWNER_CAP = `${KIOSK_MODULE}::KioskOwnerCap`;
/**

@@ -232,3 +236,8 @@ * Create a new shared Kiosk and returns the [kiosk, kioskOwnerCap] tuple.

amount !== null
? tx.pure(amount, 'Option<u64>')
? tx.pure(
{
Some: amount,
},
'Option<u64>',
)
: tx.pure({ None: true }, 'Option<u64>');

@@ -340,3 +349,6 @@

* 2. Resolving all the transfer policies (if any).
* 3. Returns the PurchasedItem OR places the item in the user's kiosk (if there's a kiosk lock policy).
* 3. Returns the item and whether the user can transfer it or not.
*
* If the item can be transferred, there's an extra transaction required by the user
* to transfer it to an address or place it in their kiosk.
*/

@@ -346,12 +358,15 @@ export function purchaseAndResolvePolicies(

itemType: string,
listing: KioskListing,
kioskId: string,
itemId: string,
price: string,
kiosk: ObjectArgument,
itemId: SuiAddress,
policy: TransferPolicy,
): TransactionArgument | null {
environment: RulesEnvironmentParam,
extraParams?: PurchaseOptionalParams,
): PurchaseAndResolvePoliciesResponse {
// if we don't pass the listing or the listing doens't have a price, return.
if (!listing || listing?.price === undefined) return null;
if (price === undefined || typeof price !== 'string')
throw new Error(`Price of the listing is not supplied.`);
// Split the coin for the amount of the listing.
const coin = tx.splitCoins(tx.gas, [tx.pure(listing.price)]);
const coin = tx.splitCoins(tx.gas, [tx.pure(price, 'u64')]);

@@ -362,3 +377,3 @@ // initialize the purchase `kiosk::purchase`

itemType,
kioskId,
kiosk,
itemId,

@@ -369,5 +384,6 @@ coin,

// Start resolving rules.
// For now, we only support royalty rule.
// Will need some tweaking to make it function properly with the other
// ruleset.
// Right now we support `kiosk_lock_rule` and `royalty_rule`.
// They can also be supplied in parallel (supports combination).
let hasKioskLockRule = false;
for (let rule of policy.rules) {

@@ -377,11 +393,29 @@ const ruleWithoutAddr = getTypeWithoutPackageAddress(rule);

switch (ruleWithoutAddr) {
case 'royalty_rule::Rule':
case ROYALTY_RULE:
resolveRoyaltyRule(
tx,
itemType,
listing.price,
price,
policy.id,
transferRequest,
environment,
);
break;
case KIOSK_LOCK_RULE:
if (!extraParams?.ownedKiosk || !extraParams?.ownedKioskCap)
throw new Error(
`This item type ${itemType} has a 'kiosk_lock_rule', but function call is missing user's kiosk and kioskCap params`,
);
hasKioskLockRule = true;
resolveKioskLockRule(
tx,
itemType,
purchasedItem,
extraParams.ownedKiosk,
extraParams.ownedKioskCap,
policy.id,
transferRequest,
environment,
);
break;
default:

@@ -395,3 +429,6 @@ break;

return purchasedItem;
return {
item: purchasedItem,
canTransfer: !hasKioskLockRule,
};
}

@@ -5,12 +5,10 @@ // Copyright (c) Mysten Labs, Inc.

import { TransactionArgument, TransactionBlock } from '@mysten/sui.js';
import { ObjectArgument, objArg } from '../utils';
import { getRulePackageAddress, objArg } from '../utils';
import { lock } from './kiosk';
import {
ObjectArgument,
RulesEnvironmentParam,
TRANSFER_POLICY_MODULE,
} from '../types';
/** The Transfer Policy module. */
export const TRANSFER_POLICY_MODULE = '0x2::transfer_policy';
/** The Transer Policy Rules package address */
// TODO: Figure out how we serve this for both testnet & mainnet (different package)
export const TRANSFER_POLICY_RULES_PACKAGE_ADDRESS =
'bd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585';
/**

@@ -52,3 +50,3 @@ * Call the `transfer_policy::new` function to create a new transfer policy.

amount !== null
? tx.pure(amount, 'Option<u64>')
? tx.pure({ Some: amount }, 'Option<u64>')
: tx.pure({ None: true }, 'Option<u64>');

@@ -109,4 +107,5 @@

price: string,
policyId: string,
policyId: ObjectArgument,
transferRequest: TransactionArgument,
environment: RulesEnvironmentParam,
) {

@@ -116,3 +115,3 @@ const policyObj = objArg(tx, policyId);

const [amount] = tx.moveCall({
target: `${TRANSFER_POLICY_RULES_PACKAGE_ADDRESS}::royalty_rule::fee_amount`,
target: `${getRulePackageAddress(environment)}::royalty_rule::fee_amount`,
typeArguments: [itemType],

@@ -127,3 +126,3 @@ arguments: [policyObj, objArg(tx, price)],

tx.moveCall({
target: `${TRANSFER_POLICY_RULES_PACKAGE_ADDRESS}::royalty_rule::pay`,
target: `${getRulePackageAddress(environment)}::royalty_rule::pay`,
typeArguments: [itemType],

@@ -133,1 +132,27 @@ arguments: [policyObj, transferRequest, feeCoin],

}
/**
* Locks the item in the supplied kiosk and
* proves to the `kiosk_lock` rule that the item was indeed locked,
* by calling the `kiosk_lock_rule::prove` function to resolve it.
*/
export function resolveKioskLockRule(
tx: TransactionBlock,
itemType: string,
item: TransactionArgument,
kiosk: ObjectArgument,
kioskCap: ObjectArgument,
policyId: ObjectArgument,
transferRequest: TransactionArgument,
environment: RulesEnvironmentParam,
) {
// lock item in the kiosk.
lock(tx, itemType, kiosk, kioskCap, policyId, item);
// proves that the item is locked in the kiosk to the TP.
tx.moveCall({
target: `${getRulePackageAddress(environment)}::kiosk_lock_rule::prove`,
typeArguments: [itemType],
arguments: [transferRequest, objArg(tx, kiosk)],
});
}

@@ -16,12 +16,17 @@ // Copyright (c) Mysten Labs, Inc.

import { DynamicFieldInfo } from '@mysten/sui.js/dist/types/dynamic_fields';
import { bcs, Kiosk } from './bcs';
import { bcs } from './bcs';
import { KIOSK_TYPE, Kiosk, RulesEnvironmentParam } from './types';
import {
MAINNET_RULES_PACKAGE_ADDRESS,
TESTNET_RULES_PACKAGE_ADDRESS,
} from './constants';
/**
* A valid argument for any of the Kiosk functions.
*/
export type ObjectArgument =
| string
| TransactionArgument
| SharedObjectRef
| SuiObjectRef;
/* A simple map to the rule package addresses */
// TODO: Supply the mainnet and devnet addresses.
export const rulesPackageAddresses = {
mainnet: MAINNET_RULES_PACKAGE_ADDRESS,
testnet: TESTNET_RULES_PACKAGE_ADDRESS,
devnet: '',
custom: null,
};

@@ -72,3 +77,3 @@ /**

return bcs.de('0x2::kiosk::Kiosk', queryRes.data.bcs!.bcsBytes, 'base64');
return bcs.de(KIOSK_TYPE, queryRes.data.bcs!.bcsBytes, 'base64');
}

@@ -114,5 +119,5 @@

// e.g. 0x2::kiosk::Item -> kiosk::Item
export const getTypeWithoutPackageAddress = (type: string) => {
export function getTypeWithoutPackageAddress(type: string) {
return type.split('::').slice(-2).join('::');
};
}

@@ -122,7 +127,7 @@ /**

*/
export const attachListingsAndPrices = (
export function attachListingsAndPrices(
kioskData: KioskData,
listings: KioskListing[],
listingObjects: SuiObjectResponse[],
) => {
) {
// map item listings as {item_id: KioskListing}

@@ -150,3 +155,3 @@ // for easier mapping on the nex

});
};
}

@@ -156,6 +161,6 @@ /**

*/
export const attachLockedItems = (
export function attachLockedItems(
kioskData: KioskData,
lockedItemIds: ObjectId[],
) => {
) {
// map lock status in an array of type { item_id: true }

@@ -174,2 +179,17 @@ const lockedStatuses = lockedItemIds.reduce<Record<ObjectId, boolean>>(

});
};
}
/**
* A helper to get a rule's environment address.
*/
export function getRulePackageAddress(
environment: RulesEnvironmentParam,
): string {
// if we have custom environment, we return it.
if (environment.env === 'custom') {
if (!environment.address)
throw new Error('Please supply the custom package address for rules.');
return environment.address;
}
return rulesPackageAddresses[environment.env];
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc