aptos-labs / aptos-ts-sdk

An SDK for accessing the Aptos blockchain data, submitting transactions, and more!
https://aptos-labs.github.io/aptos-ts-sdk/
Apache License 2.0
80 stars 46 forks source link

[Feature Request] Add ability to simulate a transaction as if proposed to a multisig account #582

Open mshakeg opened 1 week ago

mshakeg commented 1 week ago

🚀 Feature Request Description

Add the ability to simulate a transaction that would be proposed to a multisig account without requiring the transaction to be actually proposed first.

Motivation

Is your feature request related to a problem? Please describe you use case.

When working with multisig accounts, it's currently not possible to simulate what would happen if a proposed transaction were to be executed by the multisig account without first creating the proposal transaction. This means developers have to:

  1. Create and submit a proposal transaction (costing gas)
  2. Wait for proposal transaction to be committed
  3. Try to execute the transaction to see if it would succeed
  4. If the execution would fail, create another transaction to cleanup/remove the failed proposal

Having the ability to simulate before proposal would:

Pitch

Describe the solution you would like

Add a new simulation method specifically for multisig transactions that:

  1. Takes a would-be proposal's payload
  2. Simulates it as if it were being executed by the multisig account
  3. Returns simulation results without requiring an actual proposal to exist

Example API:

const [response] = await aptos.transaction.simulate.multisig({
  multisigAddress,
  payload: {
    function: "0x1::coin::transfer",
    functionArguments: [recipient, amount],
    typeArguments: ["0x1::aptos_coin::AptosCoin"]
  }
});

This would simulate the transaction as if it were being executed by the multisig account without requiring a proposal to exist first.

Describe alternatives you've considered

  1. Current approach of simulating with multisig payload - fails with MULTISIG_TRANSACTION_NOT_FOUND because it expects a proposal to exist
  2. Simulating as direct execution from multisig account - fails with INVALID_AUTH_KEY because auth validation can't be bypassed
  3. Creating temporary proposals for simulation - works but costly and requires cleanup

Are you willing to open a pull request?

I suspect this will require changes to Aptos core, and I don't have much familiarity with rust and that codebase so I wouldn't be as effective as a core dev.

Additional context

This is particularly important for dApps that use multisig accounts for protocol operations. Being able to simulate transactions before proposal would significantly improve the development experience and reduce costs from failed proposals.

Related code showing current limitations:

// Currently fails with MULTISIG_TRANSACTION_NOT_FOUND
const tx = await aptosClient.transaction.build.simple({
  sender: deployer.accountAddress,
  data: {
    multisigAddress,
    ...entryPayload
  }
});

const [response] = await aptosClient.transaction.simulate.simple({
  signerPublicKey: deployer.publicKey,
  transaction: tx
});
gregnazario commented 3 days ago

Thanks for the request @mshakeg

Check out this example https://github.com/aptos-labs/aptos-ts-sdk/blob/main/examples/typescript-esm/multisig_v2.ts#L144-L162 it was updated a week ago, and the feature flag for mainnet was turned on I think today. It allows you to simulate as other accounts, without necessarily having the public key / transactions.

Let us know if you have any feedback or it doesn't solve your problem cc @junkil-park