Skip to content

feat: replace postActions/extraMsg with safe_deposit for UTXO deposits#458

Open
r-near wants to merge 4 commits intomainfrom
feat/safe-deposit-utxo
Open

feat: replace postActions/extraMsg with safe_deposit for UTXO deposits#458
r-near wants to merge 4 commits intomainfrom
feat/safe-deposit-utxo

Conversation

@r-near
Copy link
Copy Markdown
Collaborator

@r-near r-near commented Apr 8, 2026

Summary

  • Replace postActions/extraMsg with safe_deposit on getUtxoDepositAddress across core API client and bridge interface
  • NEAR builder now calls safe_verify_deposit (with 1.2 mNEAR deposit) instead of verify_deposit when safe_deposit is present
  • Fix pre-existing noNonNullAssertion lint warnings in starknet encoding

Matches bridge-sdk-rs#260.

Test plan

  • bun run build passes
  • bun run lint passes (0 warnings)
  • bun run test packages/ — 263 tests pass

r-near added 2 commits April 8, 2026 10:10
The bridge API now uses view calls instead of on-chain transactions to
generate deposit addresses, avoiding NotEnoughBalance errors. Replace
postActions/extraMsg with safe_deposit on getUtxoDepositAddress, and
use safe_verify_deposit when finalizing deposits with safe_deposit.

Matches bridge-sdk-rs#260.
Copilot AI review requested due to automatic review settings April 8, 2026 17:11
@r-near r-near requested review from a team as code owners April 8, 2026 17:11
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 8, 2026

⚠️ No Changeset found

Latest commit: f6d49ef

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates UTXO deposit flows away from postActions/extraMsg to a safe_deposit message, updating the core API client + bridge interface, and updating the NEAR builder to use safe_verify_deposit (with the required attached deposit) when applicable. It also removes pre-existing non-null assertions in Starknet byte array decoding.

Changes:

  • Update Core BridgeAPI.getUtxoDepositAddress + Bridge.getUtxoDepositAddress options to accept safeDeposit / send safe_deposit.
  • Update NEAR builder to call safe_verify_deposit (and attach DEPOSIT.SAFE_VERIFY_DEPOSIT) when depositMsg.safe_deposit is provided.
  • Refactor Starknet decodeByteArray to avoid non-null assertions and add a missing-offset guard.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/starknet/src/encoding.ts Removes non-null assertions in decodeByteArray and adds offset guard.
packages/near/src/builder.ts Switches finalization call to safe_verify_deposit + attaches deposit when safe_deposit is present.
packages/near/src/types.ts Adds UtxoSafeDeposit type and DEPOSIT.SAFE_VERIFY_DEPOSIT constant.
packages/near/src/index.ts Re-exports UtxoSafeDeposit.
packages/near/tests/utxo.test.ts Adds coverage for safe-deposit finalization path.
packages/core/src/api.ts Changes UTXO deposit address API to accept safeDeposit and send safe_deposit.
packages/core/src/bridge.ts Updates bridge-level UTXO deposit options/result to align with safe-deposit flow.
packages/core/src/index.ts Re-exports SafeDeposit.
packages/core/tests/api.test.ts Updates API test to use safeDeposit parameter.
docs/reference/near.mdx Documents safe_deposit and safe_verify_deposit behavior for NEAR builder.
docs/reference/core.mdx Updates Core docs to describe safeDeposit and removes postActions/extraMsg references.
Comments suppressed due to low confidence (1)

packages/core/tests/api.test.ts:272

  • The new safe_deposit behavior isn’t fully exercised: the MSW handler always returns a response regardless of request body, so this test would still pass even if the client failed to send safe_deposit (or sent the wrong key). Consider asserting the POST body includes safe_deposit: { msg: ... } (and not safeDeposit) in this test/handler.
    it("should handle safe_deposit parameter", async () => {
      const response = await api.getUtxoDepositAddress("btc", "recipient.near", {
        msg: "safe deposit message",
      })
      expect(response).toEqual({
        address: "tb1qssh0ejglq0v53pwrsxlhxpxw29gfu6c4ls9eyy",
      })
    })

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const connector = this.getUtxoConnectorAddress(params.chain)

// Build deposit_msg for the contract (convert bigint amounts to strings)
const isSafeDeposit = params.depositMsg.safe_deposit != null
Copy link
Copy Markdown
Collaborator

@karim-en karim-en Apr 8, 2026

Choose a reason for hiding this comment

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

I think it is better to fully remove the not-safe flow from the bridge SDK js.
I even prefer to fully remove the legacy code in contract, but unfortunately we can't do that because the Satoshi protocol relay on it.

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.

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.

3 participants