@moveflow/sui-sdk.js
Version:
Typescript SDK for MoveFlow on SUI blockchain
305 lines (304 loc) • 13.6 kB
TypeScript
import { Network } from './config';
import { PaginatedObjectsResponse, SuiTransactionBlockResponse } from '@mysten/sui.js/dist/cjs/client/types';
import { PaginationArguments, TransactionBlock } from '@mysten/sui.js';
/**
* FeatureInfo describes features of a payment stream
*
* pauseable - if the payment stream can be paused by the sender
* senderCloseable - if the payment can be closed by the sender
* recipientModifiable - not used now
*/
export type FeatureInfo = {
pauseable: boolean;
senderCloseable: boolean;
recipientModifiable: boolean;
};
/**
* FeeInfo describes fee info of a payment stream
*
* feeRecipient - whenever a payment is withdrawn from the stream, a fee is paid to the recipient
* feePoint - the denominator of fee point is 10000, i.e, 25 means 0.25%
*/
export type FeeInfo = {
feeRecipient: string;
feePoint: number;
};
/**
* PauseInfo describes pausing info of a payment stream
*
* paused - if the stream is paused or not
* pausedAt - the time when the stream was paused, the value is unix epoch time in seconds
* accPausedTime - accumulated paused time of multiple pauses. It's reset to 0 once a payment is withdrawn
*/
export type PauseInfo = {
paused: boolean;
pausedAt: number;
accPausedTime: number;
};
/**
* StreamInfo describes a payment stream
*
* Explanation of most fields are omitted as the names are self-explanatory.
* The interval is time duration in seconds.
* The lastWithdrawTime, startTime and stopTime are unix epoch time in seconds.
*/
export type StreamInfo = {
id: string;
coinType: string;
name: string;
remark: string;
sender: string;
recipient: string;
interval: number;
ratePerInterval: number;
lastWithdrawTime: number;
startTime: number;
stopTime: number;
depositAmount: number;
withdrawnAmount: number;
remainingAmount: number;
closed: boolean;
featureInfo: FeatureInfo;
feeInfo: FeeInfo;
pauseInfo: PauseInfo;
balance: number;
};
/**
* StreamDirection enum describes the relationship between the payment stream and the users.
*
* OUT - outgoing stream. If a user sends money to the stream, the stream is the outgoing stream to the user.
* IN - incoming stream. If a user receives money from the stream, the stream is the incoming stream to the user.
*/
export declare enum StreamDirection {
OUT = 0,
IN = 1
}
export type StreamCreationResult = {
streamId: string;
senderCap: string;
recipientCap: string;
};
export type CoinConfig = {
coinType: string;
feePoint: number;
};
export type PaginatedCoinConfigs = {
coinConfigs: CoinConfig[];
nextCursor: string | null;
hasNextPage: boolean;
};
export type Paginatedstrings = {
objectIds: string[];
nextCursor: PaginatedObjectsResponse['nextCursor'];
hasNextPage: boolean;
};
export declare class Stream {
private _network;
private _config;
private _rpcProvider;
private readonly SUI;
constructor(network: Network);
get network(): Network;
get networkName(): string;
/**
* This function builds a TransactionBlock to create a new payment stream
*
* @param coinType the coin type that is used in the payment stream, e.g., 0x2::sui::SUI
*
* @param name the name of the stream, max 1024 characters
* @param remark the remark of the stream, max 1024 characters
* @param sender the payment sender's address, which must be the same as the TransactionBlock signer
* @param recipient the payment receiver's address
* @param depositAmount the initial deposit amount of the coin specified by the coinType parameter
* @param startTime the unix epoch time in seconds, i.e., Date.now() / 1000
* @param stopTime the unix epoch time in seconds
* @param interval the payment interval in seconds, and the deposit is divided evenly among the intervals. Default to 60 seconds
* @param closeable if the stream can be closed by the sender. Default to true
* @param modifiable if the stream can be modified by the recipient. Default to true. Not effective now
* @returns the TransactionBlock which can be signed to create a new payment stream
*/
createTransaction(coinType: string, name: string, remark: string, sender: string, recipient: string, depositAmount: bigint, startTime: number, stopTime: number, interval?: number, closeable?: boolean, modifiable?: boolean): Promise<TransactionBlock>;
/**
* This function builds a TransactionBlock to extend an existing payment stream
*
* @param coinType the coin type that is used in the payment stream, e.g., 0x2::sui::SUI
* @param sender the payment sender's address, which must be the same as the TransactionBlock signer
* @param senderCap the sender capability object id
* @param streamId the payment stream object id
* @param newStopTime the new stop time of the payment stream
* @returns the TransactionBlock which can be signed to extend an existing payment stream
*/
extendTransaction(coinType: string, sender: string, senderCap: string, streamId: string, newStopTime: number): Promise<TransactionBlock>;
/**
* This function builds a TransactionBlock to pause an existing payment stream
*
* @param coinType the coin type that is used in the payment stream, e.g., 0x2::sui::SUI
* @param senderCap the sender capability object id
* @param streamId the payment stream object id
* @returns the TransactionBlock which can be signed to pause an existing payment stream
*/
pauseTransaction(coinType: string, senderCap: string, streamId: string): TransactionBlock;
/**
* This function builds a TransactionBlock to resume a paused payment stream
*
* @param coinType the coin type that is used in the payment stream, e.g., 0x2::sui::SUI
* @param senderCap the sender capability object id
* @param streamId the payment stream object id
* @returns the TransactionBlock which can be signed to resume a paused payment stream
*/
resumeTransaction(coinType: string, senderCap: string, streamId: string): TransactionBlock;
/**
* This function builds a TransactionBlock to withdraw from a payment stream, whose signer must be the recipient.
*
* @param coinType the coin type that is used in the payment stream, e.g., 0x2::sui::SUI
* @param streamId the payment stream object id
* @returns the TransactionBlock which can be signed to withdraw from a payment stream.
*/
withdrawTransaction(coinType: string, streamId: string): TransactionBlock;
/**
* This function builds a TransactionBlock to set a new recipient of a payment stream, whose signer must be the current recipient.
*
* @param coinType the coin type that is used in the payment stream, e.g., 0x2::sui::SUI
* @param streamId the payment stream object id
* @returns the TransactionBlock which can be signed to set a new recipient of the payment stream.
*/
setNewRecipientTransaction(coinType: string, streamId: string, newRecipient: string): TransactionBlock;
/**
* This function builds a TransactionBlock to close an existing payment stream
*
* @param coinType the coin type that is used in the payment stream, e.g., 0x2::sui::SUI
* @param senderCap the sender capability object id
* @param streamId the payment stream object id
* @returns the TransactionBlock which can be signed to close an existing payment stream
*/
closeTransaction(coinType: string, senderCap: string, streamId: string): TransactionBlock;
/**
* This function parses a createTransaction response
*
* @param response the transaction response of the createTransaction
* @returns a StreamCreationResult struct
*/
getStreamCreationResult(response: SuiTransactionBlockResponse): StreamCreationResult;
/**
* This function get the payment streams specified by the parameters
*
* @param address the sender or recipient's address of the payment streams, depending on the direction
* @param direction the direction of the payment stream, IN or OUT. If IN, then the address is the recipient, otherwise, sender
* @returns an array of StreamInfo objects satisfying the parameters
*/
getStreams(address: string, direction: StreamDirection): Promise<StreamInfo[]>;
/**
* This function get the stream info specified by the id
*
* @param id the stream id
* @returns the StreamInfo object
*/
getStreamById(id: string): Promise<StreamInfo>;
/**
* This function returns the amount of the withdrawable fund in the payment stream
*
* @param stream the StreamInfo object
* @returns the amount of the withdrawable fund
*/
withdrawable(stream: StreamInfo): bigint;
/**
* This function returns true if the stream can be closed by the sender, and false otherwise
*
* @param stream the StreamInfo object
* @param sender the sender address
* @returns true if the stream can be closed by the sender, and false otherwise
*/
closeable(stream: StreamInfo, sender: string): boolean;
/**
* This function returns true if the stream can be paused by the sender, and false otherwise
*
* @param stream the StreamInfo object
* @param sender the sender address
* @returns true if the stream can be paused by the sender, and false otherwise
*/
pauseable(stream: StreamInfo, sender: string): boolean;
/**
* This function returns true if the stream can be modified by the recipient, and false otherwise
*
* @param stream the StreamInfo object
* @param recipient the recipient address
* @returns true if the stream can be modified by the recipient, and false otherwise
*/
recipientModifiable(stream: StreamInfo, recipient: string): boolean;
/**
* This function returns all the SenderCap object ids of the owner. Use this function if there aren't many (over 100) SenderCaps
*
* @param owner the owner of the SenderCaps
* @returns an array of SenderCap object ids
*/
getSenderCaps(owner: string): Promise<string[]>;
/**
* This function returns Paginatedstrings. Use this function if there are many (over 100) senderCaps
*
* @param owner the owner of the SenderCaps
* @param paginationArguments pagination arguments, such as cursor, limit
* @returns Paginatedstrings object
*/
getPaginatedSenderCaps(owner: string, paginationArguments: PaginationArguments<PaginatedObjectsResponse['nextCursor']>): Promise<Paginatedstrings>;
/**
* This function returns all the RecipientCap object ids of the owner. Use this function if there aren't many (over 100) RecipientCaps
*
* @param owner the owner of the RecipientCaps
* @returns an array of RecipientCap object ids
*/
getRecipientCaps(owner: string): Promise<string[]>;
/**
* This function returns Paginatedstrings. Use this function if there are many (over 100) recipientCaps
*
* @param owner the owner of the RecipientCaps
* @param paginationArguments pagination arguments, such as cursor, limit
* @returns Paginatedstrings object
*/
getPaginatedRecipientCaps(owner: string, paginationArguments: PaginationArguments<PaginatedObjectsResponse['nextCursor']>): Promise<Paginatedstrings>;
/**
* This function returns an array of all the supported coins. Use this function if there aren't many (over 100) coins supported.
*
* @returns all the supported coins
*/
getSupportedCoins(): Promise<CoinConfig[]>;
/**
* This function returns PaginatedCoinConfigs. Use this function if there are many (over 100) coins supported.
*
* @returns paginated supported coins
*/
getPaginatedSupportedCoins(paginationArguments: PaginationArguments<string | null>): Promise<PaginatedCoinConfigs>;
private getOwnedObjects;
private getPaginatedOwnedObjects;
private convert;
private extractCoinType;
private ensurePositiveInteger;
private ensureValidTime;
private ensureValidFeePoint;
private ensureValidCoinType;
private isSUI;
private getCoins;
private getCoin;
/**
* This function builds a TransactionBlock to register a coin type
*
* @param coinType the coin type that is used in the payment streams, e.g., 0x2::sui::SUI
* @param feePoint the denominator of fee point is 10000, i.e, 25 means 0.25%
* @returns the TransactionBlock which can be signed by the admin to register a new coin type
*/
registerCoinTransaction(coinType: string, feePoint: number): TransactionBlock;
/**
* This function builds a TransactionBlock to set a new fee point for the coin type
*
* @param coinType the coin type that is used in the payment streams, e.g., 0x2::sui::SUI
* @param newFeePoint the denominator of fee point is 10000, i.e, 25 means 0.25%
* @returns the TransactionBlock which can be signed by the admin to set the new fee point
*/
setFeePointTransaction(coinType: string, newFeePoint: number): TransactionBlock;
/**
* This function builds a TransactionBlock to set a new fee recipient
*
* @param newFeeRecipient the new fee recipient address
* @returns the TransactionBlock which can be signed by the admin to set the new fee recipient
*/
setFeeRecipientTransaction(newFeeRecipient: string): TransactionBlock;
}