-
Notifications
You must be signed in to change notification settings - Fork 6
Add Wrapped TON (wTON) #746
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
7eace49
1c8e98e
ad06d92
c9268c8
0de29f1
8e0ea90
d5e7e6f
54d6b92
95237a1
bf7054a
494093f
ade0133
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
|
|
||
| const ERROR_INVALID_OP = 72 | ||
| const ERROR_WRONG_OP = 0xffff | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused |
||
| const ERROR_NOT_OWNER = 73 | ||
|
krebernisak marked this conversation as resolved.
|
||
| const ERROR_NOT_VALID_WALLET = 74 | ||
| const ERROR_WRONG_WORKCHAIN = 333 | ||
| const ERROR_BALANCE_ERROR = 47 | ||
| const ERROR_NOT_ENOUGH_GAS = 48 | ||
| const ERROR_INVALID_MESSAGE = 49 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // Imported from https://github.com/ton-blockchain/tolk-bench/blob/0f416ca611fbfa25e736973d01e5fb70af485468/contracts_Tolk/03_notcoin/messages.tolk | ||
| import "@stdlib/gas-payments" | ||
| import "errors" | ||
|
|
||
| // we're working in basechain, but theoretically, a jetton might even work in masterchain | ||
| const MY_WORKCHAIN = BASECHAIN | ||
|
|
||
| fun getPrecompiledGasConsumption(): int? | ||
| asm "GETPRECOMPILEDGAS" | ||
|
|
||
| // Storage costs | ||
| // these constants are used to estimate storage fee (how much we should pay for storing a wallet contract) | ||
|
|
||
| const STORAGE_SIZE_MaxWallet_bits = 1033 | ||
| const STORAGE_SIZE_MaxWallet_cells = 3 | ||
| const STORAGE_SIZE_InitStateWallet_bits = 931 | ||
| const STORAGE_SIZE_InitStateWallet_cells = 3 | ||
|
|
||
| const MESSAGE_SIZE_BurnNotification_bits = 754 // body = 32+64+124+(3+8+256)+(3+8+256) | ||
| const MESSAGE_SIZE_BurnNotification_cells = 1 // body always in ref | ||
|
|
||
| const MIN_STORAGE_DURATION = 5 * 365 * 24 * 3600 // 5 years | ||
|
|
||
|
|
||
| // Gas costs | ||
| // these constants are used to estimate gas fee (how much we should remain on balance for a swap to succeed); | ||
| // they must be absolutely equal to consumed gas; if not, tests fail; | ||
| // actual consumed gas (desired value of these constants) are printed to console after tests run | ||
|
|
||
| const GAS_CONSUMPTION_JettonTransfer = 6153 | ||
| const GAS_CONSUMPTION_JettonReceive = 7253 | ||
| const GAS_CONSUMPTION_BurnRequest = 4368 | ||
| const GAS_CONSUMPTION_BurnNotification = 3855 | ||
|
|
||
|
|
||
| fun calculateJettonWalletMinStorageFee() { | ||
| return calculateStorageFee(MY_WORKCHAIN, MIN_STORAGE_DURATION, STORAGE_SIZE_MaxWallet_bits, STORAGE_SIZE_MaxWallet_cells); | ||
| } | ||
|
|
||
| fun forwardInitStateOverhead() { | ||
| return calculateForwardFeeWithoutLumpPrice(MY_WORKCHAIN, STORAGE_SIZE_InitStateWallet_bits, STORAGE_SIZE_InitStateWallet_cells); | ||
| } | ||
|
|
||
| fun checkAmountIsEnoughToTransfer(msgValue: int, forwardTonAmount: int, fwdFee: int) { | ||
| var fwdCount = forwardTonAmount != 0 ? 2 : 1; // second sending (forward) will be cheaper that first | ||
|
|
||
| var jettonWalletGasConsumption = getPrecompiledGasConsumption(); | ||
| var sendTransferGasConsumption = (jettonWalletGasConsumption == null) ? GAS_CONSUMPTION_JettonTransfer : jettonWalletGasConsumption; | ||
| var receiveTransferGasConsumption = (jettonWalletGasConsumption == null) ? GAS_CONSUMPTION_JettonReceive : jettonWalletGasConsumption; | ||
|
|
||
| assert (msgValue > | ||
| forwardTonAmount + | ||
| // 3 messages: wal1->wal2, wal2->owner, wal2->response | ||
| // but last one is optional (it is ok if it fails) | ||
| fwdCount * fwdFee + | ||
| forwardInitStateOverhead() + // additional fwd fees related to initstate in iternal_transfer | ||
| calculateGasFee(MY_WORKCHAIN, sendTransferGasConsumption) + | ||
| calculateGasFee(MY_WORKCHAIN, receiveTransferGasConsumption) + | ||
| calculateJettonWalletMinStorageFee() | ||
| ) throw ERROR_NOT_ENOUGH_GAS; | ||
| } | ||
|
|
||
| fun checkAmountIsEnoughToBurn(msgValue: int) { | ||
| var jettonWalletGasConsumption = getPrecompiledGasConsumption(); | ||
| var sendBurnGasConsumption = (jettonWalletGasConsumption == null) ? GAS_CONSUMPTION_BurnRequest : jettonWalletGasConsumption; | ||
|
|
||
| assert (msgValue > | ||
| calculateForwardFee(MY_WORKCHAIN, MESSAGE_SIZE_BurnNotification_bits, MESSAGE_SIZE_BurnNotification_cells) + | ||
| calculateGasFee(MY_WORKCHAIN, sendBurnGasConsumption) + | ||
| calculateGasFee(MY_WORKCHAIN, GAS_CONSUMPTION_BurnNotification) | ||
| ) throw ERROR_NOT_ENOUGH_GAS; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import "fees-management" | ||
| import "storage" | ||
|
|
||
| fun calcDeployedJettonWallet(ownerAddress: address, minterAddress: address, jettonWalletCode: cell): AutoDeployAddress { | ||
|
krebernisak marked this conversation as resolved.
Outdated
|
||
| val emptyWalletStorage: WalletStorage = { | ||
| status: 0, | ||
| jettonBalance: 0, | ||
| ownerAddress, | ||
| minterAddress, | ||
| }; | ||
|
|
||
| return { | ||
| workchain: MY_WORKCHAIN, | ||
| stateInit: { | ||
| code: jettonWalletCode, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if there's a way to use the hash of the code instead to save on storage and compute fees. IIUC the hash is computed from leaves to root, so the hash of the code should always result in the same. |
||
| data: emptyWalletStorage.toCell() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun calcAddressOfJettonWallet(ownerAddress: address, minterAddress: address, jettonWalletCode: cell) { | ||
| val jwDeployed = calcDeployedJettonWallet(ownerAddress, minterAddress, jettonWalletCode); | ||
| return jwDeployed.calculateAddress() | ||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.