@mysten/kiosk
Advanced tools
Comparing version 0.3.3 to 0.4.0
@@ -39,3 +39,3 @@ "use strict"; | ||
attachLockedItems: () => attachLockedItems, | ||
bcs: () => import_sui.bcs, | ||
bcs: () => import_bcs.bcs, | ||
borrow: () => borrow, | ||
@@ -78,7 +78,4 @@ borrowMut: () => borrowMut, | ||
// src/utils.ts | ||
var import_sui2 = require("@mysten/sui.js"); | ||
// src/bcs.ts | ||
var import_sui = require("@mysten/sui.js"); | ||
var import_bcs = require("@mysten/sui.js/bcs"); | ||
@@ -110,3 +107,3 @@ // src/types/kiosk.ts | ||
// src/bcs.ts | ||
import_sui.bcs.registerStructType(KIOSK_TYPE, { | ||
import_bcs.bcs.registerStructType(KIOSK_TYPE, { | ||
id: "address", | ||
@@ -118,3 +115,3 @@ profits: "u64", | ||
}); | ||
import_sui.bcs.registerStructType(KIOSK_PURCHASE_CAP, { | ||
import_bcs.bcs.registerStructType(KIOSK_PURCHASE_CAP, { | ||
id: "address", | ||
@@ -125,6 +122,6 @@ kioskId: "address", | ||
}); | ||
import_sui.bcs.registerStructType(TRANSFER_POLICY_CREATED_EVENT, { | ||
import_bcs.bcs.registerStructType(TRANSFER_POLICY_CREATED_EVENT, { | ||
id: "address" | ||
}); | ||
import_sui.bcs.registerStructType(TRANSFER_POLICY_TYPE, { | ||
import_bcs.bcs.registerStructType(TRANSFER_POLICY_TYPE, { | ||
id: "address", | ||
@@ -161,4 +158,4 @@ balance: "u64", | ||
} | ||
async function getKioskObject(provider, id) { | ||
const queryRes = await provider.getObject({ id, options: { showBcs: true } }); | ||
async function getKioskObject(client, id) { | ||
const queryRes = await client.getObject({ id, options: { showBcs: true } }); | ||
if (!queryRes || queryRes.error || !queryRes.data) { | ||
@@ -170,3 +167,3 @@ throw new Error(`Kiosk ${id} not found; ${queryRes.error}`); | ||
} | ||
return import_sui.bcs.de(KIOSK_TYPE, queryRes.data.bcs.bcsBytes, "base64"); | ||
return import_bcs.bcs.de(KIOSK_TYPE, queryRes.data.bcs.bcsBytes, "base64"); | ||
} | ||
@@ -212,3 +209,4 @@ function extractKioskData(data, listings, lockedItemIds) { | ||
return acc; | ||
const data = (0, import_sui2.getObjectFields)(listingObjects[idx]); | ||
const content = listingObjects[idx].data?.content; | ||
const data = content?.dataType === "moveObject" ? content?.fields : null; | ||
if (!data) | ||
@@ -245,3 +243,3 @@ return acc; | ||
} | ||
async function getAllDynamicFields(provider, parentId, pagination) { | ||
async function getAllDynamicFields(client, parentId, pagination) { | ||
let hasNextPage = true; | ||
@@ -251,3 +249,3 @@ let cursor = void 0; | ||
while (hasNextPage) { | ||
const result = await provider.getDynamicFields({ | ||
const result = await client.getDynamicFields({ | ||
parentId, | ||
@@ -483,5 +481,5 @@ limit: pagination.limit || void 0, | ||
// src/query/kiosk.ts | ||
var import_sui3 = require("@mysten/sui.js"); | ||
async function fetchKiosk(provider, kioskId, pagination, options) { | ||
const data = await getAllDynamicFields(provider, kioskId, pagination); | ||
var import_utils3 = require("@mysten/sui.js/utils"); | ||
async function fetchKiosk(client, kioskId, pagination, options) { | ||
const data = await getAllDynamicFields(client, kioskId, pagination); | ||
const listings = []; | ||
@@ -491,4 +489,4 @@ const lockedItemIds = []; | ||
const [kiosk, listingObjects] = await Promise.all([ | ||
options.withKioskFields ? getKioskObject(provider, kioskId) : Promise.resolve(void 0), | ||
options.withListingPrices ? provider.multiGetObjects({ | ||
options.withKioskFields ? getKioskObject(client, kioskId) : Promise.resolve(void 0), | ||
options.withListingPrices ? client.multiGetObjects({ | ||
ids: kioskData.listingIds, | ||
@@ -510,4 +508,4 @@ options: { | ||
} | ||
async function getOwnedKiosks(provider, address, options) { | ||
if (!(0, import_sui3.isValidSuiAddress)(address)) | ||
async function getOwnedKiosks(client, address, options) { | ||
if (!(0, import_utils3.isValidSuiAddress)(address)) | ||
return { | ||
@@ -519,3 +517,3 @@ nextCursor: null, | ||
}; | ||
const { data, hasNextPage, nextCursor } = await provider.getOwnedObjects({ | ||
const { data, hasNextPage, nextCursor } = await client.getOwnedObjects({ | ||
owner: address, | ||
@@ -528,3 +526,6 @@ filter: { StructType: KIOSK_OWNER_CAP }, | ||
}); | ||
const kioskIdList = data?.map((x) => (0, import_sui3.getObjectFields)(x)?.for); | ||
const kioskIdList = data?.map((x) => { | ||
const fields = x.data?.content?.dataType === "moveObject" ? x.data.content.fields : null; | ||
return fields?.for; | ||
}); | ||
const filteredData = data.filter((x) => "data" in x).map((x) => x.data); | ||
@@ -545,4 +546,4 @@ return { | ||
// src/query/transfer-policy.ts | ||
async function queryTransferPolicy(provider, type) { | ||
const { data } = await provider.queryEvents({ | ||
async function queryTransferPolicy(client, type) { | ||
const { data } = await client.queryEvents({ | ||
query: { | ||
@@ -553,3 +554,3 @@ MoveEventType: `${TRANSFER_POLICY_CREATED_EVENT}<${type}>` | ||
const search = data.map((event) => event.parsedJson); | ||
const policies = await provider.multiGetObjects({ | ||
const policies = await client.multiGetObjects({ | ||
ids: search.map((policy) => policy.id), | ||
@@ -562,3 +563,3 @@ options: { showBcs: true, showOwner: true } | ||
} | ||
let parsed = import_sui.bcs.de(TRANSFER_POLICY_TYPE, policy.bcs.bcsBytes, "base64"); | ||
let parsed = import_bcs.bcs.de(TRANSFER_POLICY_TYPE, policy.bcs.bcsBytes, "base64"); | ||
return { | ||
@@ -565,0 +566,0 @@ id: policy?.objectId, |
# @mysten/kiosk | ||
## 0.4.0 | ||
### Minor Changes | ||
- cc6441f46: Updated types and imports to use new modular exports from the `@mysten/sui.js` refactor | ||
- 6d41059c7: Update to use modular imports from @mysten/sui.js | ||
Some methods now accept a `SuiClient` imported from `@mysten/sui.js/client` rather than a `JsonRpcProvider` | ||
### Patch Changes | ||
- Updated dependencies [ad46f9f2f] | ||
- Updated dependencies [67e581a5a] | ||
- Updated dependencies [34242be56] | ||
- Updated dependencies [4e2a150a1] | ||
- Updated dependencies [cce6ffbcc] | ||
- Updated dependencies [0f06d593a] | ||
- Updated dependencies [83d0fb734] | ||
- Updated dependencies [09f4ed3fc] | ||
- Updated dependencies [6d41059c7] | ||
- Updated dependencies [cc6441f46] | ||
- Updated dependencies [001148443] | ||
- @mysten/sui.js@0.38.0 | ||
## 0.3.3 | ||
@@ -4,0 +28,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { bcs } from '@mysten/sui.js'; | ||
import { bcs } from '@mysten/sui.js/bcs'; | ||
export { bcs }; |
@@ -39,3 +39,3 @@ "use strict"; | ||
attachLockedItems: () => attachLockedItems, | ||
bcs: () => import_sui.bcs, | ||
bcs: () => import_bcs.bcs, | ||
borrow: () => borrow, | ||
@@ -78,7 +78,4 @@ borrowMut: () => borrowMut, | ||
// src/utils.ts | ||
var import_sui2 = require("@mysten/sui.js"); | ||
// src/bcs.ts | ||
var import_sui = require("@mysten/sui.js"); | ||
var import_bcs = require("@mysten/sui.js/bcs"); | ||
@@ -110,3 +107,3 @@ // src/types/kiosk.ts | ||
// src/bcs.ts | ||
import_sui.bcs.registerStructType(KIOSK_TYPE, { | ||
import_bcs.bcs.registerStructType(KIOSK_TYPE, { | ||
id: "address", | ||
@@ -118,3 +115,3 @@ profits: "u64", | ||
}); | ||
import_sui.bcs.registerStructType(KIOSK_PURCHASE_CAP, { | ||
import_bcs.bcs.registerStructType(KIOSK_PURCHASE_CAP, { | ||
id: "address", | ||
@@ -125,6 +122,6 @@ kioskId: "address", | ||
}); | ||
import_sui.bcs.registerStructType(TRANSFER_POLICY_CREATED_EVENT, { | ||
import_bcs.bcs.registerStructType(TRANSFER_POLICY_CREATED_EVENT, { | ||
id: "address" | ||
}); | ||
import_sui.bcs.registerStructType(TRANSFER_POLICY_TYPE, { | ||
import_bcs.bcs.registerStructType(TRANSFER_POLICY_TYPE, { | ||
id: "address", | ||
@@ -161,4 +158,4 @@ balance: "u64", | ||
} | ||
async function getKioskObject(provider, id) { | ||
const queryRes = await provider.getObject({ id, options: { showBcs: true } }); | ||
async function getKioskObject(client, id) { | ||
const queryRes = await client.getObject({ id, options: { showBcs: true } }); | ||
if (!queryRes || queryRes.error || !queryRes.data) { | ||
@@ -170,3 +167,3 @@ throw new Error(`Kiosk ${id} not found; ${queryRes.error}`); | ||
} | ||
return import_sui.bcs.de(KIOSK_TYPE, queryRes.data.bcs.bcsBytes, "base64"); | ||
return import_bcs.bcs.de(KIOSK_TYPE, queryRes.data.bcs.bcsBytes, "base64"); | ||
} | ||
@@ -212,3 +209,4 @@ function extractKioskData(data, listings, lockedItemIds) { | ||
return acc; | ||
const data = (0, import_sui2.getObjectFields)(listingObjects[idx]); | ||
const content = listingObjects[idx].data?.content; | ||
const data = content?.dataType === "moveObject" ? content?.fields : null; | ||
if (!data) | ||
@@ -245,3 +243,3 @@ return acc; | ||
} | ||
async function getAllDynamicFields(provider, parentId, pagination) { | ||
async function getAllDynamicFields(client, parentId, pagination) { | ||
let hasNextPage = true; | ||
@@ -251,3 +249,3 @@ let cursor = void 0; | ||
while (hasNextPage) { | ||
const result = await provider.getDynamicFields({ | ||
const result = await client.getDynamicFields({ | ||
parentId, | ||
@@ -483,5 +481,5 @@ limit: pagination.limit || void 0, | ||
// src/query/kiosk.ts | ||
var import_sui3 = require("@mysten/sui.js"); | ||
async function fetchKiosk(provider, kioskId, pagination, options) { | ||
const data = await getAllDynamicFields(provider, kioskId, pagination); | ||
var import_utils3 = require("@mysten/sui.js/utils"); | ||
async function fetchKiosk(client, kioskId, pagination, options) { | ||
const data = await getAllDynamicFields(client, kioskId, pagination); | ||
const listings = []; | ||
@@ -491,4 +489,4 @@ const lockedItemIds = []; | ||
const [kiosk, listingObjects] = await Promise.all([ | ||
options.withKioskFields ? getKioskObject(provider, kioskId) : Promise.resolve(void 0), | ||
options.withListingPrices ? provider.multiGetObjects({ | ||
options.withKioskFields ? getKioskObject(client, kioskId) : Promise.resolve(void 0), | ||
options.withListingPrices ? client.multiGetObjects({ | ||
ids: kioskData.listingIds, | ||
@@ -510,4 +508,4 @@ options: { | ||
} | ||
async function getOwnedKiosks(provider, address, options) { | ||
if (!(0, import_sui3.isValidSuiAddress)(address)) | ||
async function getOwnedKiosks(client, address, options) { | ||
if (!(0, import_utils3.isValidSuiAddress)(address)) | ||
return { | ||
@@ -519,3 +517,3 @@ nextCursor: null, | ||
}; | ||
const { data, hasNextPage, nextCursor } = await provider.getOwnedObjects({ | ||
const { data, hasNextPage, nextCursor } = await client.getOwnedObjects({ | ||
owner: address, | ||
@@ -528,3 +526,6 @@ filter: { StructType: KIOSK_OWNER_CAP }, | ||
}); | ||
const kioskIdList = data?.map((x) => (0, import_sui3.getObjectFields)(x)?.for); | ||
const kioskIdList = data?.map((x) => { | ||
const fields = x.data?.content?.dataType === "moveObject" ? x.data.content.fields : null; | ||
return fields?.for; | ||
}); | ||
const filteredData = data.filter((x) => "data" in x).map((x) => x.data); | ||
@@ -545,4 +546,4 @@ return { | ||
// src/query/transfer-policy.ts | ||
async function queryTransferPolicy(provider, type) { | ||
const { data } = await provider.queryEvents({ | ||
async function queryTransferPolicy(client, type) { | ||
const { data } = await client.queryEvents({ | ||
query: { | ||
@@ -553,3 +554,3 @@ MoveEventType: `${TRANSFER_POLICY_CREATED_EVENT}<${type}>` | ||
const search = data.map((event) => event.parsedJson); | ||
const policies = await provider.multiGetObjects({ | ||
const policies = await client.multiGetObjects({ | ||
ids: search.map((policy) => policy.id), | ||
@@ -562,3 +563,3 @@ options: { showBcs: true, showOwner: true } | ||
} | ||
let parsed = import_sui.bcs.de(TRANSFER_POLICY_TYPE, policy.bcs.bcsBytes, "base64"); | ||
let parsed = import_bcs.bcs.de(TRANSFER_POLICY_TYPE, policy.bcs.bcsBytes, "base64"); | ||
return { | ||
@@ -565,0 +566,0 @@ id: policy?.objectId, |
@@ -1,4 +0,4 @@ | ||
import { JsonRpcProvider, PaginationArguments, SuiAddress } from '@mysten/sui.js'; | ||
import { FetchKioskOptions, OwnedKiosks, PagedKioskData } from '../types'; | ||
export declare function fetchKiosk(provider: JsonRpcProvider, kioskId: SuiAddress, pagination: PaginationArguments<string>, options: FetchKioskOptions): Promise<PagedKioskData>; | ||
import { SuiClient, PaginationArguments } from '@mysten/sui.js/client'; | ||
export declare function fetchKiosk(client: SuiClient, kioskId: string, pagination: PaginationArguments<string>, options: FetchKioskOptions): Promise<PagedKioskData>; | ||
/** | ||
@@ -10,4 +10,4 @@ * A function to fetch all the user's kiosk Caps | ||
*/ | ||
export declare function getOwnedKiosks(provider: JsonRpcProvider, address: SuiAddress, options?: { | ||
export declare function getOwnedKiosks(client: SuiClient, address: string, options?: { | ||
pagination?: PaginationArguments<string>; | ||
}): Promise<OwnedKiosks>; |
@@ -1,2 +0,2 @@ | ||
import { JsonRpcProvider } from '@mysten/sui.js'; | ||
import { SuiClient } from '@mysten/sui.js/client'; | ||
import { TransferPolicy } from '../types'; | ||
@@ -12,2 +12,2 @@ /** | ||
*/ | ||
export declare function queryTransferPolicy(provider: JsonRpcProvider, type: string): Promise<TransferPolicy[]>; | ||
export declare function queryTransferPolicy(client: SuiClient, type: string): Promise<TransferPolicy[]>; |
@@ -1,2 +0,2 @@ | ||
import { SuiAddress, TransactionArgument, TransactionBlock } from '@mysten/sui.js'; | ||
import { TransactionBlock, TransactionArgument } from '@mysten/sui.js/transactions'; | ||
import { ObjectArgument, PurchaseAndResolvePoliciesResponse, PurchaseOptionalParams, RulesEnvironmentParam, TransferPolicy } from '../types'; | ||
@@ -30,3 +30,3 @@ /** | ||
*/ | ||
export declare function take(tx: TransactionBlock, itemType: string, kiosk: ObjectArgument, kioskCap: ObjectArgument, itemId: SuiAddress): TransactionArgument; | ||
export declare function take(tx: TransactionBlock, itemType: string, kiosk: ObjectArgument, kioskCap: ObjectArgument, itemId: string): TransactionArgument; | ||
/** | ||
@@ -36,3 +36,3 @@ * Call the `kiosk::list<T>(Kiosk, KioskOwnerCap, ID, u64)` function. | ||
*/ | ||
export declare function list(tx: TransactionBlock, itemType: string, kiosk: ObjectArgument, kioskCap: ObjectArgument, itemId: SuiAddress, price: string | bigint): void; | ||
export declare function list(tx: TransactionBlock, itemType: string, kiosk: ObjectArgument, kioskCap: ObjectArgument, itemId: string, price: string | bigint): void; | ||
/** | ||
@@ -42,3 +42,3 @@ * Call the `kiosk::list<T>(Kiosk, KioskOwnerCap, ID, u64)` function. | ||
*/ | ||
export declare function delist(tx: TransactionBlock, itemType: string, kiosk: ObjectArgument, kioskCap: ObjectArgument, itemId: SuiAddress): void; | ||
export declare function delist(tx: TransactionBlock, itemType: string, kiosk: ObjectArgument, kioskCap: ObjectArgument, itemId: string): void; | ||
/** | ||
@@ -53,3 +53,3 @@ * Call the `kiosk::place_and_list<T>(Kiosk, KioskOwnerCap, Item, u64)` function. | ||
*/ | ||
export declare function purchase(tx: TransactionBlock, itemType: string, kiosk: ObjectArgument, itemId: SuiAddress, payment: ObjectArgument): [TransactionArgument, TransactionArgument]; | ||
export declare function purchase(tx: TransactionBlock, itemType: string, kiosk: ObjectArgument, itemId: string, payment: ObjectArgument): [TransactionArgument, TransactionArgument]; | ||
/** | ||
@@ -64,3 +64,3 @@ * Call the `kiosk::withdraw(Kiosk, KioskOwnerCap, Option<u64>)` function and receive a Coin<SUI>. | ||
*/ | ||
export declare function borrow(tx: TransactionBlock, itemType: string, kiosk: ObjectArgument, kioskCap: ObjectArgument, itemId: SuiAddress): TransactionArgument; | ||
export declare function borrow(tx: TransactionBlock, itemType: string, kiosk: ObjectArgument, kioskCap: ObjectArgument, itemId: string): TransactionArgument; | ||
/** | ||
@@ -70,3 +70,3 @@ * Call the `kiosk::borrow_mut<T>(Kiosk, KioskOwnerCap, ID): &mut T` function. | ||
*/ | ||
export declare function borrowMut(tx: TransactionBlock, itemType: string, kiosk: ObjectArgument, kioskCap: ObjectArgument, itemId: SuiAddress): TransactionArgument; | ||
export declare function borrowMut(tx: TransactionBlock, itemType: string, kiosk: ObjectArgument, kioskCap: ObjectArgument, itemId: string): TransactionArgument; | ||
/** | ||
@@ -78,3 +78,3 @@ * Call the `kiosk::borrow_value<T>(Kiosk, KioskOwnerCap, ID): T` function. | ||
*/ | ||
export declare function borrowValue(tx: TransactionBlock, itemType: string, kiosk: ObjectArgument, kioskCap: ObjectArgument, itemId: SuiAddress): [TransactionArgument, TransactionArgument]; | ||
export declare function borrowValue(tx: TransactionBlock, itemType: string, kiosk: ObjectArgument, kioskCap: ObjectArgument, itemId: string): [TransactionArgument, TransactionArgument]; | ||
/** | ||
@@ -94,2 +94,2 @@ * Call the `kiosk::return_value<T>(Kiosk, Item, Borrow)` function. | ||
*/ | ||
export declare function purchaseAndResolvePolicies(tx: TransactionBlock, itemType: string, price: string, kiosk: ObjectArgument, itemId: SuiAddress, policy: TransferPolicy, environment: RulesEnvironmentParam, extraParams?: PurchaseOptionalParams): PurchaseAndResolvePoliciesResponse; | ||
export declare function purchaseAndResolvePolicies(tx: TransactionBlock, itemType: string, price: string, kiosk: ObjectArgument, itemId: string, policy: TransferPolicy, environment: RulesEnvironmentParam, extraParams?: PurchaseOptionalParams): PurchaseAndResolvePoliciesResponse; |
@@ -1,2 +0,2 @@ | ||
import { TransactionArgument, TransactionBlock } from '@mysten/sui.js'; | ||
import { TransactionBlock, TransactionArgument } from '@mysten/sui.js/transactions'; | ||
import { ObjectArgument, RulesEnvironmentParam } from '../types'; | ||
@@ -3,0 +3,0 @@ /** |
@@ -1,7 +0,6 @@ | ||
import { SuiAddress } from '@mysten/sui.js'; | ||
export type Environment = 'mainnet' | 'testnet' | 'devnet' | 'custom'; | ||
/** A Parameter to support enivronments for rules. */ | ||
/** A Parameter to support environments for rules. */ | ||
export type RulesEnvironmentParam = { | ||
env: Environment; | ||
address?: SuiAddress; | ||
address?: string; | ||
}; | ||
@@ -8,0 +7,0 @@ /** A default Testnet Environment object */ |
@@ -1,2 +0,4 @@ | ||
import { SharedObjectRef, SuiObjectRef, TransactionArgument } from '@mysten/sui.js'; | ||
import { SharedObjectRef } from '@mysten/sui.js/bcs'; | ||
import { SuiObjectRef } from '@mysten/sui.js/client'; | ||
import { TransactionArgument } from '@mysten/sui.js/transactions'; | ||
export * from './kiosk'; | ||
@@ -3,0 +5,0 @@ export * from './transfer-policy'; |
@@ -1,2 +0,3 @@ | ||
import { ObjectDigest, ObjectId, ObjectType, PaginatedObjectsResponse, TransactionArgument } from '@mysten/sui.js'; | ||
import { PaginatedObjectsResponse } from '@mysten/sui.js/client'; | ||
import { TransactionArgument } from '@mysten/sui.js/transactions'; | ||
import { ObjectArgument } from '.'; | ||
@@ -59,3 +60,3 @@ /** The Kiosk module. */ | ||
/** The ID of the Item */ | ||
objectId: ObjectId; | ||
objectId: string; | ||
/** | ||
@@ -69,3 +70,3 @@ * Whether or not there's a `PurchaseCap` issued. `true` means that | ||
/** The ID of the listing */ | ||
listingId: ObjectId; | ||
listingId: string; | ||
price?: string; | ||
@@ -79,5 +80,5 @@ }; | ||
/** The ID of the Item */ | ||
objectId: ObjectId; | ||
objectId: string; | ||
/** The type of the Item */ | ||
type: ObjectType; | ||
type: string; | ||
/** Whether the item is Locked (there must be a `Lock` Dynamic Field) */ | ||
@@ -93,4 +94,4 @@ isLocked: boolean; | ||
items: KioskItem[]; | ||
itemIds: ObjectId[]; | ||
listingIds: ObjectId[]; | ||
itemIds: string[]; | ||
listingIds: string[]; | ||
kiosk?: Kiosk; | ||
@@ -101,3 +102,3 @@ extensions: any[]; | ||
data: KioskData; | ||
nextCursor: string | null; | ||
nextCursor: string | null | undefined; | ||
hasNextPage: boolean; | ||
@@ -111,9 +112,9 @@ }; | ||
kioskOwnerCaps: KioskOwnerCap[]; | ||
kioskIds: ObjectId[]; | ||
kioskIds: string[]; | ||
} & Omit<PaginatedObjectsResponse, 'data'>; | ||
export type KioskOwnerCap = { | ||
objectId: ObjectId; | ||
kioskId: ObjectId; | ||
digest: ObjectDigest; | ||
objectId: string; | ||
kioskId: string; | ||
digest: string; | ||
version: string; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { ObjectOwner } from '@mysten/sui.js'; | ||
import { ObjectOwner } from '@mysten/sui.js/client'; | ||
/** The Transfer Policy module. */ | ||
@@ -3,0 +3,0 @@ export declare const TRANSFER_POLICY_MODULE = "0x2::transfer_policy"; |
@@ -1,4 +0,7 @@ | ||
import { JsonRpcProvider, ObjectId, PaginationArguments, SharedObjectRef, SuiObjectRef, SuiObjectResponse, TransactionArgument, TransactionBlock } from '@mysten/sui.js'; | ||
import { type DynamicFieldInfo } from '@mysten/sui.js'; | ||
import { SharedObjectRef } from '@mysten/sui.js/bcs'; | ||
import { SuiObjectRef, SuiObjectResponse } from '@mysten/sui.js/client'; | ||
import { TransactionBlock, TransactionArgument } from '@mysten/sui.js/transactions'; | ||
import { type DynamicFieldInfo } from '@mysten/sui.js/client'; | ||
import { Kiosk, KioskData, KioskListing, RulesEnvironmentParam } from './types'; | ||
import { SuiClient, PaginationArguments } from '@mysten/sui.js/client'; | ||
export declare const rulesPackageAddresses: { | ||
@@ -18,3 +21,3 @@ mainnet: string; | ||
export declare function objArg(tx: TransactionBlock, arg: string | SharedObjectRef | SuiObjectRef | TransactionArgument): TransactionArgument; | ||
export declare function getKioskObject(provider: JsonRpcProvider, id: string): Promise<Kiosk>; | ||
export declare function getKioskObject(client: SuiClient, id: string): Promise<Kiosk>; | ||
export declare function extractKioskData(data: DynamicFieldInfo[], listings: KioskListing[], lockedItemIds: string[]): KioskData; | ||
@@ -29,3 +32,3 @@ export declare function getTypeWithoutPackageAddress(type: string): string; | ||
*/ | ||
export declare function attachLockedItems(kioskData: KioskData, lockedItemIds: ObjectId[]): void; | ||
export declare function attachLockedItems(kioskData: KioskData, lockedItemIds: string[]): void; | ||
/** | ||
@@ -40,13 +43,2 @@ * A helper to get a rule's environment address. | ||
*/ | ||
export declare function getAllDynamicFields(provider: JsonRpcProvider, parentId: ObjectId, pagination: PaginationArguments<string>): Promise<{ | ||
type: "DynamicField" | "DynamicObject"; | ||
objectType: string; | ||
objectId: string; | ||
version: number; | ||
digest: string; | ||
name: { | ||
type: string; | ||
value?: any; | ||
}; | ||
bcsName: string; | ||
}[]>; | ||
export declare function getAllDynamicFields(client: SuiClient, parentId: string, pagination: PaginationArguments<string>): Promise<DynamicFieldInfo[]>; |
@@ -5,3 +5,3 @@ { | ||
"description": "Sui Kiosk library", | ||
"version": "0.3.3", | ||
"version": "0.4.0", | ||
"license": "Apache-2.0", | ||
@@ -28,7 +28,7 @@ "main": "./dist/index.js", | ||
"dependencies": { | ||
"@mysten/sui.js": "0.37.1" | ||
"@mysten/sui.js": "0.38.0" | ||
}, | ||
"devDependencies": { | ||
"tsup": "^6.7.0", | ||
"typescript": "^5.0.4" | ||
"tsup": "^7.1.0", | ||
"typescript": "^5.1.6" | ||
}, | ||
@@ -35,0 +35,0 @@ "scripts": { |
# 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**. Currently, the only | ||
> supported environment is **Sui Testnet**. | ||
This Kiosk SDK library provides different utilities to interact/create/manage a [Kiosk](https://github.com/MystenLabs/sui/tree/main/kiosk). | ||
This Kiosk SDK library provides different utilities to interact/create/manage a | ||
[Kiosk](https://github.com/MystenLabs/sui/tree/main/kiosk). | ||
@@ -27,6 +28,6 @@ ## Installation | ||
import { fetchKiosk } from '@mysten/kiosk'; | ||
import { Connection, JsonRpcProvider } from '@mysten/sui.js'; | ||
import { SuiClient } from '@mysten/sui.js/client'; | ||
const provider = new JsonRpcProvider( | ||
new Connection({ fullnode: 'https://fullnode.testnet.sui.io:443' }), | ||
const client = new SuiClient( | ||
url: 'https://fullnode.testnet.sui.io:443', | ||
); | ||
@@ -38,3 +39,3 @@ | ||
const { data } = await fetchKiosk( | ||
provider, | ||
client, | ||
kioskAddress, | ||
@@ -56,6 +57,6 @@ {}, // empty pagination, currently disabled. | ||
import { queryTransferPolicy, purchaseAndResolvePolicies, place, testnetEnvironment } from '@mysten/kiosk'; | ||
import { Connection, JsonRpcProvider } from '@mysten/sui.js'; | ||
import { SuiClient } from '@mysten/sui.js/client'; | ||
const provider = new JsonRpcProvider( | ||
new Connection({ fullnode: 'https://fullnode.testnet.sui.io:443' }), | ||
const client = new SuiClient( | ||
url: 'https://fullnode.testnet.sui.io:443', | ||
); | ||
@@ -82,3 +83,3 @@ | ||
// fetch the policy of the item (could be an array, if there's more than one transfer policy) | ||
const policies = await queryTransferPolicy(provider, item.type); | ||
const policies = await queryTransferPolicy(client, item.type); | ||
// selecting the first one for simplicity. | ||
@@ -121,3 +122,3 @@ const policyId = policy[0]?.id; | ||
import { createKioskAndShare } from '@mysten/kiosk'; | ||
import { TransactionBlock } from '@mysten/sui.js'; | ||
import { TransactionBlock } from '@mysten/sui.js/transactions'; | ||
@@ -144,3 +145,3 @@ const createKiosk = async () => { | ||
import { placeAndList } from '@mysten/kiosk'; | ||
import { TransactionBlock } from '@mysten/sui.js'; | ||
import { TransactionBlock } from '@mysten/sui.js/transactions'; | ||
@@ -170,3 +171,3 @@ const placeAndListToKiosk = async () => { | ||
import { withdrawFromKiosk } from '@mysten/kiosk'; | ||
import { TransactionBlock } from '@mysten/sui.js'; | ||
import { TransactionBlock } from '@mysten/sui.js/transactions'; | ||
@@ -173,0 +174,0 @@ const withdraw = async () => { |
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { bcs } from '@mysten/sui.js'; | ||
import { bcs } from '@mysten/sui.js/bcs'; | ||
import { | ||
@@ -6,0 +6,0 @@ KIOSK_PURCHASE_CAP, |
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { SuiObjectData, SuiObjectResponse } from '@mysten/sui.js/client'; | ||
import { isValidSuiAddress } from '@mysten/sui.js/utils'; | ||
import { | ||
JsonRpcProvider, | ||
ObjectId, | ||
PaginationArguments, | ||
SuiAddress, | ||
SuiObjectData, | ||
SuiObjectResponse, | ||
getObjectFields, | ||
isValidSuiAddress, | ||
} from '@mysten/sui.js'; | ||
import { | ||
attachListingsAndPrices, | ||
@@ -28,6 +20,7 @@ attachLockedItems, | ||
} from '../types'; | ||
import { SuiClient, PaginationArguments } from '@mysten/sui.js/client'; | ||
export async function fetchKiosk( | ||
provider: JsonRpcProvider, | ||
kioskId: SuiAddress, | ||
client: SuiClient, | ||
kioskId: string, | ||
pagination: PaginationArguments<string>, | ||
@@ -40,6 +33,6 @@ options: FetchKioskOptions, | ||
// This can't work with pagination currently. | ||
const data = await getAllDynamicFields(provider, kioskId, pagination); | ||
const data = await getAllDynamicFields(client, kioskId, pagination); | ||
const listings: KioskListing[] = []; | ||
const lockedItemIds: ObjectId[] = []; | ||
const lockedItemIds: string[] = []; | ||
@@ -53,5 +46,5 @@ // extracted kiosk data. | ||
const [kiosk, listingObjects] = await Promise.all([ | ||
options.withKioskFields ? getKioskObject(provider, kioskId) : Promise.resolve(undefined), | ||
options.withKioskFields ? getKioskObject(client, kioskId) : Promise.resolve(undefined), | ||
options.withListingPrices | ||
? provider.multiGetObjects({ | ||
? client.multiGetObjects({ | ||
ids: kioskData.listingIds, | ||
@@ -85,4 +78,4 @@ options: { | ||
export async function getOwnedKiosks( | ||
provider: JsonRpcProvider, | ||
address: SuiAddress, | ||
client: SuiClient, | ||
address: string, | ||
options?: { | ||
@@ -101,3 +94,3 @@ pagination?: PaginationArguments<string>; | ||
// fetch owned kiosk caps, paginated. | ||
const { data, hasNextPage, nextCursor } = await provider.getOwnedObjects({ | ||
const { data, hasNextPage, nextCursor } = await client.getOwnedObjects({ | ||
owner: address, | ||
@@ -112,3 +105,6 @@ filter: { StructType: KIOSK_OWNER_CAP }, | ||
// get kioskIds from the OwnerCaps. | ||
const kioskIdList = data?.map((x: SuiObjectResponse) => getObjectFields(x)?.for); | ||
const kioskIdList = data?.map((x: SuiObjectResponse) => { | ||
const fields = x.data?.content?.dataType === 'moveObject' ? x.data.content.fields : null; | ||
return (fields as { for: string })?.for; | ||
}); | ||
@@ -115,0 +111,0 @@ // clean up data that might have an error in them. |
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { JsonRpcProvider } from '@mysten/sui.js'; | ||
import { SuiClient } from '@mysten/sui.js/client'; | ||
import { bcs } from '../bcs'; | ||
@@ -18,7 +18,7 @@ import { TRANSFER_POLICY_CREATED_EVENT, TRANSFER_POLICY_TYPE, TransferPolicy } from '../types'; | ||
export async function queryTransferPolicy( | ||
provider: JsonRpcProvider, | ||
client: SuiClient, | ||
type: string, | ||
): Promise<TransferPolicy[]> { | ||
// console.log('event type: %s', `${TRANSFER_POLICY_CREATED_EVENT}<${type}>`); | ||
const { data } = await provider.queryEvents({ | ||
const { data } = await client.queryEvents({ | ||
query: { | ||
@@ -30,3 +30,3 @@ MoveEventType: `${TRANSFER_POLICY_CREATED_EVENT}<${type}>`, | ||
const search = data.map((event) => event.parsedJson as { id: string }); | ||
const policies = await provider.multiGetObjects({ | ||
const policies = await client.multiGetObjects({ | ||
ids: search.map((policy) => policy.id), | ||
@@ -33,0 +33,0 @@ options: { showBcs: true, showOwner: true }, |
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { SuiAddress, TransactionArgument, TransactionBlock } from '@mysten/sui.js'; | ||
import { TransactionBlock, TransactionArgument } from '@mysten/sui.js/transactions'; | ||
@@ -99,3 +99,3 @@ import { getTypeWithoutPackageAddress, objArg } from '../utils'; | ||
kioskCap: ObjectArgument, | ||
itemId: SuiAddress, | ||
itemId: string, | ||
): TransactionArgument { | ||
@@ -120,3 +120,3 @@ let [item] = tx.moveCall({ | ||
kioskCap: ObjectArgument, | ||
itemId: SuiAddress, | ||
itemId: string, | ||
price: string | bigint, | ||
@@ -145,3 +145,3 @@ ): void { | ||
kioskCap: ObjectArgument, | ||
itemId: SuiAddress, | ||
itemId: string, | ||
): void { | ||
@@ -182,3 +182,3 @@ tx.moveCall({ | ||
kiosk: ObjectArgument, | ||
itemId: SuiAddress, | ||
itemId: string, | ||
payment: ObjectArgument, | ||
@@ -232,3 +232,3 @@ ): [TransactionArgument, TransactionArgument] { | ||
kioskCap: ObjectArgument, | ||
itemId: SuiAddress, | ||
itemId: string, | ||
): TransactionArgument { | ||
@@ -253,3 +253,3 @@ let [item] = tx.moveCall({ | ||
kioskCap: ObjectArgument, | ||
itemId: SuiAddress, | ||
itemId: string, | ||
): TransactionArgument { | ||
@@ -276,3 +276,3 @@ let [item] = tx.moveCall({ | ||
kioskCap: ObjectArgument, | ||
itemId: SuiAddress, | ||
itemId: string, | ||
): [TransactionArgument, TransactionArgument] { | ||
@@ -320,3 +320,3 @@ let [item, promise] = tx.moveCall({ | ||
kiosk: ObjectArgument, | ||
itemId: SuiAddress, | ||
itemId: string, | ||
policy: TransferPolicy, | ||
@@ -323,0 +323,0 @@ environment: RulesEnvironmentParam, |
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { TransactionArgument, TransactionBlock } from '@mysten/sui.js'; | ||
import { TransactionBlock, TransactionArgument } from '@mysten/sui.js/transactions'; | ||
import { getRulePackageAddress, objArg } from '../utils'; | ||
@@ -6,0 +6,0 @@ import { lock } from './kiosk'; |
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { SuiAddress } from '@mysten/sui.js'; | ||
/* A list of environments. */ | ||
export type Environment = 'mainnet' | 'testnet' | 'devnet' | 'custom'; | ||
/** A Parameter to support enivronments for rules. */ | ||
export type RulesEnvironmentParam = { env: Environment; address?: SuiAddress }; | ||
/** A Parameter to support environments for rules. */ | ||
export type RulesEnvironmentParam = { env: Environment; address?: string }; | ||
@@ -12,0 +10,0 @@ /** A default Testnet Environment object */ |
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { SharedObjectRef, SuiObjectRef, TransactionArgument } from '@mysten/sui.js'; | ||
import { SharedObjectRef } from '@mysten/sui.js/bcs'; | ||
import { SuiObjectRef } from '@mysten/sui.js/client'; | ||
import { TransactionArgument } from '@mysten/sui.js/transactions'; | ||
@@ -6,0 +8,0 @@ export * from './kiosk'; |
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { | ||
ObjectDigest, | ||
ObjectId, | ||
ObjectType, | ||
PaginatedObjectsResponse, | ||
TransactionArgument, | ||
} from '@mysten/sui.js'; | ||
import { PaginatedObjectsResponse } from '@mysten/sui.js/client'; | ||
import { TransactionArgument } from '@mysten/sui.js/transactions'; | ||
import { ObjectArgument } from '.'; | ||
@@ -80,3 +75,3 @@ | ||
/** The ID of the Item */ | ||
objectId: ObjectId; | ||
objectId: string; | ||
/** | ||
@@ -90,3 +85,3 @@ * Whether or not there's a `PurchaseCap` issued. `true` means that | ||
/** The ID of the listing */ | ||
listingId: ObjectId; | ||
listingId: string; | ||
price?: string; | ||
@@ -101,5 +96,5 @@ }; | ||
/** The ID of the Item */ | ||
objectId: ObjectId; | ||
objectId: string; | ||
/** The type of the Item */ | ||
type: ObjectType; | ||
type: string; | ||
/** Whether the item is Locked (there must be a `Lock` Dynamic Field) */ | ||
@@ -115,4 +110,4 @@ isLocked: boolean; | ||
items: KioskItem[]; | ||
itemIds: ObjectId[]; | ||
listingIds: ObjectId[]; | ||
itemIds: string[]; | ||
listingIds: string[]; | ||
kiosk?: Kiosk; | ||
@@ -124,3 +119,3 @@ extensions: any[]; // type will be defined on later versions of the SDK. | ||
data: KioskData; | ||
nextCursor: string | null; | ||
nextCursor: string | null | undefined; | ||
hasNextPage: boolean; | ||
@@ -136,10 +131,10 @@ }; | ||
kioskOwnerCaps: KioskOwnerCap[]; | ||
kioskIds: ObjectId[]; | ||
kioskIds: string[]; | ||
} & Omit<PaginatedObjectsResponse, 'data'>; | ||
export type KioskOwnerCap = { | ||
objectId: ObjectId; | ||
kioskId: ObjectId; | ||
digest: ObjectDigest; | ||
objectId: string; | ||
kioskId: string; | ||
digest: string; | ||
version: string; | ||
}; |
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { ObjectOwner } from '@mysten/sui.js'; | ||
import { ObjectOwner } from '@mysten/sui.js/client'; | ||
@@ -6,0 +6,0 @@ /** The Transfer Policy module. */ |
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { | ||
JsonRpcProvider, | ||
ObjectId, | ||
PaginationArguments, | ||
SharedObjectRef, | ||
SuiObjectRef, | ||
SuiObjectResponse, | ||
TransactionArgument, | ||
TransactionBlock, | ||
getObjectFields, | ||
} from '@mysten/sui.js'; | ||
import { type DynamicFieldInfo } from '@mysten/sui.js'; | ||
import { SharedObjectRef } from '@mysten/sui.js/bcs'; | ||
import { SuiObjectRef, SuiObjectResponse } from '@mysten/sui.js/client'; | ||
import { TransactionBlock, TransactionArgument } from '@mysten/sui.js/transactions'; | ||
import { type DynamicFieldInfo } from '@mysten/sui.js/client'; | ||
import { bcs } from './bcs'; | ||
import { KIOSK_TYPE, Kiosk, KioskData, KioskListing, RulesEnvironmentParam } from './types'; | ||
import { MAINNET_RULES_PACKAGE_ADDRESS, TESTNET_RULES_PACKAGE_ADDRESS } from './constants'; | ||
import { SuiClient, PaginationArguments } from '@mysten/sui.js/client'; | ||
@@ -59,4 +52,4 @@ /* A simple map to the rule package addresses */ | ||
export async function getKioskObject(provider: JsonRpcProvider, id: string): Promise<Kiosk> { | ||
const queryRes = await provider.getObject({ id, options: { showBcs: true } }); | ||
export async function getKioskObject(client: SuiClient, id: string): Promise<Kiosk> { | ||
const queryRes = await client.getObject({ id, options: { showBcs: true } }); | ||
@@ -96,9 +89,9 @@ if (!queryRes || queryRes.error || !queryRes.data) { | ||
listings.push({ | ||
objectId: val.name.value.id, | ||
objectId: (val.name.value as { id: string }).id, | ||
listingId: val.objectId, | ||
isExclusive: val.name.value.is_exclusive, | ||
isExclusive: (val.name.value as { is_exclusive: boolean }).is_exclusive, | ||
}); | ||
break; | ||
case 'kiosk::Lock': | ||
lockedItemIds?.push(val.name.value.id); | ||
lockedItemIds?.push((val.name.value as { id: string }).id); | ||
break; | ||
@@ -127,4 +120,4 @@ } | ||
// for easier mapping on the nex | ||
const itemListings = listings.reduce<Record<ObjectId, KioskListing>>( | ||
(acc: Record<ObjectId, KioskListing>, item, idx) => { | ||
const itemListings = listings.reduce<Record<string, KioskListing>>( | ||
(acc: Record<string, KioskListing>, item, idx) => { | ||
acc[item.objectId] = { ...item }; | ||
@@ -136,6 +129,8 @@ | ||
const data = getObjectFields(listingObjects[idx]); | ||
const content = listingObjects[idx].data?.content; | ||
const data = content?.dataType === 'moveObject' ? content?.fields : null; | ||
if (!data) return acc; | ||
acc[item.objectId].price = data.value; | ||
acc[item.objectId].price = (data as { value: string }).value; | ||
return acc; | ||
@@ -154,6 +149,6 @@ }, | ||
*/ | ||
export function attachLockedItems(kioskData: KioskData, lockedItemIds: ObjectId[]) { | ||
export function attachLockedItems(kioskData: KioskData, lockedItemIds: string[]) { | ||
// map lock status in an array of type { item_id: true } | ||
const lockedStatuses = lockedItemIds.reduce<Record<ObjectId, boolean>>( | ||
(acc: Record<ObjectId, boolean>, item: string) => { | ||
const lockedStatuses = lockedItemIds.reduce<Record<string, boolean>>( | ||
(acc: Record<string, boolean>, item: string) => { | ||
acc[item] = true; | ||
@@ -190,4 +185,4 @@ return acc; | ||
export async function getAllDynamicFields( | ||
provider: JsonRpcProvider, | ||
parentId: ObjectId, | ||
client: SuiClient, | ||
parentId: string, | ||
pagination: PaginationArguments<string>, | ||
@@ -200,3 +195,3 @@ ) { | ||
while (hasNextPage) { | ||
const result = await provider.getDynamicFields({ | ||
const result = await client.getDynamicFields({ | ||
parentId, | ||
@@ -203,0 +198,0 @@ limit: pagination.limit || undefined, |
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
214565
186
3097
+ Added@mysten/sui.js@0.38.0(transitive)
- Removed@mysten/sui.js@0.37.1(transitive)
Updated@mysten/sui.js@0.38.0