@aresrpg/aresrpg-sdk
Advanced tools
Comparing version 2.3.0 to 2.4.0
{ | ||
"name": "@aresrpg/aresrpg-sdk", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "General SDK to interract with AresRPG", | ||
@@ -5,0 +5,0 @@ "type": "module", |
export const ITEM_CATEGORY = { | ||
// uncategorized item, usually simple resources | ||
MISC: 'misc', | ||
// consumable items, like potions | ||
CONSUMABLE: 'consumable', | ||
// rare relics | ||
// equipment | ||
RELIC: 'relic', | ||
// used to improve items | ||
RUNE: 'rune', | ||
// mounts | ||
MOUNT: 'mount', | ||
// equipment | ||
HAT: 'hat', | ||
// equipment | ||
CLOACK: 'cloack', | ||
// equipment | ||
AMULET: 'amulet', | ||
// equipment | ||
RING: 'ring', | ||
// equipment | ||
BELT: 'belt', | ||
// equipment | ||
BOOTS: 'boots', | ||
// weapon | ||
TITLE: 'title', | ||
PET: 'pet', | ||
// weapons | ||
BOW: 'bow', | ||
// weapon | ||
WAND: 'wand', | ||
// weapon | ||
STAFF: 'staff', | ||
// weapon | ||
DAGGER: 'dagger', | ||
// weapon | ||
SHOVEL: 'shovel', | ||
// weapon | ||
SWORD: 'sword', | ||
// weapon & tool | ||
SCYTHE: 'scythe', | ||
// weapon & tool | ||
AXE: 'axe', | ||
// weapon & tool | ||
HAMMER: 'hammer', | ||
// weapon & tool | ||
FISHING_ROD: 'fishing_rod', | ||
// weapon & tool | ||
PICKAXE: 'pickaxe', | ||
// additionnal equipable item like skins and titles | ||
TITLE: 'title', | ||
// misc | ||
KEY: 'key', | ||
PET: 'pet', | ||
// consumables | ||
ORB: 'orb', | ||
} | ||
export const EQUIPMENTS = [ | ||
ITEM_CATEGORY.RELIC, | ||
ITEM_CATEGORY.RUNE, | ||
ITEM_CATEGORY.MOUNT, | ||
ITEM_CATEGORY.HAT, | ||
ITEM_CATEGORY.CLOACK, | ||
ITEM_CATEGORY.AMULET, | ||
ITEM_CATEGORY.RING, | ||
ITEM_CATEGORY.BELT, | ||
ITEM_CATEGORY.BOOTS, | ||
ITEM_CATEGORY.TITLE, | ||
ITEM_CATEGORY.PET, | ||
] | ||
export const WEAPONS = [ | ||
ITEM_CATEGORY.BOW, | ||
ITEM_CATEGORY.WAND, | ||
ITEM_CATEGORY.STAFF, | ||
ITEM_CATEGORY.DAGGER, | ||
ITEM_CATEGORY.SHOVEL, | ||
ITEM_CATEGORY.SWORD, | ||
ITEM_CATEGORY.SCYTHE, | ||
ITEM_CATEGORY.AXE, | ||
ITEM_CATEGORY.HAMMER, | ||
ITEM_CATEGORY.FISHING_ROD, | ||
ITEM_CATEGORY.PICKAXE, | ||
] | ||
export const MISC = ['character', ITEM_CATEGORY.KEY] | ||
export const CONSUMABLES = [ITEM_CATEGORY.ORB] |
@@ -35,2 +35,6 @@ import { KioskClient, Network } from '@mysten/kiosk' | ||
import { get_locked_characters_by_ids } from './sui/read/get_locked_characters_by_ids.js' | ||
import { list_item } from './sui/write/list_item.js' | ||
import { SUPPORTED_NFTS } from './sui/supported_nfts.js' | ||
import { get_items } from './sui/cache.js' | ||
import { delist_item } from './sui/write/delist_item.js' | ||
@@ -46,2 +50,7 @@ const { | ||
const item_listed = type => `0x2::kiosk::ItemListed<${type}>` | ||
const item_purchased = type => `0x2::kiosk::ItemPurchased<${type}>` | ||
const item_delisted = type => `0x2::kiosk::ItemDelisted<${type}>` | ||
export { SUPPORTED_NFTS } | ||
export async function SDK({ | ||
@@ -124,2 +133,4 @@ rpc_url = getFullnodeUrl('testnet'), | ||
feed_suifren: feed_suifren(context), | ||
list_item: list_item(), | ||
delist_item: delist_item(), | ||
@@ -132,2 +143,4 @@ add_header: add_header(context), | ||
get_items: ids => get_items(context, ids, { allow_characters: true }), | ||
async get_sui_balance(owner) { | ||
@@ -141,5 +154,19 @@ const { totalBalance } = await sui_client.getBalance({ | ||
async subscribe(on_message) { | ||
const supported_types = [ | ||
`${types.PACKAGE_ID}::character::Character`, | ||
`${types.PACKAGE_ID}::item::Item`, | ||
...Object.keys(SUPPORTED_NFTS), | ||
] | ||
return sui_client.subscribeEvent({ | ||
onMessage: on_message, | ||
filter: { Package: types.PACKAGE_ID }, | ||
filter: { | ||
Any: [ | ||
{ Package: types.PACKAGE_ID }, | ||
...supported_types.flatMap(type => [ | ||
{ MoveEventType: item_listed(type) }, | ||
{ MoveEventType: item_purchased(type) }, | ||
{ MoveEventType: item_delisted(type) }, | ||
]), | ||
], | ||
}, | ||
}) | ||
@@ -146,0 +173,0 @@ }, |
@@ -5,2 +5,3 @@ import { LRUCache } from 'lru-cache' | ||
import { get_suifren_stats } from './suifrens.js' | ||
import { parse_character } from './parser.js' | ||
@@ -11,2 +12,3 @@ const DFIELD_CACHE = new LRUCache({ max: 10000 }) | ||
export function parse_sui_object({ types }, object) { | ||
if (object.error) return null | ||
const { | ||
@@ -21,5 +23,7 @@ content: { fields }, | ||
is_aresrpg_item: type === `${types.PACKAGE_ID}::item::Item`, | ||
is_aresrpg_character: type === `${types.PACKAGE_ID}::character::Character`, | ||
image_url: display?.data?.image_url, | ||
name: display?.data?.name || fields.name, | ||
id: fields.id.id, | ||
list_price: 0n, | ||
} | ||
@@ -81,4 +85,8 @@ } | ||
* ORDER IS NOT GUARANTEED | ||
* @type {(context: import("../../types.js").Context, ids: string[]) => Promise<Map<string, import("../../types.js").SuiItem>>} */ | ||
export async function get_items(context, ids) { | ||
* @type {(context: import("../../types.js").Context, ids: string[], options?: { allow_characters?: boolean }) => Promise<Map<string, import("../../types.js").SuiItem>>} */ | ||
export async function get_items( | ||
context, | ||
ids, | ||
{ allow_characters = false } = {}, | ||
) { | ||
const { sui_client, types } = context | ||
@@ -92,5 +100,5 @@ const unknown_ids = ids.filter(id => !OBJECT_CACHE.has(id)) | ||
const parsed_objects = unknown_objects.map(object => | ||
parse_sui_object({ types }, object), | ||
) | ||
const parsed_objects = unknown_objects | ||
.map(object => parse_sui_object({ types }, object)) | ||
.filter(Boolean) | ||
@@ -100,2 +108,4 @@ const { ares: ares_item, others: other_items } = parsed_objects.reduce( | ||
if (object.is_aresrpg_item) ares.push(object) | ||
else if (allow_characters && object.is_aresrpg_character) | ||
ares.push(object) | ||
else others.push(object) | ||
@@ -140,2 +150,4 @@ return { ares, others } | ||
ares_item.map(async item => { | ||
if (item.is_aresrpg_character) return parse_character(context)(item) | ||
// cached stats | ||
@@ -178,3 +190,6 @@ const stats = await get_dynamic_field_object(sui_client, { | ||
internal_items.forEach(item => OBJECT_CACHE.set(item.id, item)) | ||
internal_items | ||
// ignore characters | ||
.filter(item => item.is_aresrpg_item) | ||
.forEach(item => OBJECT_CACHE.set(item.id, item)) | ||
@@ -181,0 +196,0 @@ return new Map( |
@@ -56,2 +56,7 @@ import { get_items, get_purchase_caps } from './cache.js' | ||
...character, | ||
item_type: 'character', | ||
item_category: 'character', | ||
item_set: 'none', | ||
amount: 1, | ||
inventory: null, | ||
position: JSON.parse(character.position), | ||
@@ -58,0 +63,0 @@ // @ts-ignore |
@@ -26,6 +26,7 @@ import { parse_sui_object } from '../cache.js' | ||
withObjects: true, | ||
objectOptions: { showContent: true }, | ||
objectOptions: { showContent: true, showDisplay: true }, | ||
}, | ||
}) | ||
return characters | ||
.filter(({ listing }) => !listing) | ||
.map(object => parse_sui_object({ types }, object)) | ||
@@ -32,0 +33,0 @@ .filter( |
@@ -7,3 +7,3 @@ import { get_items } from '../cache.js' | ||
/** @type {(address: string) => Promise<import("../../../types.js").SuiItem[]>} */ | ||
return async address => { | ||
return async (address, only_listed) => { | ||
const { kioskOwnerCaps } = await kiosk_client.getOwnedKiosks({ | ||
@@ -23,2 +23,3 @@ address, | ||
withObjects: false, | ||
withListingPrices: true, | ||
}, | ||
@@ -28,4 +29,12 @@ }) | ||
return items | ||
.filter(({ listing }) => !listing) | ||
.map(({ objectId }) => ({ | ||
.filter(({ listing }) => { | ||
if (only_listed) { | ||
// here we only want listed items | ||
if (!listing) return false | ||
// if the listing is exclusive, we don't want it | ||
return !listing.isExclusive | ||
} | ||
return !listing | ||
}) | ||
.map(({ objectId, listing }) => ({ | ||
id: objectId, | ||
@@ -35,2 +44,3 @@ kiosk_id, | ||
is_kiosk_personal, | ||
...(listing && { list_price: BigInt(listing.price) }), | ||
})) | ||
@@ -44,2 +54,3 @@ }), | ||
objects.map(({ id }) => id), | ||
{ allow_characters: true }, | ||
) | ||
@@ -46,0 +57,0 @@ |
@@ -22,2 +22,3 @@ import { ITEM_CATEGORY } from '../items.js' | ||
air_resistance: 3, | ||
amount: 1, | ||
}, | ||
@@ -30,2 +31,3 @@ [BULLSHARK]: { | ||
name: 'Capy', | ||
amount: 1, | ||
}, | ||
@@ -40,3 +42,4 @@ [PRIME_MACHIN]: { | ||
raw_damage: 3, | ||
amount: 1, | ||
}, | ||
} |
export type Context = { | ||
sui_client: import('@mysten/sui.js/client').SuiClient | ||
kiosk_client: import('@mysten/kiosk').KioskClient | ||
types: import('./types-parser.js').SuiIds | ||
types: import('./src/types-parser.js').SuiIds | ||
network: import('@mysten/kiosk').Network | ||
@@ -44,2 +44,4 @@ } | ||
amount: number | ||
// kiosk related | ||
@@ -49,5 +51,8 @@ kiosk_id: string | ||
personal_kiosk_cap_id: string | ||
list_price?: bigint | ||
seller?: string | ||
// type related | ||
is_aresrpg_item: boolean | ||
is_aresrpg_character: boolean | ||
image_url: string | ||
@@ -54,0 +59,0 @@ _type: string |
export namespace ITEM_CATEGORY { | ||
let MISC: string; | ||
let CONSUMABLE: string; | ||
let RELIC: string; | ||
@@ -13,2 +11,4 @@ let RUNE: string; | ||
let BOOTS: string; | ||
let TITLE: string; | ||
let PET: string; | ||
let BOW: string; | ||
@@ -25,5 +25,8 @@ let WAND: string; | ||
let PICKAXE: string; | ||
let TITLE: string; | ||
let KEY: string; | ||
let PET: string; | ||
let ORB: string; | ||
} | ||
export const EQUIPMENTS: string[]; | ||
export const WEAPONS: string[]; | ||
export const MISC: string[]; | ||
export const CONSUMABLES: string[]; |
@@ -12,3 +12,3 @@ export function SDK({ rpc_url, wss_url, network, websocket_constructor, }: { | ||
get_locked_items: (address: string) => Promise<import("../types.js").SuiItem[]>; | ||
get_unlocked_items: (address: string) => Promise<import("../types.js").SuiItem[]>; | ||
get_unlocked_items: (address: string, only_listed: any) => Promise<import("../types.js").SuiItem[]>; | ||
get_item_by_id: (id: string) => Promise<import("../types.js").SuiItem>; | ||
@@ -106,2 +106,17 @@ get_suifren_object_accessory: (suifren_id: any) => Promise<any>; | ||
}) => void; | ||
list_item: ({ tx, kiosk, kiosk_cap, item_id, item_type, price, }: { | ||
tx?: import("@mysten/sui.js/transactions").TransactionBlock; | ||
kiosk: any; | ||
kiosk_cap: any; | ||
item_id: any; | ||
item_type: any; | ||
price: any; | ||
}) => void; | ||
delist_item: ({ tx, kiosk, kiosk_cap, item_id, item_type, }: { | ||
tx?: import("@mysten/sui.js/transactions").TransactionBlock; | ||
kiosk: any; | ||
kiosk_cap: any; | ||
item_id: any; | ||
item_type: any; | ||
}) => void; | ||
add_header: (tx: any) => any; | ||
@@ -129,2 +144,3 @@ admin_promote: ({ tx, recipient }: { | ||
}) => import("@mysten/sui.js/transactions").TransactionBlock; | ||
get_items: (ids: any) => Promise<Map<string, import("../types.js").SuiItem>>; | ||
get_sui_balance(owner: any): Promise<bigint>; | ||
@@ -149,4 +165,6 @@ subscribe(on_message: any): Promise<import("@mysten/sui.js/client").Unsubscribe>; | ||
}>; | ||
export { SUPPORTED_NFTS }; | ||
import { Network } from '@mysten/kiosk'; | ||
import { SuiClient } from '@mysten/sui.js/client'; | ||
import { KioskClient } from '@mysten/kiosk'; | ||
import { SUPPORTED_NFTS } from './sui/supported_nfts.js'; |
@@ -7,2 +7,4 @@ export function parse_sui_object({ types }: { | ||
export function get_purchase_caps(context: any, caps: any): Promise<any>; | ||
export function get_items(context: import("../../types.js").Context, ids: string[]): Promise<Map<string, import("../../types.js").SuiItem>>; | ||
export function get_items(context: import("../../types.js").Context, ids: string[], options?: { | ||
allow_characters?: boolean; | ||
}): Promise<Map<string, import("../../types.js").SuiItem>>; |
/** @param {import("../../../types.js").Context} context */ | ||
export function get_unlocked_items(context: import("../../../types.js").Context): (address: string) => Promise<import("../../../types.js").SuiItem[]>; | ||
export function get_unlocked_items(context: import("../../../types.js").Context): (address: string, only_listed: any) => Promise<import("../../../types.js").SuiItem[]>; |
@@ -15,2 +15,3 @@ export const BULLSHARK: "0x80d7de9c4a56194087e0ba0bf59492aa8e6a5ee881606226930827085ddf2332::suifrens::SuiFren<0x80d7de9c4a56194087e0ba0bf59492aa8e6a5ee881606226930827085ddf2332::capy::Capy>"; | ||
air_resistance: number; | ||
amount: number; | ||
}; | ||
@@ -23,2 +24,3 @@ "0x80d7de9c4a56194087e0ba0bf59492aa8e6a5ee881606226930827085ddf2332::suifrens::SuiFren<0x80d7de9c4a56194087e0ba0bf59492aa8e6a5ee881606226930827085ddf2332::capy::Capy>": { | ||
name: string; | ||
amount: number; | ||
}; | ||
@@ -33,3 +35,4 @@ "0x034c162f6b594cb5a1805264dd01ca5d80ce3eca6522e6ee37fd9ebfb9d3ddca::factory::PrimeMachin": { | ||
raw_damage: number; | ||
amount: number; | ||
}; | ||
}; |
108946
99
3226