Skip to content

Commit

Permalink
Merge pull request #50 from tonkeeper/feature/ton-core
Browse files Browse the repository at this point in the history
Update Ton Core and Experimental W5
  • Loading branch information
KuznetsovNikita authored Mar 25, 2024
2 parents b785b15 + 16b125c commit faf78ae
Show file tree
Hide file tree
Showing 282 changed files with 4,192 additions and 4,582 deletions.
1 change: 1 addition & 0 deletions apps/desktop/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export const Loader: FC = () => {
standalone: true,
extension: false,
proFeatures: true,
experimental: true,
ios: false,
env: {
tgAuthBotId: REACT_APP_TG_BOT_ID
Expand Down
8 changes: 7 additions & 1 deletion apps/desktop/webpack.renderer.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ export const rendererConfig: Configuration = {
'react-router-dom': path.resolve(__dirname, './node_modules/react-router-dom'),
'styled-components': path.resolve(__dirname, './node_modules/styled-components'),
'react-i18next': path.resolve(__dirname, './node_modules/react-i18next'),
'@tanstack/react-query': path.resolve(__dirname, './node_modules/@tanstack/react-query')
'@tanstack/react-query': path.resolve(
__dirname,
'./node_modules/@tanstack/react-query'
),
'@ton/core': path.resolve(__dirname, '../../packages/core/node_modules/@ton/core'),
'@ton/crypto': path.resolve(__dirname, '../../packages/core/node_modules/@ton/crypto'),
'@ton/ton': path.resolve(__dirname, '../../packages/core/node_modules/@ton/ton')
}
}
};
6 changes: 3 additions & 3 deletions apps/extension/config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ module.exports = function override(config, env) {
config.resolve.alias = {
...config.resolve.alias,
react: path.resolve(__dirname, './node_modules/react'),
ton: path.resolve(__dirname, './node_modules/ton'),
'ton-core': path.resolve(__dirname, './node_modules/ton-core'),
'ton-crypto': path.resolve(__dirname, './node_modules/ton-crypto'),
'@ton/core': path.resolve(__dirname, '../../packages/core/node_modules/@ton/core'),
'@ton/crypto': path.resolve(__dirname, '../../packages/core/node_modules/@ton/crypto'),
'@ton/ton': path.resolve(__dirname, '../../packages/core/node_modules/@ton/ton'),
'react-dom': path.resolve(__dirname, './node_modules/react-dom'),
'react-router-dom': path.resolve(__dirname, './node_modules/react-router-dom'),
'styled-components': path.resolve(__dirname, './node_modules/styled-components'),
Expand Down
3 changes: 0 additions & 3 deletions apps/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
"react-router-dom": "^6.4.5",
"stream-browserify": "^3.0.0",
"styled-components": "^6.1.1",
"ton": "^13.4.1",
"ton-core": "^0.49.0",
"ton-crypto": "^3.2.0",
"uuid": "^9.0.1",
"web-vitals": "^2.1.4",
"webextension-polyfill": "^0.10.0"
Expand Down
8 changes: 7 additions & 1 deletion apps/web/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ export default defineConfig({
'react-router-dom': path.resolve(__dirname, './node_modules/react-router-dom'),
'styled-components': path.resolve(__dirname, './node_modules/styled-components'),
'react-i18next': path.resolve(__dirname, './node_modules/react-i18next'),
'@tanstack/react-query': path.resolve(__dirname, './node_modules/@tanstack/react-query')
'@tanstack/react-query': path.resolve(
__dirname,
'./node_modules/@tanstack/react-query'
),
'@ton/core': path.resolve(__dirname, '../../packages/core/node_modules/@ton/core'),
'@ton/crypto': path.resolve(__dirname, '../../packages/core/node_modules/@ton/crypto'),
'@ton/ton': path.resolve(__dirname, '../../packages/core/node_modules/@ton/ton')
}
}
});
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"yarn-run-all": "^3.1.1"
},
"dependencies": {
"@ton/core": "0.54.0",
"@ton/crypto": "3.2.0",
"@ton/ton": "https://github.com/tonkeeper/tonkeeper-ton#build8",
"bignumber.js": "^9.1.1",
"ethers": "^6.6.5",
"query-string": "^8.1.0",
"ton": "^13.4.1",
"ton-core": "^0.49.0",
"ton-crypto": "^3.2.0",
"tweetnacl": "^1.0.3"
}
}
2 changes: 1 addition & 1 deletion packages/core/src/entries/crypto/asset/basic-asset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address } from 'ton-core';
import { Address } from '@ton/core';
import { BLOCKCHAIN_NAME } from '../../crypto';

export interface BasicAsset {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/entries/crypto/asset/ton-asset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address } from 'ton-core';
import { Address } from '@ton/core';
import { JettonsBalances } from '../../../tonApiV2';
import { BLOCKCHAIN_NAME } from '../../crypto';
import { BasicAsset, packAssetId } from './basic-asset';
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/entries/send.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Account, MessageConsequences, WalletDNS } from '../tonApiV2';
import { Account, AccountEvent, WalletDNS } from '../tonApiV2';
import { EstimatePayload } from '../tronApi';
import { BLOCKCHAIN_NAME } from './crypto';
import { Asset } from './crypto/asset/asset';
Expand Down Expand Up @@ -54,8 +54,10 @@ export function isTronRecipientData(
export type TransferEstimation<T extends Asset = Asset> = {
fee: AssetAmount<T>;
payload: T extends TonAsset
? MessageConsequences
? TransferEstimationEvent
: T extends TronAsset
? EstimatePayload
: never;
};

export type TransferEstimationEvent = { event: AccountEvent };
7 changes: 6 additions & 1 deletion packages/core/src/entries/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export enum WalletVersion {
V3R1 = 0,
V3R2 = 1,
V4R1 = 2,
V4R2 = 3
V4R2 = 3,
W5 = 4
}

export const WalletVersions = [WalletVersion.V3R1, WalletVersion.V3R2, WalletVersion.V4R2];
Expand All @@ -20,6 +21,8 @@ export const walletVersionText = (version: WalletVersion) => {
return 'v3R2';
case WalletVersion.V4R2:
return 'v4R2';
case WalletVersion.W5:
return 'W5';
default:
return String(version);
}
Expand All @@ -33,6 +36,8 @@ export const walletVersionFromText = (value: string) => {
return WalletVersion.V3R2;
case 'v4R2':
return WalletVersion.V4R2;
case 'W5':
return WalletVersion.W5;
default:
throw new Error('Unsupported version');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/service/mnemonicService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mnemonicValidate } from 'ton-crypto';
import { mnemonicValidate } from '@ton/crypto';
import { AppKey } from '../Keys';
import { IStorage } from '../Storage';
import { decrypt } from './cryptoService';
Expand Down
22 changes: 11 additions & 11 deletions packages/core/src/service/proService.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import { Address } from '@ton/core';
import BigNumber from 'bignumber.js';
import { Address } from 'ton-core';
import { AppKey } from '../Keys';
import { IStorage } from '../Storage';
import { APIConfig } from '../entries/apis';
import { BLOCKCHAIN_NAME } from '../entries/crypto';
import { AssetAmount } from '../entries/crypto/asset/asset-amount';
import { TON_ASSET } from '../entries/crypto/asset/constants';
import { DashboardCell, DashboardColumn } from '../entries/dashboard';
import { FiatCurrencies } from '../entries/fiat';
import { Language, localizationText } from '../entries/language';
import { ProState, ProSubscription, ProSubscriptionInvalid } from '../entries/pro';
import { RecipientData, TonRecipientData } from '../entries/send';
import { WalletState } from '../entries/wallet';
import { AccountsApi } from '../tonApiV2';
import {
InvoicesInvoice,
FiatCurrencies as FiatCurrenciesGenerated,
InvoiceStatus,
InvoicesInvoice,
Lang,
ProServiceService,
FiatCurrencies as FiatCurrenciesGenerated,
ProServiceDashboardColumnType,
ProServiceDashboardCellString,
ProServiceDashboardCellAddress,
ProServiceDashboardCellNumericCrypto,
ProServiceDashboardCellNumericFiat
ProServiceDashboardCellNumericFiat,
ProServiceDashboardCellString,
ProServiceDashboardColumnType,
ProServiceService
} from '../tonConsoleApi';
import { delay } from '../utils/common';
import { Flatten } from '../utils/types';
import { loginViaTG } from './telegramOauth';
import { createTonProofItem, tonConnectProofPayload } from './tonConnect/connectService';
import { walletStateInitFromState } from './wallet/contractService';
import { getWalletState } from './wallet/storeService';
import { loginViaTG } from './telegramOauth';
import { DashboardCell, DashboardColumn } from '../entries/dashboard';
import { FiatCurrencies } from '../entries/fiat';
import { Flatten } from '../utils/types';

export const setBackupState = async (storage: IStorage, state: ProSubscription) => {
await storage.set(AppKey.PRO_BACKUP, state);
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/service/tonConnect/connectService.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import queryString from 'query-string';
import { Address, beginCell, storeStateInit } from 'ton-core';
import { Address, beginCell, storeStateInit } from '@ton/core';
import {
getSecureRandomBytes,
keyPairFromSeed,
mnemonicToPrivateKey,
sha256_sync
} from 'ton-crypto';
} from '@ton/crypto';
import queryString from 'query-string';
import nacl from 'tweetnacl';
import { IStorage } from '../../Storage';
import { TonConnectError } from '../../entries/exception';
Expand Down
26 changes: 11 additions & 15 deletions packages/core/src/service/transfer/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import BigNumber from 'bignumber.js';
import {
Address,
beginCell,
Expand All @@ -8,21 +7,18 @@ import {
internal,
storeMessage,
toNano
} from 'ton-core';
import { mnemonicToPrivateKey } from 'ton-crypto';
import { WalletContractV3R1 } from 'ton/dist/wallets/WalletContractV3R1';
import { WalletContractV3R2 } from 'ton/dist/wallets/WalletContractV3R2';
import { WalletContractV4 } from 'ton/dist/wallets/WalletContractV4';
} from '@ton/core';
import { mnemonicToPrivateKey } from '@ton/crypto';
import { WalletContractV3R1 } from '@ton/ton/dist/wallets/WalletContractV3R1';
import { WalletContractV3R2 } from '@ton/ton/dist/wallets/WalletContractV3R2';
import { WalletContractV4 } from '@ton/ton/dist/wallets/WalletContractV4';
import { WalletContractV5 } from '@ton/ton/dist/wallets/WalletContractV5';
import BigNumber from 'bignumber.js';
import nacl from 'tweetnacl';
import { APIConfig } from '../../entries/apis';
import { TransferEstimationEvent } from '../../entries/send';
import { WalletState } from '../../entries/wallet';
import {
Account,
AccountsApi,
LiteServerApi,
MessageConsequences,
WalletApi
} from '../../tonApiV2';
import { Account, AccountsApi, LiteServerApi, WalletApi } from '../../tonApiV2';
import { walletContractFromState } from '../wallet/contractService';

export enum SendMode {
Expand All @@ -35,7 +31,7 @@ export enum SendMode {
}

export const externalMessage = (
contract: WalletContractV3R1 | WalletContractV3R2 | WalletContractV4,
contract: WalletContractV3R1 | WalletContractV3R2 | WalletContractV4 | WalletContractV5,
seqno: number,
body: Cell
) => {
Expand Down Expand Up @@ -151,7 +147,7 @@ export const createTransferMessage = (
export async function getKeyPairAndSeqno(options: {
api: APIConfig;
walletState: WalletState;
fee: MessageConsequences;
fee: TransferEstimationEvent;
mnemonic: string[];
amount: BigNumber;
}) {
Expand Down
21 changes: 12 additions & 9 deletions packages/core/src/service/transfer/jettonService.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Address, beginCell, Cell, comment, internal, toNano } from '@ton/core';
import { mnemonicToPrivateKey } from '@ton/crypto';
import BigNumber from 'bignumber.js';
import { Address, beginCell, Cell, comment, internal, toNano } from 'ton-core';
import { mnemonicToPrivateKey } from 'ton-crypto';
import { APIConfig } from '../../entries/apis';
import { AssetAmount } from '../../entries/crypto/asset/asset-amount';
import { TonAsset } from '../../entries/crypto/asset/ton-asset';
import { TonRecipientData } from '../../entries/send';
import { TonRecipientData, TransferEstimationEvent } from '../../entries/send';
import { WalletState } from '../../entries/wallet';
import { BlockchainApi, EmulationApi, MessageConsequences } from '../../tonApiV2';
import { BlockchainApi, EmulationApi } from '../../tonApiV2';
import { walletContractFromState } from '../wallet/contractService';
import {
checkServiceTimeOrDie,
Expand Down Expand Up @@ -87,7 +87,7 @@ export const estimateJettonTransfer = async (
recipient: TonRecipientData,
amount: AssetAmount<TonAsset>,
jettonWalletAddress: string
) => {
): Promise<TransferEstimationEvent> => {
await checkServiceTimeOrDie(api);
const [wallet, seqno] = await getWalletBalance(api, walletState);
checkWalletPositiveBalanceOrDie(wallet);
Expand All @@ -101,10 +101,13 @@ export const estimateJettonTransfer = async (
recipient.comment ? comment(recipient.comment) : null
);

const emulation = await new EmulationApi(api.tonApiV2).emulateMessageToWallet({
emulateMessageToWalletRequest: { boc: cell.toString('base64') }
const event = await new EmulationApi(api.tonApiV2).emulateMessageToAccountEvent({
ignoreSignatureCheck: true,
accountId: wallet.address,
decodeMessageRequest: { boc: cell.toString('base64') }
});
return emulation;

return { event };
};

export const sendJettonTransfer = async (
Expand All @@ -113,7 +116,7 @@ export const sendJettonTransfer = async (
recipient: TonRecipientData,
amount: AssetAmount<TonAsset>,
jettonWalletAddress: string,
fee: MessageConsequences,
fee: TransferEstimationEvent,
mnemonic: string[]
) => {
await checkServiceTimeOrDie(api);
Expand Down
24 changes: 13 additions & 11 deletions packages/core/src/service/transfer/nftService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Address, beginCell, Cell, comment, toNano } from '@ton/core';
import { mnemonicToPrivateKey } from '@ton/crypto';
import BigNumber from 'bignumber.js';
import { Address, beginCell, Cell, comment, toNano } from 'ton-core';
import { mnemonicToPrivateKey } from 'ton-crypto';
import { APIConfig } from '../../entries/apis';
import { TonRecipientData } from '../../entries/send';
import { TonRecipientData, TransferEstimationEvent } from '../../entries/send';
import { WalletState } from '../../entries/wallet';
import { BlockchainApi, EmulationApi, MessageConsequences, NftItem } from '../../tonApiV2';
import { BlockchainApi, EmulationApi, NftItem } from '../../tonApiV2';
import {
checkServiceTimeOrDie,
checkWalletBalanceOrDie,
Expand Down Expand Up @@ -91,7 +91,7 @@ export const estimateNftTransfer = async (
walletState: WalletState,
recipient: TonRecipientData,
nftItem: NftItem
) => {
): Promise<TransferEstimationEvent> => {
await checkServiceTimeOrDie(api);
const [wallet, seqno] = await getWalletBalance(api, walletState);
checkWalletPositiveBalanceOrDie(wallet);
Expand All @@ -105,18 +105,20 @@ export const estimateNftTransfer = async (
recipient.comment ? comment(recipient.comment) : null
);

const emulation = await new EmulationApi(api.tonApiV2).emulateMessageToWallet({
emulateMessageToWalletRequest: { boc: cell.toString('base64') }
const event = await new EmulationApi(api.tonApiV2).emulateMessageToAccountEvent({
ignoreSignatureCheck: true,
accountId: wallet.address,
decodeMessageRequest: { boc: cell.toString('base64') }
});
return emulation;
return { event };
};

export const sendNftTransfer = async (
api: APIConfig,
walletState: WalletState,
recipient: TonRecipientData,
nftItem: NftItem,
fee: MessageConsequences,
fee: TransferEstimationEvent,
mnemonic: string[]
) => {
await checkServiceTimeOrDie(api);
Expand Down Expand Up @@ -155,7 +157,7 @@ export const sendNftRenew = async (options: {
api: APIConfig;
walletState: WalletState;
nftAddress: string;
fee: MessageConsequences;
fee: TransferEstimationEvent;
mnemonic: string[];
amount: BigNumber;
}) => {
Expand Down Expand Up @@ -206,7 +208,7 @@ export const sendNftLink = async (options: {
walletState: WalletState;
nftAddress: string;
linkToAddress: string;
fee: MessageConsequences;
fee: TransferEstimationEvent;
mnemonic: string[];
amount: BigNumber;
}) => {
Expand Down
Loading

0 comments on commit faf78ae

Please sign in to comment.