UNPKG

@mai3/phaser-sdk

Version:

A UI component library based on the Phaser game engine

151 lines 5.88 kB
import { Address, AssetsSDK, TonClient4, TonClient4Parameters, Sender } from './external'; import { WalletConnector, WalletConnectorParams, Wallet, Account, WalletApp } from './interfaces'; import { IpfsGateway, UrlProxy } from './content-resolver'; export interface JettonTransferRequest { jetton: Address; to: Address; amount: bigint; customPayload?: string; forwardAmount?: bigint; forwardPayload?: string; } export interface TonTransferRequest { to: Address; amount: bigint; comment?: string; } export type Network = 'mainnet' | 'testnet'; export interface MerchantParams { tonAddress: Address | string; jettonAddress?: Address | string; } export interface ContentResolverParams { ipfsGateway?: IpfsGateway; urlProxy?: UrlProxy | string; } export interface GameFiInitializationParams { /** * @defaultValue testnet */ network?: Network; /** * Pass TonConnectUI instance to use HTML based flow. * Pass connector options to use game engine specific connect button implementation (headless mode), * like Phaser `createConnectButton` or draw connect button by yourself. * @defaultValue headless mode */ connector?: WalletConnector | WalletConnectorParams; /** * TonClient instance or only its params. */ client?: TonClient4 | TonClient4Parameters; /** * Loading collections, NFTs, etc. information requires requests to external resources. * Some of those resources may block direct requests from browsers by CORS policies. * Pass function or template string which will be used to generate proxy URL. For example: * `http://localhost:3000/cors-passthrough?url=%URL%` - %URL% will be replaced by URL * your proxy server should follow. */ contentResolver?: ContentResolverParams; /** * TON wallet address and jetton wallet address of in-game shop. * In-game purchases will be send to those addresses. */ merchant?: MerchantParams; } export interface Merchant { tonAddress: Address; jettonAddress?: Address; } export interface GameFiConstructorParams { walletConnector: WalletConnector; assetsSdk: AssetsSDK; merchant?: Merchant; } /** * GameFiBase is a parent for every implementation of GameFi. * Game engine specific implementations like Phaser only needs to define * its own `create` and `createConnectButton` methods. */ export declare abstract class GameFiBase { readonly walletConnector: WalletConnector; readonly assetsSdk: AssetsSDK; readonly sender: Sender; readonly merchant?: Merchant; constructor(params: GameFiConstructorParams); get wallet(): Wallet; get walletAccount(): Account; get walletAddress(): Address; get merchantAddress(): Address; get merchantJettonAddress(): Address; /** * Send TON to merchant wallet address (in-game shop). */ buyWithTon(params: Omit<TonTransferRequest, 'to'>): Promise<void>; /** * Send TON to other wallet address. */ transferTon(params: TonTransferRequest): Promise<void>; /** * Send jetton to merchant wallet address (in-game shop). */ buyWithJetton(params: Omit<JettonTransferRequest, 'to' | 'jetton'>): Promise<void>; /** * Send jetton to other wallet address. */ transferJetton(params: Omit<JettonTransferRequest, 'jetton'>): Promise<void>; /** * Open NFT collection contract. */ openNftCollection(address: Address): import("@ton/core").OpenedContract<import("@ton-community/assets-sdk").NftCollection>; /** * Open NFT sale contract. */ openNftSale(address: Address): import("@ton/core").OpenedContract<import("@ton-community/assets-sdk").NftSale>; /** * Open NFT contract. */ openNftItem(address: Address): import("@ton/core").OpenedContract<import("@ton-community/assets-sdk").NftItem>; /** * Get NFT item from collection using its index. */ openNftItemByIndex(collectionAddress: Address, itemIndex: bigint): Promise<import("@ton/core").OpenedContract<import("@ton-community/assets-sdk").NftItem>>; /** * Open SBT collection contract. */ openSbtCollection(address: Address): import("@ton/core").OpenedContract<import("@ton-community/assets-sdk").SbtCollection>; /** * Open Jetton contract. */ openJetton(address: Address): import("@ton/core").OpenedContract<import("@ton-community/assets-sdk").JettonMinter>; /** * Open Jetton Wallet contract. */ openJettonWallet(address: Address): import("@ton/core").OpenedContract<import("@ton-community/assets-sdk").JettonWallet>; /** * Call connectWallet programmatically in case * you are not going to use TonConnectUI provided UI or game engine provided button * and you draw your own UI. */ connectWallet(app: WalletApp): Promise<void>; /** * Watch weather wallet was connected or disconnected. * Use the method to reflect it on the UI state. */ onWalletChange(...params: Parameters<WalletConnector['onStatusChange']>): () => void; /** * Call connectWallet programmatically in case * you draw your own UI. */ disconnectWallet(): Promise<void>; private createMessagePayload; /** * Prepares dependencies to game engine implementations use it for `create` method. * These dependencies will be used to create an GameFi instance further. */ protected static createDependencies(params?: GameFiInitializationParams): Promise<GameFiConstructorParams>; protected static addressToObject(address: Address | string): Address; protected static isTonConnectUiInstance(instance: unknown): instance is WalletConnector; protected static createConnectUiWorkaround(params?: WalletConnectorParams): WalletConnector; } //# sourceMappingURL=game-fi.d.ts.map