@mysten/kiosk
Advanced tools
Comparing version 0.0.0-experimental-20230731203002 to 0.0.0-experimental-20230801125720
@@ -37,4 +37,6 @@ "use strict"; | ||
TRANSFER_POLICY_TYPE: () => TRANSFER_POLICY_TYPE, | ||
attachKioskLockRule: () => attachKioskLockRule, | ||
attachListingsAndPrices: () => attachListingsAndPrices, | ||
attachLockedItems: () => attachLockedItems, | ||
attachRoyaltyRule: () => attachRoyaltyRule, | ||
bcs: () => import_bcs.bcs, | ||
@@ -61,2 +63,3 @@ borrow: () => borrow, | ||
objArg: () => objArg, | ||
percentageToBasisPoints: () => percentageToBasisPoints, | ||
place: () => place, | ||
@@ -253,2 +256,7 @@ placeAndList: () => placeAndList, | ||
} | ||
function percentageToBasisPoints(percentage) { | ||
if (percentage < 0 || percentage > 100) | ||
throw new Error("Percentage needs to be in the [0,100] range."); | ||
return Math.ceil(percentage * 100); | ||
} | ||
@@ -473,4 +481,27 @@ // src/tx/transfer-policy.ts | ||
// src/tx/rules.ts | ||
function attachRoyaltyRule(tx, type, policy, policyCap, percentageBps, minAmount, environment) { | ||
if (Number(percentageBps) < 0 || Number(percentageBps) > 1e4) | ||
throw new Error("Invalid basis point percentage. Use a value between [0,10000]."); | ||
tx.moveCall({ | ||
target: `${getRulePackageAddress(environment)}::royalty_rule::add`, | ||
typeArguments: [type], | ||
arguments: [ | ||
objArg(tx, policy), | ||
objArg(tx, policyCap), | ||
tx.pure(percentageBps, "u16"), | ||
tx.pure(minAmount, "u64") | ||
] | ||
}); | ||
} | ||
function attachKioskLockRule(tx, type, policy, policyCap, environment) { | ||
tx.moveCall({ | ||
target: `${getRulePackageAddress(environment)}::kiosk_lock_rule::add`, | ||
typeArguments: [type], | ||
arguments: [objArg(tx, policy), objArg(tx, policyCap)] | ||
}); | ||
} | ||
// src/query/kiosk.ts | ||
var import_utils3 = require("@mysten/sui.js/utils"); | ||
var import_utils4 = require("@mysten/sui.js/utils"); | ||
async function fetchKiosk(client, kioskId, pagination, options) { | ||
@@ -501,3 +532,3 @@ const data = await getAllDynamicFields(client, kioskId, pagination); | ||
async function getOwnedKiosks(client, address, options) { | ||
if (!(0, import_utils3.isValidSuiAddress)(address)) | ||
if (!(0, import_utils4.isValidSuiAddress)(address)) | ||
return { | ||
@@ -577,4 +608,6 @@ nextCursor: null, | ||
TRANSFER_POLICY_TYPE, | ||
attachKioskLockRule, | ||
attachListingsAndPrices, | ||
attachLockedItems, | ||
attachRoyaltyRule, | ||
bcs, | ||
@@ -601,2 +634,3 @@ borrow, | ||
objArg, | ||
percentageToBasisPoints, | ||
place, | ||
@@ -603,0 +637,0 @@ placeAndList, |
# @mysten/kiosk | ||
## 0.0.0-experimental-20230731203002 | ||
## 0.0.0-experimental-20230801125720 | ||
### Minor Changes | ||
- 210bfac58: Adds support for attaching royalty rule and kiosk lock rule to a transfer policy. | ||
## 0.4.1 | ||
### Patch Changes | ||
- Updated dependencies [47ea5ec7c] | ||
- @mysten/sui.js@0.0.0-experimental-20230731203002 | ||
- @mysten/sui.js@0.39.0 | ||
@@ -10,0 +16,0 @@ ## 0.4.0 |
export * from './tx/kiosk'; | ||
export * from './tx/transfer-policy'; | ||
export * from './tx/rules'; | ||
export * from './query/kiosk'; | ||
@@ -4,0 +5,0 @@ export * from './bcs'; |
@@ -37,4 +37,6 @@ "use strict"; | ||
TRANSFER_POLICY_TYPE: () => TRANSFER_POLICY_TYPE, | ||
attachKioskLockRule: () => attachKioskLockRule, | ||
attachListingsAndPrices: () => attachListingsAndPrices, | ||
attachLockedItems: () => attachLockedItems, | ||
attachRoyaltyRule: () => attachRoyaltyRule, | ||
bcs: () => import_bcs.bcs, | ||
@@ -61,2 +63,3 @@ borrow: () => borrow, | ||
objArg: () => objArg, | ||
percentageToBasisPoints: () => percentageToBasisPoints, | ||
place: () => place, | ||
@@ -253,2 +256,7 @@ placeAndList: () => placeAndList, | ||
} | ||
function percentageToBasisPoints(percentage) { | ||
if (percentage < 0 || percentage > 100) | ||
throw new Error("Percentage needs to be in the [0,100] range."); | ||
return Math.ceil(percentage * 100); | ||
} | ||
@@ -473,4 +481,27 @@ // src/tx/transfer-policy.ts | ||
// src/tx/rules.ts | ||
function attachRoyaltyRule(tx, type, policy, policyCap, percentageBps, minAmount, environment) { | ||
if (Number(percentageBps) < 0 || Number(percentageBps) > 1e4) | ||
throw new Error("Invalid basis point percentage. Use a value between [0,10000]."); | ||
tx.moveCall({ | ||
target: `${getRulePackageAddress(environment)}::royalty_rule::add`, | ||
typeArguments: [type], | ||
arguments: [ | ||
objArg(tx, policy), | ||
objArg(tx, policyCap), | ||
tx.pure(percentageBps, "u16"), | ||
tx.pure(minAmount, "u64") | ||
] | ||
}); | ||
} | ||
function attachKioskLockRule(tx, type, policy, policyCap, environment) { | ||
tx.moveCall({ | ||
target: `${getRulePackageAddress(environment)}::kiosk_lock_rule::add`, | ||
typeArguments: [type], | ||
arguments: [objArg(tx, policy), objArg(tx, policyCap)] | ||
}); | ||
} | ||
// src/query/kiosk.ts | ||
var import_utils3 = require("@mysten/sui.js/utils"); | ||
var import_utils4 = require("@mysten/sui.js/utils"); | ||
async function fetchKiosk(client, kioskId, pagination, options) { | ||
@@ -501,3 +532,3 @@ const data = await getAllDynamicFields(client, kioskId, pagination); | ||
async function getOwnedKiosks(client, address, options) { | ||
if (!(0, import_utils3.isValidSuiAddress)(address)) | ||
if (!(0, import_utils4.isValidSuiAddress)(address)) | ||
return { | ||
@@ -577,4 +608,6 @@ nextCursor: null, | ||
TRANSFER_POLICY_TYPE, | ||
attachKioskLockRule, | ||
attachListingsAndPrices, | ||
attachLockedItems, | ||
attachRoyaltyRule, | ||
bcs, | ||
@@ -601,2 +634,3 @@ borrow, | ||
objArg, | ||
percentageToBasisPoints, | ||
place, | ||
@@ -603,0 +637,0 @@ placeAndList, |
@@ -42,1 +42,8 @@ import { SharedObjectRef } from '@mysten/sui.js/bcs'; | ||
export declare function getAllDynamicFields(client: SuiClient, parentId: string, pagination: PaginationArguments<string>): Promise<DynamicFieldInfo[]>; | ||
/** | ||
* Converts a number to basis points. | ||
* Supports up to 2 decimal points. | ||
* E.g 9.95 -> 995 | ||
* @param percentage A percentage amount in the range [0, 100] including decimals. | ||
*/ | ||
export declare function percentageToBasisPoints(percentage: number): number; |
@@ -5,3 +5,3 @@ { | ||
"description": "Sui Kiosk library", | ||
"version": "0.0.0-experimental-20230731203002", | ||
"version": "0.0.0-experimental-20230801125720", | ||
"license": "Apache-2.0", | ||
@@ -28,3 +28,3 @@ "main": "./dist/index.js", | ||
"dependencies": { | ||
"@mysten/sui.js": "0.0.0-experimental-20230731203002" | ||
"@mysten/sui.js": "0.39.0" | ||
}, | ||
@@ -31,0 +31,0 @@ "devDependencies": { |
114
README.md
# Kiosk SDK | ||
> **This package is still in active development. Use at your own risk**. Currently, the only | ||
> supported environment is **Sui Testnet**. | ||
> **This package is still in active development. Use at your own risk**. | ||
@@ -24,5 +23,27 @@ This Kiosk SDK library provides different utilities to interact/create/manage a | ||
<details> | ||
<summary>Getting the listings & items by the kiosk's id</summary> | ||
<summary>Find the kiosks owned by an address</summary> | ||
```typescript | ||
import { getOwnedKiosks } from '@mysten/kiosk'; | ||
import { SuiClient } from '@mysten/sui.js/client'; | ||
const client = new SuiClient( | ||
url: 'https://fullnode.testnet.sui.io:443', | ||
); | ||
// You could use these to fetch the contents for each kiosk, or use the `kioskOwnerCap` data for other actions. | ||
const getUserKiosks = async () => { | ||
const address = `0xAddress`; | ||
const { data } = await getOwnedKiosks(client, address); | ||
console.log(data); // kioskOwnerCaps:[], kioskIds: [] | ||
}; | ||
``` | ||
</details> | ||
<details> | ||
<summary>Getting the listings & items by the kiosk's ID</summary> | ||
```typescript | ||
import { fetchKiosk } from '@mysten/kiosk'; | ||
@@ -187,1 +208,88 @@ import { SuiClient } from '@mysten/sui.js/client'; | ||
</details> | ||
<details> | ||
<summary>Create a Transfer Policy for a Type</summary> | ||
You can create a TransferPolicy only for packages for which you own the `publisher` object. | ||
As a best practice, you should use a single Transfer policy per type (T). If you use more than one | ||
policy for a type, and the rules for each differ, anyone that meets the conditions for any of the | ||
attached policies can purchase an asset from a kiosk. You can't specify which policy applies to a | ||
specific asset for the type when there is more than one policy attached. When someone meets the | ||
conditions that are easiest to meet, they are allowed to purchase and transfer the asset. | ||
Before you create a transfer policy, you can use the `queryTransferpolicy` function to check the | ||
transfer policy associated with a type. This is similar to the `purchaseAndResolvePolicies` example | ||
above. | ||
```typescript | ||
import { createTransferPolicy } from '@mysten/kiosk'; | ||
import { TransactionBlock } from '@mysten/sui.js'; | ||
const createPolicyForType = async () => { | ||
const type = 'SomePackageId::type::MyType'; // the Type for which we're creating a Transfer Policy. | ||
const publisher = 'publisherObjectId'; // the publisher object id that you got when claiming the package that defines the Type. | ||
const address = 'AddressToReceiveTheCap'; | ||
const tx = new TransactionBlock(); | ||
// create transfer policy | ||
let transferPolicyCap = createTransferPolicy(tx, type, publisher); | ||
// transfer the Cap to the address. | ||
tx.transferObjects([transferPolicyCap], tx.pure(address, 'address')); | ||
// ... continue to sign and execute the transaction | ||
// ... | ||
}; | ||
``` | ||
</details> | ||
<details> | ||
<summary>Attach Royalty and Lock rules to a Transfer policy</summary> | ||
```typescript | ||
import { | ||
createTransferPolicy, | ||
attachKioskLockRule, | ||
attachRoyaltyRule, | ||
testnetEnvironment, | ||
percentageToBasisPoints, | ||
} from '@mysten/kiosk'; | ||
import { TransactionBlock } from '@mysten/sui.js'; | ||
// Attaches a royalty rule of 1% or 0.1 SUI (whichever is bigger) | ||
// as well as a kiosk lock, making the objects trade-able only from/to a kiosk. | ||
const attachStrongRoyalties = async () => { | ||
const type = 'SomePackageId::type::MyType'; // the Type for which we're attaching rules. | ||
const policyId = 'policyObjectId'; // the transfer Policy ID that was created for that Type. | ||
const transferPolicyCap = 'transferPolicyCapId'; // the transferPolicyCap for that policy. | ||
// royalties configuration. | ||
const percentage = 2.55; // 2.55% | ||
const minAmount = 100_000_000; // 0.1 SUI. | ||
// the environment on which we're referecing the rules package. | ||
// use `mainnetEnvironment` for mainnet. | ||
const enviroment = testnetEnvironment; | ||
const tx = new TransactionBlock(); | ||
attachKioskLockRule(tx, type, policyId, policyCapId, enviroment); | ||
attachRoyaltyRule( | ||
tx, | ||
type, | ||
policyId, | ||
policyCapId, | ||
percentageToBasisPoints(percentage), | ||
minAmount, | ||
enviroment, | ||
); | ||
// ... continue to sign and execute the transaction | ||
// ... | ||
}; | ||
``` | ||
</details> |
@@ -6,2 +6,3 @@ // Copyright (c) Mysten Labs, Inc. | ||
export * from './tx/transfer-policy'; | ||
export * from './tx/rules'; | ||
export * from './query/kiosk'; | ||
@@ -8,0 +9,0 @@ export * from './bcs'; |
@@ -201,1 +201,13 @@ // Copyright (c) Mysten Labs, Inc. | ||
} | ||
/** | ||
* Converts a number to basis points. | ||
* Supports up to 2 decimal points. | ||
* E.g 9.95 -> 995 | ||
* @param percentage A percentage amount in the range [0, 100] including decimals. | ||
*/ | ||
export function percentageToBasisPoints(percentage: number) { | ||
if (percentage < 0 || percentage > 100) | ||
throw new Error('Percentage needs to be in the [0,100] range.'); | ||
return Math.ceil(percentage * 100); | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
232201
35
3286
294
+ Added@mysten/sui.js@0.39.0(transitive)
- Removed@mysten/sui.js@0.0.0-experimental-20230731203002(transitive)
Updated@mysten/sui.js@0.39.0