Skip to content

Fix/pre simulation#180

Merged
alexshchur merged 28 commits intofix/simulate-before-writingfrom
fix/pre-simulation
Mar 24, 2026
Merged

Fix/pre simulation#180
alexshchur merged 28 commits intofix/simulate-before-writingfrom
fix/pre-simulation

Conversation

@alexshchur
Copy link
Copy Markdown
Contributor

  • add preliminary simulation for "non-encrypted" txs: shield, claim, unshield
    • disable "write contract" button if simulation fails
  • as for the txs that do contain encrypted inputs (e.g. send) - we can't simulate them preliminarily, because we only encrypt at the time of writing

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 17, 2026

⚠️ No Changeset found

Latest commit: 1278d38

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
cofhesdk-docs Ignored Ignored Mar 24, 2026 9:32am

Request Review

@alexshchur alexshchur marked this pull request as ready for review March 19, 2026 08:45
Copy link
Copy Markdown
Collaborator

@architect-dev architect-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple small requests

Comment thread packages/react/src/components/FnxFloatingButton/pages/SendPage.tsx Outdated
Comment thread packages/react/src/components/FnxFloatingButton/pages/SendPage.tsx Outdated
return getCofheTokenShieldCallArgs({ token, amount: amountWei, account }).main;
}, [account, isValidShieldAmount, shieldAmount, token]);

const shieldSimulation = useCofheSimulateWriteContract(shieldCallArgs, {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this function doesn't involve encrypting any inputs, can we use the standard viem simulation instead of a custom version?

Copy link
Copy Markdown
Contributor Author

@alexshchur alexshchur Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do use standard viem simulation. It's exposed as a method, not as a hook, though.
We need the simulation results in the render function, hence we either need our own small hook or use wagmi (we don't currently have wagmi in the react package)

Comment thread packages/react/src/hooks/useCofheSimulateWriteContract.ts Outdated
}

// Dual tokens: unshield takes uint64
const amount = BigInt.asUintN(64, rawAmount);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with this pattern. What happens if rawAmount is outside the range for a uint64?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was first introduced here. I reused the existing code

if keeps the low 64 bits, so if it overflows, it'll start over, i.e. 2^64+777 -> 777

now that it caught attention, maybe instead of such a conversion we need to check if it's within the range and then throw error?

Comment thread packages/react/src/utils/utils.ts Outdated
…shield

feat: decouple approval tx from shield tx
@alexshchur alexshchur merged commit bcb1ab4 into fix/simulate-before-writing Mar 24, 2026
7 checks passed
@alexshchur alexshchur deleted the fix/pre-simulation branch March 24, 2026 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants