Skip to content

feat: Return Jettons, that were sent by accident #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Shvandre
Copy link
Collaborator

Closes #58

@Shvandre Shvandre marked this pull request as ready for review May 22, 2025 13:30
@Shvandre Shvandre requested review from Copilot and Kaladin13 May 22, 2025 13:30
Copy link

@Copilot 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 adds automatic return logic for accidental Jetton/TON transfers to vault contracts, updates environment helpers to expose an initialization check, and expands test coverage around these scenarios.

  • Added isInited helpers in createJettonVault and createTonVault environments
  • Implemented UnexpectedJettonNotification handler in TonVault and proof‐check return logic in JettonVault
  • Expanded tests to verify accidental returns for both TON and Jetton vaults, and updated formatting in pre-commit hook

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
sources/utils/environment.ts Added isInited method to vault interface and factories
sources/tests/ton-vault.spec.ts New test for returning Jettons sent to TON Vault
sources/tests/proofs.spec.ts New tests for invalid proofs and wrong‐Jetton scenarios
sources/contracts/vaults/ton-vault.tact Defined UnexpectedJettonNotification & return message
sources/contracts/vaults/proofs/check-proof.tact Refactored checkProof to return Bool
sources/contracts/vaults/jetton-vault.tact Added return‐on‐invalid‐proof and wrong‐sender logic
sources/contracts/utils/utils.tact Introduced sliceWithOneZeroBit helper
.husky/pre-commit Updated tact-fmt invocation
Comments suppressed due to low confidence (1)

.husky/pre-commit:2

  • [nitpick] The tact-fmt invocation was modified to --write ./, but the diff context shows an extra space and missing dash alignment. Ensure the pre-commit script matches other hooks and linting conventions.
yarn tact-fmt --write ./

Shvandre and others added 2 commits May 22, 2025 16:39
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@pyAndr3w
Copy link

Jettons can still get stuck in the vault because of this:

require(msg.walletAddress == self.possibleJettonWallet, "TEP89 proof: Wallet address does not match");

@Shvandre
Copy link
Collaborator Author

Jettons can still get stuck in the vault because of this:

require(msg.walletAddress == self.possibleJettonWallet, "TEP89 proof: Wallet address does not match");

I will solve that as part of #61

Copy link
Collaborator

@Kaladin13 Kaladin13 left a comment

Choose a reason for hiding this comment

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

Great job, small nitpicks

@@ -134,4 +134,125 @@ describe("Proofs", () => {
)
expect(await jettonVaultInstance.getInited()).toBe(false)
})
test("Jettons are returned if proof type is incorrect", async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add classic const balanceBefore = jetton.balance() and then expect(balanceAfter).toBe(balanceBefore)

@@ -44,6 +62,27 @@ contract TonVault(
});
}

// Someone possibly transferred us jettons by accident
receive(msg: UnexpectedJettonNotification) {
message(MessageParameters {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe let's separate this refund to standalone function? It is used three times with the same exact code

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.

We should try to return Jettons back if someone sent them with incorrect proof or just sent incorrect Jettons
3 participants