Skip to content

Commit

Permalink
v3.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
mytonwalletorg committed Sep 5, 2024
1 parent 764633a commit 54da326
Show file tree
Hide file tree
Showing 38 changed files with 426 additions and 169 deletions.
1 change: 1 addition & 0 deletions changelogs/3.0.11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bug fixes and performance improvements
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mytonwallet",
"version": "3.0.10",
"version": "3.0.11",
"description": "The most feature-rich web wallet and browser extension for TON – with support of multi-accounts, tokens (jettons), NFT, TON DNS, TON Sites, TON Proxy, and TON Magic.",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion public/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.10
3.0.11
10 changes: 6 additions & 4 deletions src/api/blockchains/ton/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import type { ApiWalletVersion } from '../../types';
import type { ContractInfo, ContractName } from './types';
import { Workchain } from '../../types';

export const TOKEN_TRANSFER_TONCOIN_AMOUNT = 100000000n; // 0.1 TON
export const TOKEN_TRANSFER_TONCOIN_FORWARD_AMOUNT = 1n; // 0.000000001 TON
export const NFT_TRANSFER_TONCOIN_AMOUNT = 100000000n; // 0.1 TON
export const NFT_TRANSFER_TONCOIN_FORWARD_AMOUNT = 1n; // 0.000000001 TON
export const TOKEN_TRANSFER_AMOUNT = 50000000n; // 0.05 TON
export const TINY_TOKEN_TRANSFER_AMOUNT = 18000000n; // 0.018 TON
export const TOKEN_TRANSFER_FORWARD_AMOUNT = 1n; // 0.000000001 TON

export const NFT_TRANSFER_AMOUNT = 100000000n; // 0.1 TON
export const NFT_TRANSFER_FORWARD_AMOUNT = 1n; // 0.000000001 TON

export const STAKE_COMMENT = 'd';
export const UNSTAKE_COMMENT = 'w';
Expand Down
8 changes: 4 additions & 4 deletions src/api/blockchains/ton/nfts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { buildNft } from './util/metadata';
import { fetchAccountEvents, fetchAccountNfts, fetchNftItems } from './util/tonapiio';
import { commentToBytes, packBytesAsSnake, toBase64Address } from './util/tonCore';
import { fetchStoredAccount, fetchStoredAddress } from '../../common/accounts';
import { NFT_TRANSFER_TONCOIN_AMOUNT, NFT_TRANSFER_TONCOIN_FORWARD_AMOUNT, NftOpCode } from './constants';
import { NFT_TRANSFER_AMOUNT, NFT_TRANSFER_FORWARD_AMOUNT, NftOpCode } from './constants';
import { checkMultiTransactionDraft, checkToAddress, submitMultiTransfer } from './transactions';
import { isActiveSmartContract } from './wallet';

Expand Down Expand Up @@ -124,7 +124,7 @@ export async function checkNftTransferDraft(options: {
const messages = nftAddresses.slice(0, NFT_BATCH_SIZE).map((nftAddress) => {
return {
payload: buildNftTransferPayload(fromAddress, toAddress, comment),
amount: NFT_TRANSFER_TONCOIN_AMOUNT,
amount: NFT_TRANSFER_AMOUNT,
toAddress: nftAddress,
};
});
Expand Down Expand Up @@ -165,7 +165,7 @@ export async function submitNftTransfers(options: {

return {
payload,
amount: NFT_TRANSFER_TONCOIN_AMOUNT,
amount: NFT_TRANSFER_AMOUNT,
toAddress: nftAddress,
};
});
Expand All @@ -190,7 +190,7 @@ function buildNftTransferPayload(
fromAddress: string,
toAddress: string,
payload?: string | Cell,
forwardAmount = NFT_TRANSFER_TONCOIN_FORWARD_AMOUNT,
forwardAmount = NFT_TRANSFER_FORWARD_AMOUNT,
) {
let builder = new Builder()
.storeUint(NftOpCode.TransferOwnership, 32)
Expand Down
17 changes: 12 additions & 5 deletions src/api/blockchains/ton/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import type {
} from '../../types';
import type { AnyPayload, ApiTransactionExtra, JettonMetadata } from './types';

import { DEFAULT_DECIMAL_PLACES, TON_SYMBOL, TONCOIN_SLUG } from '../../../config';
import {
DEFAULT_DECIMAL_PLACES, TINY_TOKENS, TON_SYMBOL, TONCOIN_SLUG,
} from '../../../config';
import { parseAccountId } from '../../../util/account';
import { logDebugError } from '../../../util/logs';
import { fixIpfsUrl } from '../../../util/metadata';
Expand All @@ -28,8 +30,9 @@ import { JettonWallet } from './contracts/JettonWallet';
import { fetchStoredAddress } from '../../common/accounts';
import {
DEFAULT_DECIMALS,
TOKEN_TRANSFER_TONCOIN_AMOUNT,
TOKEN_TRANSFER_TONCOIN_FORWARD_AMOUNT,
TINY_TOKEN_TRANSFER_AMOUNT,
TOKEN_TRANSFER_AMOUNT,
TOKEN_TRANSFER_FORWARD_AMOUNT,
} from './constants';

export type TokenBalanceParsed = {
Expand Down Expand Up @@ -148,14 +151,18 @@ export async function buildTokenTransfer(
payload = buildTokenTransferBody({
tokenAmount: amount,
toAddress,
forwardAmount: TOKEN_TRANSFER_TONCOIN_FORWARD_AMOUNT,
forwardAmount: TOKEN_TRANSFER_FORWARD_AMOUNT,
forwardPayload: payload,
responseAddress: fromAddress,
});

const toncoinAmount = TINY_TOKENS.has(tokenAddress)
? TINY_TOKEN_TRANSFER_AMOUNT
: TOKEN_TRANSFER_AMOUNT;

return {
tokenWallet,
amount: TOKEN_TRANSFER_TONCOIN_AMOUNT,
amount: toncoinAmount,
toAddress: tokenWalletAddress,
payload,
};
Expand Down
71 changes: 51 additions & 20 deletions src/api/blockchains/ton/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { OpenedContract } from '@ton/core';
import {
beginCell, Cell, external, internal, SendMode, storeMessage,
beginCell, Cell, external, internal, loadStateInit, SendMode, storeMessage,
} from '@ton/core';

import type { DieselStatus } from '../../../global/types';
Expand Down Expand Up @@ -28,11 +28,13 @@ import type {
import type { TonWallet } from './util/tonCore';
import { ApiCommonError, ApiTransactionDraftError, ApiTransactionError } from '../../types';

import { DIESEL_ADDRESS, ONE_TON, TONCOIN_SLUG } from '../../../config';
import {
DEFAULT_FEE, DIESEL_ADDRESS, DIESEL_TOKENS, ONE_TON, TONCOIN_SLUG,
} from '../../../config';
import { parseAccountId } from '../../../util/account';
import { bigintMultiplyToNumber } from '../../../util/bigint';
import { compareActivities } from '../../../util/compareActivities';
import { fromDecimal } from '../../../util/decimals';
import { fromDecimal, toDecimal } from '../../../util/decimals';
import { buildCollectionByKey, omit } from '../../../util/iteratees';
import { logDebugError } from '../../../util/logs';
import { pause } from '../../../util/schedulers';
Expand Down Expand Up @@ -63,7 +65,12 @@ import { ApiServerError, handleServerError } from '../../errors';
import { resolveAddress } from './address';
import { fetchKeyPair, fetchPrivateKey } from './auth';
import {
ATTEMPTS, FEE_FACTOR, STAKE_COMMENT, TRANSFER_TIMEOUT_SEC, UNSTAKE_COMMENT,
ATTEMPTS,
FEE_FACTOR,
STAKE_COMMENT,
TINY_TOKEN_TRANSFER_AMOUNT,
TRANSFER_TIMEOUT_SEC,
UNSTAKE_COMMENT,
} from './constants';
import {
buildTokenTransfer, findTokenByMinter, parseTokenTransaction, resolveTokenBySlug,
Expand All @@ -78,7 +85,7 @@ const WAIT_TRANSFER_TIMEOUT = 5 * 60 * 1000; // 5 min
const WAIT_TRANSFER_PAUSE = 1000; // 1 sec.
const WAIT_TRANSACTION_PAUSE = 500; // 0.5 sec.

const MAX_BALANCE_WITH_CHECK_DIESEL = 220000000n; // 0.22 TON
const MAX_BALANCE_WITH_CHECK_DIESEL = 100000000n; // 0.1 TON
const PENDING_DIESEL_TIMEOUT = 15 * 60 * 1000; // 15 min

const pendingTransfers: Record<string, {
Expand All @@ -99,15 +106,14 @@ export async function checkTransactionDraft(
amount: bigint;
tokenAddress?: string;
data?: AnyPayload;
stateInit?: Cell;
stateInit?: string;
shouldEncrypt?: boolean;
isBase64Data?: boolean;
},
): Promise<ApiCheckTransactionDraftResult> {
const {
accountId,
tokenAddress,
stateInit,
shouldEncrypt,
isBase64Data,
} = options;
Expand All @@ -128,7 +134,27 @@ export async function checkTransactionDraft(

const { isInitialized } = await getContractInfo(network, toAddress);

if (result.isBounceable && !isInitialized) {
if (options.stateInit && !isBase64Data) {
return {
...result,
error: ApiTransactionDraftError.StateInitWithoutBin,
};
}

let stateInit;

if (options.stateInit) {
try {
stateInit = Cell.fromBase64(options.stateInit);
} catch {
return {
...result,
error: ApiTransactionDraftError.InvalidStateInit,
};
}
}

if (result.isBounceable && !isInitialized && !stateInit) {
result.isToAddressNew = !(await checkHasTransaction(network, toAddress));
return {
...result,
Expand Down Expand Up @@ -219,7 +245,12 @@ export async function checkTransactionDraft(
? balance > realFee
: balance >= amount + realFee;

if (network === 'mainnet' && tokenAddress && balance < MAX_BALANCE_WITH_CHECK_DIESEL) {
if (
network === 'mainnet'
&& tokenAddress
&& DIESEL_TOKENS.has(tokenAddress)
&& balance < MAX_BALANCE_WITH_CHECK_DIESEL
) {
const {
status: dieselStatus,
amount: dieselAmount,
Expand Down Expand Up @@ -252,12 +283,12 @@ export async function checkTransactionDraft(
}
}

function estimateDiesel(address: string, tokenAddress: string) {
function estimateDiesel(address: string, tokenAddress: string, toncoinAmount: string) {
return callBackendGet<{
status: DieselStatus;
amount?: string;
pendingCreatedAt?: string;
}>('/diesel/estimate', { address, tokenAddress });
}>('/diesel/estimate', { address, tokenAddress, toncoinAmount });
}

export async function checkToAddress(network: ApiNetwork, toAddress: string) {
Expand Down Expand Up @@ -536,10 +567,9 @@ async function signTransaction({
: packBytesAsSnake(payload, 0) as Cell;
}

const init = stateInit ? {
code: stateInit.refs[0],
data: stateInit.refs[1],
} : undefined;
const init = stateInit ? loadStateInit(
stateInit.asSlice(),
) : undefined;

const sendMode = isFullBalance
? SendMode.CARRY_ALL_REMAINING_BALANCE
Expand Down Expand Up @@ -898,10 +928,9 @@ async function signMultiTransaction(
payload = Cell.fromBase64(payload);
}

const init = stateInit ? {
code: stateInit.refs[0],
data: stateInit.refs[1],
} : undefined;
const init = stateInit ? loadStateInit(
stateInit.asSlice(),
) : undefined;

return internal({
value: amount,
Expand Down Expand Up @@ -1147,11 +1176,13 @@ export async function fetchEstimateDiesel(accountId: string, tokenAddress: strin

if (balance >= MAX_BALANCE_WITH_CHECK_DIESEL) return undefined;

const toncoinAmount = toDecimal((TINY_TOKEN_TRANSFER_AMOUNT + DEFAULT_FEE) * 2n);

const {
status,
amount,
pendingCreatedAt,
} = await estimateDiesel(address, tokenAddress);
} = await estimateDiesel(address, tokenAddress, toncoinAmount);
const { decimals } = findTokenByMinter(tokenAddress)!;

const isAwaitingNotExpiredPrevious = Boolean(
Expand Down
2 changes: 1 addition & 1 deletion src/api/extensionMethods/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export async function sendTransaction(params: {
toAddress,
amount,
data: processedData,
stateInit: processedStateInit,
stateInit,
});

if ('error' in checkResult) {
Expand Down
Loading

0 comments on commit 54da326

Please sign in to comment.