aftermath-ts-sdk
Version:
Aftermath TypeScript SDK
70 lines (69 loc) • 3.13 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DynamicGas = void 0;
const caller_1 = require("../utils/caller");
/**
* The `DynamicGas` class provides functionality for dynamically determining
* or attaching a suitable gas payment object to a transaction. This allows
* for more flexible transaction building when exact gas objects are not
* predetermined.
*/
class DynamicGas extends caller_1.Caller {
// =========================================================================
// Constructor
// =========================================================================
/**
* Creates a new `DynamicGas` instance for interacting with dynamic gas endpoints.
*
* @param config - Optional caller config, including the Sui network and an access token.
*/
constructor(config) {
super(config, "dynamic-gas");
}
// =========================================================================
// Tx Setup
// =========================================================================
/**
* Requests the dynamic gas service to set up a transaction with an appropriate gas coin,
* or sponsor signature if needed, based on the user's wallet and coin type preference.
*
* @param inputs - An object containing the `Transaction` to be adjusted, the `walletAddress`, and `gasCoinType`.
* @returns A promise that resolves to an `ApiDynamicGasResponse`, which includes the new transaction bytes
* (`txBytes`) and possibly a `sponsoredSignature`.
*
* @example
* ```typescript
* const afSdk = new Aftermath("MAINNET");
* await afSdk.init(); // initialize provider
*
* const dynamicGas = afSdk.DynamicGas();
*
* const updatedTx = await dynamicGas.getUseDynamicGasForTx({
* tx: transactionBlock,
* walletAddress: "0x<user_address>",
* gasCoinType: "0x2::sui::SUI"
* });
* // updatedTx.txBytes and updatedTx.sponsoredSignature can now be used for signing/execution
* ```
*/
getUseDynamicGasForTx(inputs) {
return __awaiter(this, void 0, void 0, function* () {
const { tx, walletAddress, gasCoinType } = inputs;
return this.fetchApi("", {
serializedTx: tx.serialize(),
walletAddress,
gasCoinType,
});
});
}
}
exports.DynamicGas = DynamicGas;