Skip to content

TEP-137: Jetton Wallet Balance Query #137

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 3 commits into
base: master
Choose a base branch
from

Conversation

0kenx
Copy link

@0kenx 0kenx commented Jan 9, 2024

No description provided.

0kenx added 3 commits January 9, 2024 23:04
Signed-off-by: 0kenx <km@nxfi.app>
Signed-off-by: 0kenx <km@nxfi.app>
Signed-off-by: 0kenx <km@nxfi.app>
@0kenx 0kenx changed the title TEP-x: Jetton Wallet Balance Query TEP-137: Jetton Wallet Balance Query Jan 9, 2024
@mr-tron
Copy link

mr-tron commented Jan 18, 2024

It will never be accepted.

For example in situations where the smart contract knows that no outbound transfer can happen between the get_balance call and the get_balance_response reply (for example when a smart contract queries its own balance), the smart contract can know the minimum amount of Jetton tokens it holds.

In this case contract should block processing all over messages which can change balance until it receives get_balance_response. In can require up to few minutes. Very easy to make mistake for developers without big experience in async networks.

@0kenx
Copy link
Author

0kenx commented Jan 26, 2024

In this case contract should block processing all over messages which can change balance until it receives get_balance_response. In can require up to few minutes.

This is simply not true. In my example where the contract just wants to make sure its balance is greater than x, as long as the contract doesn't transfer funds out (i.e. the balance doesn't reduce) it can keep processing other messages, and if it receives a response that is at least x it can proceed.

Very easy to make mistake for developers without big experience in async networks.

As I have stated multiple times in the document, it should up to the dapp developer to correctly use this feature. You can't cripple experienced async developers for the reason that the feature can "potentially be misused by inexperienced developers". We can mitigate the misuse risk by providing clear explanations in the documentation (which I have already done in the standard).

@0kenx
Copy link
Author

0kenx commented May 31, 2024

Bumping this since we've again run into issues related to this design flaw.

Saying "you can't query the balance since the balance might change" is equivalent to your bank or credit card company refusing to give you an account statement because "someone might have charged your card in the meantime".

@ProgramCrafter
Copy link

I feel this should be accompanied with a good programming language with marker structs which would allow to track assumptions.

struct ValidOnce;
struct ValidThisTx;
struct ValidForever;

trait ValidityTicket {}
impl ValidityTicket for ValidOnce {}
impl ValidityTicket for ValidThisTx {}
impl ValidityTicket for ValidForever {}

async fn send_jettons_or_refund(jettons: usize) {
    let my_jetton_wallet = todo!();
    let my_balance: (usize, ValidOnce) = my_jetton_wallet.request_balance().await; // <-- TRANSACTION BOUNDARY
    
    // SAFETY: all jetton send requests are routed through balance request
    // thus they are processed in order (by lt), and our balance is at least what we received
    let my_balance: (usize, ValidThisTx) = unsafe {my_balance.fiat_extend()};
    
    (if my_balance.0 < jettons {
        send_refund()
    } else {
        my_jetton_wallet.transfer(todo!(), jettons, my_balance)
    }).await;  // <-- TRANSACTION BOUNDARY
}

@0kenx
Copy link
Author

0kenx commented Jun 17, 2024

let my_balance: (usize, ValidOnce) = my_jetton_wallet.request_balance().await; // <-- TRANSACTION BOUNDARY

this expression is not feasible on TON since call context is not preserved.

@ProgramCrafter
Copy link

If destination contract can be trusted to return a cell as-is, then continuation with needed temporary variables may be passed.
If there are few overlapping "calls" on each moment of time, then continuation may be stored in a dictionary.

Copy link

@Eikyarkway Eikyarkway left a comment

Choose a reason for hiding this comment

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

@Jamal1369
Copy link

J****A(CEO)

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.

6 participants