From 0418ab7acf01b65888012ddb24e864e41a007ac5 Mon Sep 17 00:00:00 2001 From: 0kenx Date: Tue, 9 Jan 2024 23:04:47 +0100 Subject: [PATCH 1/3] Add jetton wallet balance query Signed-off-by: 0kenx --- text/0000-jetton-wallet-balance-query.md | 77 ++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 text/0000-jetton-wallet-balance-query.md diff --git a/text/0000-jetton-wallet-balance-query.md b/text/0000-jetton-wallet-balance-query.md new file mode 100644 index 00000000..35b49cd8 --- /dev/null +++ b/text/0000-jetton-wallet-balance-query.md @@ -0,0 +1,77 @@ +- **TEP**: [0](https://github.com/ton-blockchain/TEPs/pull/0) *(don't change)* +- **title**: Jetton Wallet Balance Query +- **status**: Draft +- **type**: Contract Interface +- **authors**: [Ken](https://github.com/0kenx) +- **created**: 09.01.2024 +- **replaces**: - +- **replaced by**: - + +# Summary + +This proposal suggests to extend standard Jetton wallet by adding mandatory onchain `get_balance` handler. + +# Motivation + +Sometimes a smart contract would like to query the balance of a Jetton wallet onchain. 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. + +# Guide + +Upon receiving `get_balance` message, the Jetton wallet shall reply with message `get_balance_response` with its current balance. + +# Specification + +> The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119. + +## New Jetton contracts + +Jetton wallet should handle message + +`get_balance#312493a5 query_id:uint64 = InternalMsgBody;` + +with TON amount higher than `5000 gas-units + msg_forward_prices.lump_price + msg_forward_prices.cell_price` = 0.0061 TON for current basechain settings attached. If the attached TON amount is not enough then throw an exception, otherwise reply with: + +`get_balance_response#41cb4e49 query_id:uint64 balance:(VarUInteger 16) = InternalMsgBody;` + +## Existing Jetton contracts + +Existing Jetton contracts would not be able to comply with this standard. + +## TL-B Schema + +```tl-b +var_uint$_ {n:#} len:(#< n) value:(uint (len * 8)) + = VarUInteger n; + +get_balance query_id:uint64 = InternalMsgBody; +get_balance_response query_id:uint64 balance:VarUInteger 16 = InternalMsgBody; +``` + +`crc32('get_balance query_id:uint64 = InternalMsgBody') = 0x312493a5 & 0x7fffffff = 0x312493a5` + +`crc32('get_balance_response query_id:uint64 balance:VarUInteger 16 = InternalMsgBody') = 0x41cb4e49 & 0x7fffffff = 0x41cb4e49` + +# Drawbacks + +New applications relying on this standard shall also add branch logic for already existing Jettons. + +# Rationale and alternatives + +- Why is this design the best in the space of possible designs? +- What other designs have been considered and what is the rationale for not choosing them? +- What is the impact of not doing this? + +# Prior art + +Token standards of other asynchronous blockchains provide similar functions. + +- [ICRC-1 Token Standard](https://github.com/dfinity/ICRC-1/tree/main/standards/ICRC-1) +- [Near Token Standard](https://nomicon.io/Standards/Tokens/FungibleToken/Core) + +# Unresolved questions + +None. + +# Future possibilities + +None. From 4af6acdc40579285c7bae2c76ba73461d097c8ff Mon Sep 17 00:00:00 2001 From: 0kenx Date: Tue, 9 Jan 2024 23:07:24 +0100 Subject: [PATCH 2/3] Add jetton wallet balance query Signed-off-by: 0kenx --- text/0000-jetton-wallet-balance-query.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/text/0000-jetton-wallet-balance-query.md b/text/0000-jetton-wallet-balance-query.md index 35b49cd8..90a12966 100644 --- a/text/0000-jetton-wallet-balance-query.md +++ b/text/0000-jetton-wallet-balance-query.md @@ -2,7 +2,7 @@ - **title**: Jetton Wallet Balance Query - **status**: Draft - **type**: Contract Interface -- **authors**: [Ken](https://github.com/0kenx) +- **authors**: [Ken](https://github.com/0kenx) [Microcosm Labs](https://github.com/microcosm-labs) - **created**: 09.01.2024 - **replaces**: - - **replaced by**: - @@ -57,14 +57,10 @@ New applications relying on this standard shall also add branch logic for alread # Rationale and alternatives -- Why is this design the best in the space of possible designs? -- What other designs have been considered and what is the rationale for not choosing them? -- What is the impact of not doing this? +Token standards of other asynchronous blockchains provide similar functions. This functionality cannot be achieved otherwise. # Prior art -Token standards of other asynchronous blockchains provide similar functions. - - [ICRC-1 Token Standard](https://github.com/dfinity/ICRC-1/tree/main/standards/ICRC-1) - [Near Token Standard](https://nomicon.io/Standards/Tokens/FungibleToken/Core) From dc8dc912ddc6e9dec22996592efc05aa1eed39d0 Mon Sep 17 00:00:00 2001 From: 0kenx Date: Tue, 9 Jan 2024 23:09:01 +0100 Subject: [PATCH 3/3] update TEP number Signed-off-by: 0kenx --- ...let-balance-query.md => 0137-jetton-wallet-balance-query.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename text/{0000-jetton-wallet-balance-query.md => 0137-jetton-wallet-balance-query.md} (97%) diff --git a/text/0000-jetton-wallet-balance-query.md b/text/0137-jetton-wallet-balance-query.md similarity index 97% rename from text/0000-jetton-wallet-balance-query.md rename to text/0137-jetton-wallet-balance-query.md index 90a12966..d9c20137 100644 --- a/text/0000-jetton-wallet-balance-query.md +++ b/text/0137-jetton-wallet-balance-query.md @@ -1,4 +1,4 @@ -- **TEP**: [0](https://github.com/ton-blockchain/TEPs/pull/0) *(don't change)* +- **TEP**: [137](https://github.com/ton-blockchain/TEPs/pull/137) - **title**: Jetton Wallet Balance Query - **status**: Draft - **type**: Contract Interface