myria-core-sdk
Version:
Latest version SDK
478 lines (449 loc) • 26.6 kB
TypeScript
import { IMyriaClient } from "../clients/MyriaClient";
import { APIResponseType } from "../types/APIResponseType";
import { BulkTransferTokenRequestAPIParams, BulkTransferTokenResponse, TransactionPagingDetails, SignableBulkTransferParams, SignableBulkTransferResponse, TransactionCompleteParams, TransactionCompleteResponse, TransactionData, TransferCommonParams, TransferERC20Params, TransferERC721Params, TransferResponse, TransferTokenParams, TransactionPagingData, BurnTokenParams, BurnTokenResponse, WhitelistTokensResponse, TransferETHParams } from "../types/TransactionTypes";
/**
* Create TransactionManager module
* @class TransactionManager
* @param {IMyriaClient} IMyriaClient Interface of Myria Client
* @example <caption>TransactionManage instance.</caption>
* // + Approach 1:
const mClient: IMyriaClient = {
networkId: Network.SEPOLIA,
provider: web3Instance.currentProvider,
web3: web3Instance,
env: EnvTypes.STAGING,
};
const moduleFactory = ModuleFactory.getInstance(mClient);
const transactionManager = moduleFactory.getTransactionManager();
// + Approach 2:
const mClient: IMyriaClient = {
networkId: Network.SEPOLIA,
provider: web3Instance.currentProvider,
web3: web3Instance,
env: EnvTypes.STAGING,
};
const transactionManager = new TransactionManager(mClient);
*/
export declare class TransactionManager {
private transactionAPI;
private assetMarketplaceAPI;
private commonModule;
private commonAPI;
constructor(mClient: IMyriaClient);
/**
* @summary Get transaction history list by stark key with paging options. This is designed for the purposes of small history reports sorted by latest date.
* @description Paging can be shown one after another (you cannot request for page 3 without first seeing page 1 and 2, for example, as you need details of last transaction of previous page to query for next page).
* @param {TransactionPagingDetails} TransactionPagingDetails Request params to query the list of transactions
* @returns {TransactionData[]} List of transaction details
*/
getTransactionList(payload: TransactionPagingDetails): Promise<any>;
/**
* @summary Get transaction details by transaction ID
* @param {number} transactionId Unique ID of transaction
* @returns {TransactionData} Transaction details information (including transactionStatus and createdAt, updatedAt...)
* @throws {string} Exception: Transaction ID should be valided and greater than 0
* @throws {string} Exception: Get transaction details failed with internal server error
*/
getTransactionDetails(transactionId: number): Promise<TransactionData>;
/**
* @summary Single Transfer ERC-721 (MINTABLE NFT) Token
* + The function is just supported for MINTABLE_ERC721 only
* @description After transfer was triggered, we can query the status of the transaction with the following functions:
* + getTransactionDetails(transactionId: number) {return TransactionData}
* + getTransactionsByPartnerRefID(partnerRefID: string) {return []TransactionData}
* @param {TransferERC721Params} transferParams Transfer ERC-721 token params (including sender and receiver's information)
* @throws {string} Exception: Sender vault is not found
* @throws {string} Exception: Receiver vault is not found
* @throws {string} Http Status 400 - Sender/Receiver vaults does not exist
* @throws {string} Http Status 400 - Signature is invalid
* @throws {string} Http Status 400 - Vault IDs does not have enough funds
* @returns {TransferResponse} Transaction details (such as transactionID, transactionStatus...)
*/
transferERC721Token(transferParams: TransferERC721Params): Promise<TransferResponse>;
/**
* @summary Asynchronous bulk transfer for NFT Tokens (such as: ERC-721 Tokens, Marketplace NFTs)
* - Function only supports MINTABLE_ERC721 and NFTs which are minted on Myria System
* @param {TransferTokenParams} transferTokenParams Data regarding sender and receivers relevant for the transfer.
* @description After bulk transfer was triggered, we can query the status of the batch with the following functions:
* + getTransactionsByGroupRequestIDAndPartnerRefID(groupRequestID: string, partnerRefID: string)
* + getTransactionsByPartnerRefID(partnerRefID: string)
* @returns {BulkTransferTokenResponse} Transaction data list which have been captured and validated
* - Response structure consist of 3 group of transactions failed[] / success[] / validationFailed[]
* - All transactions in failed[], relate to failures due to not enough funds or other internal server errors. These transactions cannot be processed.
* - All transactions in validationFailed[], relate to failures due to validation such as L2's signature. These can be retried with amended data.
* - All transactions in success[], indicate that they have been recorded and will be processed by the system.
* @throws {string} Exception: Sender wallet address is required
* @throws {string} Exception: Bulk transfer should include at least one transfer
* @throws {string} Exception: Receiver wallet address is required
* @throws {string} Exception: Only MINTABLE_ERC-721 tokens are valid for this type of bulk transfer
* @throws {string} Exception: Token address is required
* @throws {string} Error code 409 - Request-ID/Group-Request-ID is already exists
* @throws {string} Http error code 400 - User wallet (sender or receiver) is not registered
* @throws {string} Http error code 400 - Vault ID does not have enough funds
* @throws {string} Http error code 400 - Signature is invalid
* @example <caption>Sample code on Testnet (Staging) env</caption>
*
const mClient: IMyriaClient = {
networkId: Network.SEPOLIA,
provider: web3Instance.currentProvider,
web3: web3Instance,
env: EnvTypes.STAGING,
};
const YOUR_NFT_CONTRACT_ADDRESS = "0xA06116D9....";
const RECEIVER_WALLET_ADDRESS = '0xd0D8A467E....'; // Your receiver/users wallet address
const SENDER_WALLET_ADDRESS = '0x724f337bF0F....'; // Must be the owner of tokens, sender wallet address
const moduleFactory = ModuleFactory.getInstance(mClient);
const transactionManager = moduleFactory.getTransactionManager();
const transferredItems: ItemSignableTransferParams[] = [
{
quantizedAmount: 1, // Should be 1 as always
receiverWalletAddress: RECEIVER_WALLET_ADDRESS,
tokenType: TokenType.MINTABLE_ERC721,
tokenData: {
tokenAddress: YOUR_NFT_CONTRACT_ADDRESS,
tokenId: '1' // Your minted token ID
},
},
{
quantizedAmount: 1,
receiverWalletAddress: RECEIVER_WALLET_ADDRESS,
tokenType: TokenType.MINTABLE_ERC721,
tokenData: {
tokenAddress: YOUR_NFT_CONTRACT_ADDRESS,
tokenId: '2' // Your minted token ID
},
},
{
quantizedAmount: 1,
receiverWalletAddress: RECEIVER_WALLET_ADDRESS,
tokenType: TokenType.MINTABLE_ERC721,
tokenData: {
tokenAddress: YOUR_NFT_CONTRACT_ADDRESS,
tokenId: '3' // Your minted token ID
},
},
];
const transferTokenParams: TransferTokenParams = {
senderWalletAddress: SENDER_WALLET_ADDRESS,
groupRequestId: '7257d29c-c96a-4302-8eaf-368a0d62b977', // Can use random UUID to generate groupRequestID
requestId: '7257d29c-c96a-4302-8eaf-368a0d62b977', // Can use random UUID to generate requestID
partnerRefId: 'Project-ID', // Project-ID on Myria System
description: 'Test-Test Bulk Transfer',
items: transferredItems,
};
const transferResult = await transactionManager.bulkTransferNfts(
transferTokenParams,
);
*
*/
bulkTransferNfts(transferTokenParams: TransferTokenParams): Promise<APIResponseType<BulkTransferTokenResponse>>;
bulkTransferNftsV2(transferTokenParams: TransferTokenParams): Promise<APIResponseType<BulkTransferTokenResponse>>;
getSignableDetailsTransferERC20(transferTokenParams: TransferTokenParams): Promise<BulkTransferTokenRequestAPIParams>;
/**
* @summary Async bulk transfer for ERC-20 Tokens (such as: Myria Tokens, ...)
* - Function only supports ERC20 and Myria Tokens (ERC20) which are registered in Myria System already (i.e. via a deposit).
* @param {TransferTokenParams} transferTokenParams Data regarding sender and receivers relevant for the transfer.
* @description After bulk transfer was triggered, we can query the status of the batch with the following functions:
* + getTransactionsByGroupRequestIDAndPartnerRefID(groupRequestID: string, partnerRefID: string)
* + getTransactionsByPartnerRefID(partnerRefID: string)
* @example <caption>Sample code on Testnet (Staging) env</caption>
const mClient: IMyriaClient = {
networkId: Network.SEPOLIA,
provider: web3Instance.currentProvider,
web3: web3Instance,
env: EnvTypes.STAGING,
};
const MYR_TOKEN_ADDRESS_EXAMPLE = "0xA06116D9...."; // ERC-20 token address - and make sure it is registered in Myria System already
const RECEIVER_WALLET_ADDRESS = '0xd0D8A467E....'; // Your receiver/users wallet address
const SENDER_WALLET_ADDRESS = '0x724f337bF0F....'; // Must be the owner of tokens, sender wallet address
const moduleFactory = ModuleFactory.getInstance(mClient);
const transactionManager = moduleFactory.getTransactionManager();
const transferredItems: ItemSignableTransferParams[] = [
{
quantizedAmount: String(convertAmountToQuantizedAmount(1)),
receiverWalletAddress: RECEIVER_WALLET_ADDRESS,
tokenType: TokenType.ERC20,
tokenData: {
tokenAddress: MYR_TOKEN_ADDRESS_EXAMPLE,
},
},
{
quantizedAmount: String(convertAmountToQuantizedAmount(2)),
receiverWalletAddress: RECEIVER_WALLET_ADDRESS,
tokenType: TokenType.ERC20,
tokenData: {
tokenAddress: MYR_TOKEN_ADDRESS_EXAMPLE,
},
},
{
quantizedAmount: String(convertAmountToQuantizedAmount(3)),
receiverWalletAddress: RECEIVER_WALLET_ADDRESS,
tokenType: TokenType.ERC20,
tokenData: {
tokenAddress: MYR_TOKEN_ADDRESS_EXAMPLE,
},
},
];
const transferTokenParams: TransferTokenParams = {
senderWalletAddress: SENDER_WALLET_ADDRESS,
groupRequestId: '7257d29c-c96a-4302-8eaf-368a0d62b977', // Can use random UUID to generate groupRequestID
requestId: '7257d29c-c96a-4302-8eaf-368a0d62b977', // Can use random UUID to generate requestID
partnerRefId: 'Project-ID', // Partner project ID
description: 'Test-Test Bulk Transfer',
items: transferredItems,
};
const transferResult = await transactionManager.bulkTransferERC20Token(
transferTokenParams,
);
* @returns {BulkTransferTokenResponse} Transaction data list which have been captured and validated
* - Response structure consist of 3 group of transactions: failed[] / success[] / validationFailed[]
* - All transactions in failed[], relate to failures due to not enough funds or other internal server errors. These transactions cannot be processed.
* - All transactions in validationFailed[], relate to failures due to validation such as L2's signature. These can be retried with amended data.
* - All transactions in success[], indicate that they have been recorded and will be processed by the system.
* @throws {string} Exception: Sender wallet address is required
* @throws {string} Exception: Bulk transfer should include at least one transfer
* @throws {string} Exception: Receiver wallet address is required
* @throws {string} Exception: Only ERC20 Tokens are valid for this type of bulk transfer
* @throws {string} Exception: Token address is required
* @throws {string} Http error code 409 - Request-ID/Group-Request-ID already exists
* @throws {string} Http error code 400 - User wallet (sender or receiver) is not registered
* @throws {string} Http error code 400 - Vault ID does not have enough funds
* @throws {string} Http error code 400 - Signature is invalid
*/
bulkTransferERC20Token(transferTokenParams: TransferTokenParams): Promise<APIResponseType<BulkTransferTokenResponse>>;
getTransactionsByRequestID(requestID: string): Promise<APIResponseType<TransactionData[]>>;
/**
* @description Query a list of transactions based on group request ID and Partner Ref ID
* @param {string} groupReqID The unique group request ID of the transaction batch
* @param {string} partnerRefID The unique partner reference ID as Project ID
* @param {TransactionPagingDetails=} transactionPaging The pagination params (which included starkKey, limit, createdAt, transactionCategory for query next page)
* @throws {string} Exception: Partner Reference ID is required
* @throws {string} Exception: Group Request ID is required
* @returns {TransactionData[]} List of transactions data which indicate the status of batch, transaction results, transaction details information
* (such as transactionID, transactionStatus...)
* @example <caption>Sample code on Testnet (Staging) env</caption>
const mClient: IMyriaClient = {
networkId: Network.SEPOLIA,
provider: web3Instance.currentProvider,
web3: web3Instance,
env: EnvTypes.STAGING,
};
const groupRequestID = "e2fb1ef6-680b-4515-9ca6-0c46bc026ecd";
const partnerRefId = "10"; // Unique ItemSignableTransferParamsProject ID in Myria System
const moduleFactory = ModuleFactory.getInstance(mClient);
const transactionManager = moduleFactory.getTransactionManager();
const result = await transactionManager.getTransactionsByGroupRequestIDAndPartnerRefID(
groupRequestID,
partnerRefId
);
console.log('Transaction result -> ', result);
*/
getTransactionsByGroupRequestIDAndPartnerRefID(groupReqID: string, partnerRefID: string, transactionPaging?: TransactionPagingDetails): Promise<APIResponseType<TransactionPagingData>>;
/**
* @description Query a list of transactions based on partner reference ID (which should be project ID)
* @param partnerRefID The unique partner reference ID (Project ID)
* @throws {string} Exception: Partner reference ID is required
* @returns {TransactionData[]} List of transactions data which indicate the status of batch, transaction results, transaction details information
* (such as transactionID, transactionStatus...)
* @example <caption>Sample code on Testnet (Staging) env</caption>
const mClient: IMyriaClient = {
networkId: Network.SEPOLIA,
provider: web3Instance.currentProvider,
web3: web3Instance,
env: EnvTypes.STAGING,
};
const partnerRefId = "Project-ID"; // Unique ID of the project on Myria System
const moduleFactory = ModuleFactory.getInstance(mClient);
const transactionManager = moduleFactory.getTransactionManager();
const result = await transactionManager.getTransactionsByPartnerRefID(
partnerRefId
);
console.log('Transaction result -> ', result);
*/
getTransactionsByPartnerRefID(partnerRefID: string): Promise<APIResponseType<TransactionData[]>>;
signableBulkTransferDetail(params: SignableBulkTransferParams): Promise<SignableBulkTransferResponse>;
/**
* @summary Single Transfer ERC-20 Token
* @param {TransferERC20Params} transferParams Transfer ERC-20 Tokens params (include information for Sender/Receiver)
* @description After transfer was triggered, we can query the status of the transaction with the following functions:
* + getTransactionDetails(transactionId: number) {return TransactionData}
* + getTransactionsByPartnerRefID(partnerRefID: string) {return []TransactionData}
* @returns {TransferResponse} Transactions data which indicate the status of batch, transaction results, transaction details information
* (such as transactionID, transactionStatus...)
* @throws {string} Exception: Sender vault is not found
* @throws {string} Exception: Receiver vault is not found
* @throws {string} Http Status 400 - Sender/Receiver vaults do not exist
* @throws {string} Http Status 400 - Signature is invalid
* @throws {string} Http Status 400 - Vault IDs does not have enough funds
*/
transferERC20Token(transferParams: TransferERC20Params): Promise<TransferResponse>;
/**
* @summary Single Transfer ERC-20 Token
* @param {TransferERC20Params} transferParams Transfer ERC-20 Tokens params (include information for Sender/Receiver)
* @description After transfer was triggered, we can query the status of the transaction with the following functions:
* + getTransactionDetails(transactionId: number) {return TransactionData}
* + getTransactionsByPartnerRefID(partnerRefID: string) {return []TransactionData}
* @returns {TransferResponse} Transactions data which indicate the status of batch, transaction results, transaction details information
* (such as transactionID, transactionStatus...)
* @throws {string} Exception: Sender vault is not found
* @throws {string} Exception: Receiver vault is not found
* @throws {string} Http Status 400 - Sender/Receiver vaults do not exist
* @throws {string} Http Status 400 - Signature is invalid
* @throws {string} Http Status 400 - Vault IDs does not have enough funds
*/
transferETHToken(transferParams: TransferETHParams): Promise<TransferResponse>;
transferTokenCommon(transferParams: TransferCommonParams): Promise<TransferResponse>;
updateTransactionComplete(payload: TransactionCompleteParams): Promise<APIResponseType<TransactionCompleteResponse>>;
/**
* @summary Asynchronous burn for NFT Tokens (such as: ERC-721 Tokens, Marketplace NFTs)
* - Function only supports MINTABLE_ERC721 and NFTs which are minted on Myria System
* @param {BurnTokenParams} burnTokenParams Data regarding sender and receivers relevant for the burn transfer.
* @description After burn transfer was triggered, we can query the status of the batch with the following functions:
* + getTransactionsByGroupRequestIDAndPartnerRefID(groupRequestID: string, partnerRefID: string)
* + getTransactionsByPartnerRefID(partnerRefID: string)
* @returns {BurnTokenResponse} Transaction data list which have been captured and validated
* - Response structure consist of 3 group of transactions failed[] / success[] / validationFailed[]
* - All transactions in failed[], relate to failures due to not enough funds or other internal server errors. These transactions cannot be processed.
* - All transactions in validationFailed[], relate to failures due to validation such as L2's signature. These can be retried with amended data.
* - All transactions in success[], indicate that they have been recorded and will be processed by the system.
* @throws {string} Exception: Sender wallet address is required
* @throws {string} Exception: Burn transfer should include at least one transfer
* @throws {string} Exception: Only MINTABLE_ERC-721 tokens are valid for this type of bulk transfer
* @throws {string} Exception: Token address is required
* @throws {string} Error code 409 - Request-ID/Group-Request-ID is already exists
* @throws {string} Http error code 400 - User wallet (sender or receiver) is not registered
* @throws {string} Http error code 400 - Vault ID does not have enough funds
* @throws {string} Http error code 400 - Signature is invalid
* @example <caption>Sample code on Testnet (Staging) env</caption>
*
const mClient: IMyriaClient = {
networkId: Network.SEPOLIA,
provider: web3Instance.currentProvider,
web3: web3Instance,
env: EnvTypes.STAGING,
};
const YOUR_NFT_CONTRACT_ADDRESS = "0xA06116D9....";
const SENDER_WALLET_ADDRESS = '0x724f337bF0F....'; // Must be the owner of tokens, sender wallet address
const moduleFactory = ModuleFactory.getInstance(mClient);
const transactionManager = moduleFactory.getTransactionManager();
const burnTransferredItems: ItemSignableBurnTransferParams[] = [
{
quantizedAmount: 1, // Should be 1 as always
tokenType: TokenType.MINTABLE_ERC721,
tokenData: {
tokenAddress: YOUR_NFT_CONTRACT_ADDRESS,
tokenId: '1' // Your minted token ID,
quantum: '1'
},
},
{
quantizedAmount: 1,
tokenType: TokenType.MINTABLE_ERC721,
tokenData: {
tokenAddress: YOUR_NFT_CONTRACT_ADDRESS,
tokenId: '2' // Your minted token ID,
},
},
{
quantizedAmount: 1,
tokenType: TokenType.MINTABLE_ERC721,
tokenData: {
tokenAddress: YOUR_NFT_CONTRACT_ADDRESS,
tokenId: '3' // Your minted token ID
},
},
];
const burnTransferTokenParams: BurnTokenParams = {
senderWalletAddress: SENDER_WALLET_ADDRESS,
groupRequestId: '7257d29c-c96a-4302-8eaf-368a0d62b977', // Can use random UUID to generate groupRequestID
requestId: '7257d29c-c96a-4302-8eaf-368a0d62b977', // Can use random UUID to generate requestID
partnerRefId: 'Project-ID', // Project-ID on Myria System
description: 'Test-Test Burn Transfer',
items: burnTransferredItems,
};
const burnTransferResult = await transactionManager.burnNfts(
burnTransferTokenParams,
);
*
*/
burnNfts(burnTokenParams: BurnTokenParams): Promise<APIResponseType<BurnTokenResponse>>;
/**
* @summary Asynchronous burn for ERC-20 Tokens or Ethers Tokens (such as: ERC-20, Myria Tokens, Eth)
* - Function only supports ERC-20 standard tokens and Eth on Myria System
* @param {BurnTokenParams} burnTransferTokenParams Data regarding sender and receivers relevant for the burn.
* @description After burn transfer was triggered, we can query the status of the batch with the following functions:
* + getTransactionsByGroupRequestIDAndPartnerRefID(groupRequestID: string, partnerRefID: string)
* + getTransactionsByPartnerRefID(partnerRefID: string)
* @returns {BurnTokenResponse} Transaction data list which have been captured and validated
* - Response structure consist of 3 group of transactions failed[] / success[] / validationFailed[]
* - All transactions in failed[], relate to failures due to not enough funds or other internal server errors. These transactions cannot be processed.
* - All transactions in validationFailed[], relate to failures due to validation such as L2's signature. These can be retried with amended data.
* - All transactions in success[], indicate that they have been recorded and will be processed by the system.
* @throws {string} Exception: Sender wallet address is required
* @throws {string} Exception: Burn transfer should include at least one transfer
* @throws {string} Exception: Only ERC-20 or Eth tokens are valided for this burn action
* @throws {string} Exception: Token address is required
* @throws {string} Error code 409 - Request-ID/Group-Request-ID is already exists
* @throws {string} Http error code 400 - User wallet (sender or receiver) is not registered
* @throws {string} Http error code 400 - Vault ID does not have enough funds
* @throws {string} Http error code 400 - Signature is invalid
* @example <caption>Sample code on Testnet (Staging) env</caption>
*
const mClient: IMyriaClient = {
networkId: Network.SEPOLIA,
provider: web3Instance.currentProvider,
web3: web3Instance,
env: EnvTypes.STAGING,
};
const YOUR_TOKEN_CONTRACT_ADDRESS = "0xA06116D9....";
const SENDER_WALLET_ADDRESS = '0x724f337bF0F....'; // Must be the owner of tokens, sender wallet address
const moduleFactory = ModuleFactory.getInstance(mClient);
const transactionManager = moduleFactory.getTransactionManager();
const QUANTUM = 10000000000;
const burnTransferredItems: ItemSignableBurnParams[] = [
{
quantizedAmount: 1, // Should be 1 as always
tokenType: TokenType.ERC20,
tokenData: {
tokenAddress: YOUR_TOKEN_CONTRACT_ADDRESS,
quantum: QUANTUM
},
},
{
quantizedAmount: 1,
tokenType: TokenType.ERC20,
tokenData: {
tokenAddress: YOUR_TOKEN_CONTRACT_ADDRESS,
quantum: QUANTUM
},
},
{
quantizedAmount: 1,
tokenType: TokenType.ERC20,
tokenData: {
tokenAddress: YOUR_TOKEN_CONTRACT_ADDRESS,
quantum: QUANTUM
},
},
];
const burnTokensParams: BurnTokenParams = {
senderWalletAddress: SENDER_WALLET_ADDRESS,
groupRequestId: '7257d29c-c96a-4302-8eaf-368a0d62b977', // Can use random UUID to generate groupRequestID
requestId: '7257d29c-c96a-4302-8eaf-368a0d62b977', // Can use random UUID to generate requestID
partnerRefId: 'Project-ID', // Project-ID on Myria System
description: 'Test-Test Burn Transfer',
items: burnTransferredItems,
};
const burnTransferResult = await transactionManager.burnERC20Tokens(
burnTransferTokenParams,
);
*
*/
burnERC20Tokens(burnTransferTokenParams: BurnTokenParams): Promise<APIResponseType<BurnTokenResponse>>;
/**
* @summary Get list of tokens supported in Myria
* @description Get details tokens list data which is supported in Myria including TokenHex, TokenQuantum...
* @returns {WhitelistTokensResponse} Whitelist tokens data
**/
getSupportedTokens(): Promise<WhitelistTokensResponse>;
}