@biconomy/abstractjs
Version:
SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.
82 lines • 3.55 kB
JavaScript
import { prepareRawComposableParams } from "../../../modules/utils/composabilityCalls.js";
import { createConditionInputParam } from "../../../modules/utils/conditions.js";
import { formatComposableCallWithVersion } from "./buildComposable.js";
/**
* Builds an instruction for raw composable transaction. This is a generic function which creates the raw composable instructions
* to execute against composability stack
*
* @param baseParams - Base configuration for the instruction
* @param baseParams.account - The account that will execute the composable transaction
* @param baseParams.currentInstructions - Optional array of existing instructions to append to
* @param parameters - Parameters for generate composable instruction
* @param parameters.to - Address of the target contract address
* @param parameters.calldata - Raw calldata of the solidity function call
* @param parameters.chainId - Chain where the composable transaction will be executed
* @param [parameters.gasLimit] - Optional gas limit
* @param [parameters.value] - Optional value
*
* @returns Promise resolving to array of instructions
*
* @example
* ```typescript
* const instructions = buildRawComposable(
* { accountAddress: '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' },
* {
* to: targetContractAddress,
* calldata: '0x000000',
* chainId: baseSepolia.id
* }
* )
* ```
*/
export const buildRawComposable = async (baseParams, parameters, composabilityParameters) => {
const { currentInstructions = [] } = baseParams;
const { to, calldata, gasLimit, value, chainId, conditions, metadata, lowerBoundTimestamp, upperBoundTimestamp, executionSimulationRetryDelay, simulationOverrides } = parameters;
const { composabilityVersion } = composabilityParameters;
if (!composabilityVersion) {
throw new Error(`Composability version is required to build a composable call.
This error may be caused by using a non-composable .build decorator with a composable call.
Please use buildComposable instead.`);
}
if (calldata.length < 10 || !calldata.startsWith("0x")) {
throw new Error("Invalid calldata");
}
const functionSig = calldata.slice(0, 10);
const callDataEncodedArgs = `0x${calldata.slice(10)}`;
let versionAgnosticComposableParams = [];
if (callDataEncodedArgs.length !== 0) {
versionAgnosticComposableParams =
prepareRawComposableParams(callDataEncodedArgs);
}
// Append condition InputParams if conditions are specified
const allInputParams = conditions?.length
? [
...versionAgnosticComposableParams,
...conditions.map(createConditionInputParam)
]
: versionAgnosticComposableParams;
const composableCall = formatComposableCallWithVersion(composabilityVersion, false, // efficientMode is false for raw composable calls
allInputParams, functionSig, to, value, gasLimit);
const defaultMetadata = [
{
type: "CUSTOM",
description: "Custom composable on-chain action",
chainId
}
];
return [
...currentInstructions,
{
calls: [composableCall],
chainId,
isComposable: true,
metadata: metadata || defaultMetadata,
lowerBoundTimestamp,
upperBoundTimestamp,
executionSimulationRetryDelay,
simulationOverrides
}
];
};
export default buildRawComposable;
//# sourceMappingURL=buildRawComposable.js.map