diff --git a/packages/accounts/src/account.ts b/packages/accounts/src/account.ts index feb61ab188..47fe2245f8 100644 --- a/packages/accounts/src/account.ts +++ b/packages/accounts/src/account.ts @@ -152,7 +152,7 @@ export class Account implements IntoConnection { const block = await this.connection.provider.block({ finality: 'final' }); const blockHash = block.header.hash; - const nonce = accessKey.nonce + BigInt(1); + const nonce = accessKey.nonce + 1n; return await signTransaction( receiverId, nonce, actions, baseDecode(blockHash), this.connection.signer, this.accountId, this.connection.networkId ); @@ -444,7 +444,7 @@ export class Account implements IntoConnection { const delegateAction = buildDelegateAction({ actions, maxBlockHeight: BigInt(header.height) + BigInt(blockHeightTtl), - nonce: BigInt(accessKey.nonce) + BigInt(1), + nonce: BigInt(accessKey.nonce) + 1n, publicKey, receiverId, senderId: this.accountId, @@ -610,7 +610,7 @@ export class Account implements IntoConnection { const validatorId = uniquePools[index]; if (state.status === 'fulfilled') { const currentBN = BigInt(state.value); - if (currentBN !== BigInt(0)) { + if (currentBN !== 0n) { return { ...result, stakedValidators: [...result.stakedValidators, { validatorId, amount: currentBN.toString() }], @@ -626,7 +626,7 @@ export class Account implements IntoConnection { } return result; }, - { stakedValidators: [], failedValidators: [], total: BigInt(0) }); + { stakedValidators: [], failedValidators: [], total: 0n }); return { ...summary, diff --git a/packages/accounts/src/account_2fa.ts b/packages/accounts/src/account_2fa.ts index 26ce031c46..c2ba68caa3 100644 --- a/packages/accounts/src/account_2fa.ts +++ b/packages/accounts/src/account_2fa.ts @@ -160,7 +160,7 @@ export class Account2FA extends AccountMultisig { const currentAccountStateKeys = currentAccountState.map(({ key }) => key.toString('base64')); return currentAccountState.length ? [ deployContract(cleanupContractBytes), - functionCall('clean', { keys: currentAccountStateKeys }, MULTISIG_GAS, BigInt('0')) + functionCall('clean', { keys: currentAccountStateKeys }, MULTISIG_GAS, 0n) ] : []; } diff --git a/packages/accounts/src/constants.ts b/packages/accounts/src/constants.ts index ad8bec4dac..7a14e61e7b 100644 --- a/packages/accounts/src/constants.ts +++ b/packages/accounts/src/constants.ts @@ -3,7 +3,7 @@ import { parseNearAmount } from '@near-js/utils'; export const MULTISIG_STORAGE_KEY = '__multisigRequest'; export const MULTISIG_ALLOWANCE = BigInt(parseNearAmount('1')); // TODO: Different gas value for different requests (can reduce gas usage dramatically) -export const MULTISIG_GAS = BigInt('100000000000000'); -export const MULTISIG_DEPOSIT = BigInt('0'); +export const MULTISIG_GAS = 100000000000000n; +export const MULTISIG_DEPOSIT = 0n; export const MULTISIG_CHANGE_METHODS = ['add_request', 'add_request_and_confirm', 'delete_request', 'confirm']; export const MULTISIG_CONFIRM_METHODS = ['confirm']; diff --git a/packages/accounts/src/local-view-execution/runtime.ts b/packages/accounts/src/local-view-execution/runtime.ts index 34311d2ee1..b005d5d16b 100644 --- a/packages/accounts/src/local-view-execution/runtime.ts +++ b/packages/accounts/src/local-view-execution/runtime.ts @@ -298,21 +298,21 @@ export class Runtime { const result = this.storageRead(key_len, key_ptr); if (result == null) { - return BigInt(0); + return 0n; } this.registers[register_id] = result; - return BigInt(1); + return 1n; } private hasStorageKey (key_len: bigint, key_ptr: bigint): bigint { const result = this.storageRead(key_len, key_ptr); if (result == null) { - return BigInt(0); + return 0n; } - return BigInt(1); + return 1n; } private getHostImports() { diff --git a/packages/accounts/test/providers.test.ts b/packages/accounts/test/providers.test.ts index c0989c5138..63d751c372 100644 --- a/packages/accounts/test/providers.test.ts +++ b/packages/accounts/test/providers.test.ts @@ -19,7 +19,7 @@ describe('providers', () => { test('txStatus with string hash and buffer hash', async () => { const sender = await createAccount(near); const receiver = await createAccount(near); - const outcome = await sender.sendMoney(receiver.accountId, BigInt('1')); + const outcome = await sender.sendMoney(receiver.accountId, 1n); const responseWithString = await provider.txStatus(outcome.transaction.hash, sender.accountId); const responseWithUint8Array = await provider.txStatus(base58.decode(outcome.transaction.hash), sender.accountId); expect(responseWithString).toMatchObject(outcome); @@ -29,7 +29,7 @@ describe('providers', () => { test('txStatusReciept with string hash and buffer hash', async () => { const sender = await createAccount(near); const receiver = await createAccount(near); - const outcome = await sender.sendMoney(receiver.accountId, BigInt('1')); + const outcome = await sender.sendMoney(receiver.accountId, 1n); const reciepts = await provider.sendJsonRpc('EXPERIMENTAL_tx_status', [outcome.transaction.hash, sender.accountId]); const responseWithString = await provider.txStatusReceipts(outcome.transaction.hash, sender.accountId); diff --git a/packages/transactions/src/action_creators.ts b/packages/transactions/src/action_creators.ts index 64b68980ed..0c0bff7c6f 100644 --- a/packages/transactions/src/action_creators.ts +++ b/packages/transactions/src/action_creators.ts @@ -98,8 +98,8 @@ export function stringifyJsonOrBytes(args: any): Buffer { function functionCall( methodName: string, args: Uint8Array | object, - gas = BigInt(0), - deposit = BigInt(0), + gas = 0n, + deposit = 0n, stringify = stringifyJsonOrBytes, jsContract = false ): Action { @@ -124,7 +124,7 @@ function functionCall( * @param deposit The amount to be deposited along with the transfer. Default: 0. * @returns A new action for transferring funds. */ -function transfer(deposit = BigInt(0)): Action { +function transfer(deposit = 0n): Action { return new Action({ transfer: new Transfer({ deposit }) }); } @@ -134,7 +134,7 @@ function transfer(deposit = BigInt(0)): Action { * @param publicKey The public key associated with the staking action. * @returns A new action for staking tokens. */ -function stake(stake = BigInt(0), publicKey: PublicKey): Action { +function stake(stake = 0n, publicKey: PublicKey): Action { return new Action({ stake: new Stake({ stake, publicKey }) }); } diff --git a/packages/transactions/test/serialize.test.ts b/packages/transactions/test/serialize.test.ts index d032e829aa..157251e63a 100644 --- a/packages/transactions/test/serialize.test.ts +++ b/packages/transactions/test/serialize.test.ts @@ -202,7 +202,7 @@ describe('serialize and deserialize on different types of nonce', () => { 'test.near', PublicKey.fromString('Anu7LYDfpLtkP7E16LT9imXF694BdQaa9ufVkQiwTQxC'), 'whatever.near', - BigInt(1), + 1n, actions, blockHash); const serialized = encodeTransaction(transaction); diff --git a/packages/transactions/test/transaction.test.ts b/packages/transactions/test/transaction.test.ts index e6df79f41e..2efe9cbebf 100644 --- a/packages/transactions/test/transaction.test.ts +++ b/packages/transactions/test/transaction.test.ts @@ -5,26 +5,26 @@ const { functionCall } = actionCreators; test('functionCall with already serialized args', () => { const serializedArgs = Buffer.from('{}'); - const action = functionCall('methodName', serializedArgs, BigInt(1), BigInt(2)); + const action = functionCall('methodName', serializedArgs, 1n, 2n); expect(action).toMatchObject({ functionCall: { methodName: 'methodName', args: serializedArgs, - gas: BigInt(1), - deposit: BigInt(2) + gas: 1n, + deposit: 2n } }); }); test('functionCall with non-serialized args', () => { const serializedArgs = Buffer.from('{}'); - const action = functionCall('methodName', {}, BigInt(1), BigInt(2)); + const action = functionCall('methodName', {}, 1n, 2n); expect(action).toMatchObject({ functionCall: { methodName: 'methodName', args: serializedArgs, - gas: BigInt(1), - deposit: BigInt(2) + gas: 1n, + deposit: 2n } }); }); diff --git a/packages/utils/src/constants.ts b/packages/utils/src/constants.ts index 01b413f985..d6b0e3bea6 100644 --- a/packages/utils/src/constants.ts +++ b/packages/utils/src/constants.ts @@ -4,4 +4,4 @@ // Due to protocol changes that charge upfront for the maximum possible gas price inflation due to // full blocks, the price of max_prepaid_gas is decreased to `300 * 10**12`. // For discussion see https://github.com/nearprotocol/NEPs/issues/67 -export const DEFAULT_FUNCTION_CALL_GAS = BigInt('30000000000000'); \ No newline at end of file +export const DEFAULT_FUNCTION_CALL_GAS = 30000000000000n; \ No newline at end of file diff --git a/packages/utils/src/format.ts b/packages/utils/src/format.ts index 8e4830d545..56df34607c 100644 --- a/packages/utils/src/format.ts +++ b/packages/utils/src/format.ts @@ -8,13 +8,13 @@ export const NEAR_NOMINATION_EXP = 24; /** * Number of indivisible units in one NEAR. Derived from {@link NEAR_NOMINATION_EXP}. */ -export const NEAR_NOMINATION = BigInt(10) ** BigInt(NEAR_NOMINATION_EXP); +export const NEAR_NOMINATION = 10n ** BigInt(NEAR_NOMINATION_EXP); // Pre-calculate offsets used for rounding to different number of digits const ROUNDING_OFFSETS: bigint[] = []; -const BN10 = BigInt(10); +const BN10 = 10n; for ( - let i = 0, offset = BigInt(5); + let i = 0, offset = 5n; i < NEAR_NOMINATION_EXP; i++, offset = offset * BN10 ) { diff --git a/packages/utils/src/validators.ts b/packages/utils/src/validators.ts index ff167ddd61..4160f8ba02 100644 --- a/packages/utils/src/validators.ts +++ b/packages/utils/src/validators.ts @@ -29,11 +29,11 @@ function findSeatPriceForProtocolBefore49(validators: (CurrentEpochValidatorInfo throw new Error('Stakes are below seats'); } // assert stakesSum >= numSeats - let left = BigInt(1), right = stakesSum + BigInt(1); - while (left !== right - BigInt(1)) { - const mid = (left + right) / BigInt(2); + let left = 1n, right = stakesSum + 1n; + while (left !== right - 1n) { + const mid = (left + right) / 2n; let found = false; - let currentSum = BigInt(0); + let currentSum = 0n; for (let i = 0; i < stakes.length; ++i) { currentSum = currentSum + (stakes[i] / mid); if (currentSum >= num) { @@ -59,7 +59,7 @@ function findSeatPriceForProtocolAfter49(validators: (CurrentEpochValidatorInfo if (validators.length < maxNumberOfSeats) { return stakesSum * BigInt(minimumStakeRatio[0]) / BigInt(minimumStakeRatio[1]); } else { - return stakes[0] + BigInt(1); + return stakes[0] + 1n; } } diff --git a/packages/utils/test/validator.test.ts b/packages/utils/test/validator.test.ts index eb575c0e51..fffa2ee288 100644 --- a/packages/utils/test/validator.test.ts +++ b/packages/utils/test/validator.test.ts @@ -5,23 +5,23 @@ test('find seat price', async () => { expect(findSeatPrice( // @ts-expect-error test input [{ stake: '1000000' }, { stake: '1000000' }, { stake: '100' }], 2, [1, 6250], 49 - )).toEqual(BigInt('101')); + )).toEqual(101n); expect(findSeatPrice( // @ts-expect-error test input [{ stake: '1000000' }, { stake: '1000000' }, { stake: '100' }], 3, [1, 6250] - )).toEqual(BigInt('101')); + )).toEqual(101n); expect(findSeatPrice( // @ts-expect-error test input [{ stake: '1000000' }, { stake: '1000000' }, { stake: '100' }], 4, [1, 6250], 49 - )).toEqual(BigInt('320')); + )).toEqual(320n); expect(findSeatPrice( // @ts-expect-error test input [{ stake: '1000000' }, { stake: '1000000' }, { stake: '100' }], 4, [1, 6250], 48 - )).toEqual(BigInt('500000')); + )).toEqual(500000n); expect(findSeatPrice( // @ts-expect-error test input [{ stake: '1000' }, { stake: '1000' }, { stake: '200' }], 100, [1, 25] - )).toEqual(BigInt('88')); + )).toEqual(88n); }); test('diff validators', async () => { diff --git a/packages/wallet-account/src/near.ts b/packages/wallet-account/src/near.ts index 0b614e34c9..30bef48c08 100644 --- a/packages/wallet-account/src/near.ts +++ b/packages/wallet-account/src/near.ts @@ -114,7 +114,7 @@ export class Near { if (config.masterAccount) { // TODO: figure out better way of specifiying initial balance. // Hardcoded number below must be enough to pay the gas cost to dev-deploy with near-shell for multiple times - const initialBalance = config.initialBalance ? BigInt(config.initialBalance) : BigInt('500000000000000000000000000'); + const initialBalance = config.initialBalance ? BigInt(config.initialBalance) : 500000000000000000000000000n; this.accountCreator = new LocalAccountCreator(new Account(this.connection, config.masterAccount), initialBalance); } else if (config.helperUrl) { this.accountCreator = new UrlAccountCreator(this.connection, config.helperUrl); diff --git a/packages/wallet-account/src/wallet_account.ts b/packages/wallet-account/src/wallet_account.ts index daa40b8984..e61a9023e2 100644 --- a/packages/wallet-account/src/wallet_account.ts +++ b/packages/wallet-account/src/wallet_account.ts @@ -370,7 +370,7 @@ export class ConnectedWalletAccount extends Account { const publicKey = PublicKey.from(accessKey.public_key); // TODO: Cache & listen for nonce updates for given access key - const nonce = accessKey.access_key.nonce + BigInt(1); + const nonce = accessKey.access_key.nonce + 1n; const transaction = createTransaction(this.accountId, publicKey, receiverId, nonce, actions, blockHash); await this.walletConnection.requestSignTransactions({ transactions: [transaction],