stellar-plus
Version:
beta version of stellar-plus, an all-in-one sdk for the Stellar blockchain
85 lines (84 loc) • 3.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SACHandler = void 0;
const tslib_1 = require("tslib");
const stellar_sdk_1 = require("@stellar/stellar-sdk");
const classic_1 = require("../../../stellar-plus/asset/classic");
const soroban_token_1 = require("../../../stellar-plus/asset/soroban-token");
const types_1 = require("../../../stellar-plus/asset/types");
class SACHandler {
/**
*
* @param args - The constructor arguments.
* @param {NetworkConfig} args.networkConfig - The network to connect to.
* Parameters related to the classic asset.
* @param {string} args.code - The asset code.
* @param {string | AccountHandler} args.issuerAccount - The issuer account. Can be a public key or an account handler. If it's an account handler, it will enable management functions.
* @param contractParameters - The contract parameters.
* @param {Spec=} contractParameters.spec - The contract specification object.
* @param {Buffer=} contractParameters.wasm - The contract wasm file as a buffer.
* @param {string=} contractParameters.wasmHash - The contract wasm hash id.
* @param {string=} contractParameters.contractId - The contract id.
* @param options - The contract options.
* @param {SorobanTransactionPipelineOptions=} options.sorobanTransactionPipeline - The Soroban transaction pipeline.
* @param { ClassicTransactionPipelineOptions=} options.classicTransactionPipeline - The classic transaction pipeline.
*
*
* @description - The Stellar Asset Contract handler. It combines the classic asset handler and the Soroban token handler.
* Allows to wrap and deploy the classic asset with the Stellar Asset Contract and to use both Classic and Soroban interfaces.
*
* @returns {void}
*
* @example - Initialize the Stellar Asset Contract handler and wrapping a classic asset with it:
*
* ```typescript
* const issuer = new StellarPlus.Account.DefaultAccountHandler({ networkConfig })
* await issuer.friendbot?.initialize()
*
* const issuerInvocation: TransactionInvocation = {
* header: {
* source: issuer.getPublicKey(),
* fee: '10000000', // 1 XLM max fee
* timeout: 30,
* },
* signers: [issuer],
* }
*
* const asset = new StellarPlus.Asset.SACHandler({
* network,
* code: 'CAKE',
* issuerPublicKey: issuer.getPublicKey(),
* issuerAccount: issuer,
* })
*
* await asset.wrapAndDeploy(issuerInvocation)
*
* // From this point on, the asset is wrapped and deployed with the Stellar Asset Contract.
* // You'll be able to use both the classic and the Soroban interfaces fully.
*
*/
constructor(args) {
this.type = types_1.AssetTypes.SAC;
this.classicHandler = new classic_1.ClassicAssetHandler(args);
this.sorobanTokenHandler = new soroban_token_1.SorobanTokenHandler(args);
}
/**
*
* @param {TransactionInvocation} txInvocation - The transaction invocation object.
* @param {EnvelopeHeader} txInvocation.header - The transaction header.
* @param {Account[]} txInvocation.signers - The transaction signers.
* @param {TransactionInvocation=} txInvocation.feeBump - The fee bump transaction invocation object.
*
* @description - Wraps and deploys the classic asset with the Stellar Asset Contract.
*
* @returns {Promise<SorobanTransactionPipelineOutput | void>}
*
*/
wrapAndDeploy(args) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const asset = new stellar_sdk_1.Asset(this.classicHandler.code, this.classicHandler.issuerPublicKey);
return yield this.sorobanTokenHandler.wrapAndDeployClassicAsset(Object.assign({ asset }, args));
});
}
}
exports.SACHandler = SACHandler;