Closing a Quote
Last updated
// Prepare close position parameters
const nowInSeconds = Math.floor(Date.now() / 1000);
const deadlineInSeconds = nowInSeconds + deadline; // 'deadline' is a duration in seconds
const closePositionParameters = [
quoteId.toString(),
closePrice.toString(),
quantityToClose.toString(),
orderType,
deadlineInSeconds.toString()
];
// Encode the function call using the Symmio Core ABI
const encodedClosePositionData = web3.eth.abi.encodeFunctionCall(
requestToClosePositionFunctionAbi, // ABI definition for requestToClosePosition
closePositionParameters
);
// Prepare call data for the AccountLayer's _call: [subAccount, [calldata]]
const _callData = [subAccountAddress, [encodedClosePositionData]];
// Estimate gas and send the transaction through the AccountLayer
const gasPrice = await web3.eth.getGasPrice();
const gasEstimate = await accountLayerContract.methods._call(..._callData).estimateGas({ from: process.env.WALLET_ADDRESS });
const gasEstimateBigInt = BigInt(gasEstimate);
const adjustedGasLimit = gasEstimateBigInt + (gasEstimateBigInt * BigInt(20) / BigInt(100)); // 20% buffer
const transactionReceipt = await accountLayerContract.methods._call(..._callData).send({
from: process.env.WALLET_ADDRESS,
gas: adjustedGasLimit.toString(),
gasPrice: gasPrice.toString()
});
console.log("Transaction Receipt:", transactionReceipt);