diff --git a/cli/commands/start/eth2near-relay.js b/cli/commands/start/eth2near-relay.js index 40b8210e3..2750d6de1 100644 --- a/cli/commands/start/eth2near-relay.js +++ b/cli/commands/start/eth2near-relay.js @@ -63,9 +63,7 @@ class StartEth2NearRelayCommand { nodeUrl: nearNodeUrl, networkId: nearNetworkId, masterAccount: nearMasterAccount, - deps: { - keyStore: keyStore - } + keyStore }) const relay = new Eth2NearRelay() diff --git a/cli/commands/status.js b/cli/commands/status.js index 1ca911bb2..ab1ff4d80 100644 --- a/cli/commands/status.js +++ b/cli/commands/status.js @@ -173,9 +173,7 @@ class NearStatus { nodeUrl: nearNodeUrl, nearNetworkId, masterAccount: nearMasterAccount, - deps: { - keyStore: keyStore - } + keyStore }) this.masterAccount = (await verifyAccountGently(near, nearMasterAccount)) ? new Status(nearMasterAccount, Ok, Valid) diff --git a/cli/commands/update-dag-merkle-roots.js b/cli/commands/update-dag-merkle-roots.js index e6314a552..3d8ceabec 100644 --- a/cli/commands/update-dag-merkle-roots.js +++ b/cli/commands/update-dag-merkle-roots.js @@ -28,9 +28,7 @@ class UpdateDagMerkleRoots { const near = await nearAPI.connect({ nodeUrl: nearNodeUrl, networkId: nearNetworkId, - deps: { - keyStore: keyStore - } + keyStore }) console.log(`DAG Merkle roots SHA256-checksum: ${sha256(JSON.stringify(dagMerkleRoots, null, 2))}`) diff --git a/cli/init/near-contracts.js b/cli/init/near-contracts.js index ae4deb71d..5c53c8edf 100644 --- a/cli/init/near-contracts.js +++ b/cli/init/near-contracts.js @@ -65,9 +65,7 @@ class InitNearContracts { nodeUrl: nearNodeUrl, networkId: nearNetworkId, masterAccount: nearMasterAccount, - deps: { - keyStore: keyStore - } + keyStore }) console.log('Creating accounts and deploying the contracts.') diff --git a/cli/init/near-token-factory.js b/cli/init/near-token-factory.js index 7c21e176a..a3d3a84ca 100644 --- a/cli/init/near-token-factory.js +++ b/cli/init/near-token-factory.js @@ -43,7 +43,7 @@ class InitNearTokenFactory { nodeUrl: nearNodeUrl, networkId: nearNetworkId, masterAccount: nearMasterAccount, - deps: { keyStore: keyStore } + keyStore }) await verifyAccount(near, nearMasterAccount) diff --git a/eth2near/eth2near-block-relay/index.js b/eth2near/eth2near-block-relay/index.js index 05ac65313..2560ed9a3 100644 --- a/eth2near/eth2near-block-relay/index.js +++ b/eth2near/eth2near-block-relay/index.js @@ -236,7 +236,7 @@ class Eth2NearRelay { actions.push(action) } - const task = this.ethClientContract.account.signAndSendTransaction(this.ethClientContract.contractId, actions) + const task = this.ethClientContract.account.signAndSendTransaction({ receiverId: this.ethClientContract.contractId, actions }) console.log( `Submit txn to add block ${clientBlockNumber + 1 diff --git a/near2eth/near2eth-block-relay/index.js b/near2eth/near2eth-block-relay/index.js index e1f840424..6bacafc7e 100644 --- a/near2eth/near2eth-block-relay/index.js +++ b/near2eth/near2eth-block-relay/index.js @@ -38,9 +38,7 @@ class Near2EthRelay { this.near = await nearAPI.connect({ nodeUrl: nearNodeUrl, networkId: nearNetworkId, - deps: { - keyStore: keyStore - } + keyStore }) // Declare Near2EthClient contract. diff --git a/testing/adapter/index.js b/testing/adapter/index.js index 4102dec2f..7be1c9015 100644 --- a/testing/adapter/index.js +++ b/testing/adapter/index.js @@ -212,7 +212,7 @@ async function getBridgeOnNearBalance ({ nodeUrl: nearNodeUrl, networkId: nearNetworkId, masterAccount: nearReceiverAccount, - deps: { keyStore: keyStore } + keyStore }) const nearAccount = new nearAPI.Account( diff --git a/testing/ci/e2e.sh b/testing/ci/e2e.sh index dc821739f..0e1356f52 100755 --- a/testing/ci/e2e.sh +++ b/testing/ci/e2e.sh @@ -44,7 +44,7 @@ node index.js init-near-token-factory yarn run pm2 ping sleep 5 yarn run pm2 list -node index.js start near2eth-relay --near2eth-relay-min-delay 1 --near2eth-relay-max-delay 30 --near2eth-relay-after-submit-delay-ms 40000 --near2eth-relay-block-select-duration 5 +node index.js start near2eth-relay --near2eth-relay-min-delay 1 --near2eth-relay-max-delay 30 --near2eth-relay-after-submit-delay-ms 40000 --near2eth-relay-block-select-duration 0 sleep 5 yarn run pm2 list node index.js start eth2near-relay diff --git a/testing/ci/test_ethrelay_catchup.sh b/testing/ci/test_ethrelay_catchup.sh index 8c60a7ffc..92384af0d 100755 --- a/testing/ci/test_ethrelay_catchup.sh +++ b/testing/ci/test_ethrelay_catchup.sh @@ -46,7 +46,7 @@ node index.js init-near-token-factory yarn run pm2 ping sleep 5 yarn run pm2 list -node index.js start near2eth-relay --near2eth-relay-min-delay 1 --near2eth-relay-max-delay 30 --near2eth-relay-after-submit-delay-ms 15000 --near2eth-relay-block-select-duration 5 +node index.js start near2eth-relay --near2eth-relay-min-delay 1 --near2eth-relay-max-delay 30 --near2eth-relay-after-submit-delay-ms 15000 --near2eth-relay-block-select-duration 0 sleep 5 yarn run pm2 list sleep 100 diff --git a/testing/transfer-eth-erc20/deploy-token.js b/testing/transfer-eth-erc20/deploy-token.js index 88f42e82e..fab2a62a5 100644 --- a/testing/transfer-eth-erc20/deploy-token.js +++ b/testing/transfer-eth-erc20/deploy-token.js @@ -39,7 +39,7 @@ class DeployToken { nodeUrl: nearNodeUrl, networkId: nearNetworkId, masterAccount: nearMasterAccount, - deps: { keyStore: keyStore } + keyStore }) await verifyAccount(near, nearMasterAccount) diff --git a/testing/transfer-eth-erc20/from-near.js b/testing/transfer-eth-erc20/from-near.js index ba4c14366..5400c8723 100644 --- a/testing/transfer-eth-erc20/from-near.js +++ b/testing/transfer-eth-erc20/from-near.js @@ -370,7 +370,7 @@ class TransferEthERC20FromNear { nodeUrl: nearNodeUrl, networkId: nearNetworkId, masterAccount: nearSenderAccountId, - deps: { keyStore: keyStore } + keyStore }) const nearSenderAccount = new nearAPI.Account( near.connection, diff --git a/testing/transfer-eth-erc20/to-near.js b/testing/transfer-eth-erc20/to-near.js index 8e1bfe896..ce68cf60d 100644 --- a/testing/transfer-eth-erc20/to-near.js +++ b/testing/transfer-eth-erc20/to-near.js @@ -301,7 +301,7 @@ class TransferETHERC20ToNear { nodeUrl: nearNodeUrl, networkId: nearNetworkId, masterAccount: nearMasterAccountId, - deps: { keyStore: keyStore } + keyStore }) const nearMasterAccount = new nearAPI.Account( near.connection, diff --git a/utils/address-watcher.js b/utils/address-watcher.js index 56d08b3cf..bacd1c6e1 100644 --- a/utils/address-watcher.js +++ b/utils/address-watcher.js @@ -17,9 +17,7 @@ class AddressWatcher { this.near = await nearAPI.connect({ nodeUrl: nearNodeUrl, networkId: networkId, - deps: { - keyStore: new nearAPI.keyStores.InMemoryKeyStore() - } + keyStore: new nearAPI.keyStores.InMemoryKeyStore() }) this.metricsPort = metricsPort diff --git a/utils/borsh.js b/utils/borsh.js index a06124355..642189a7b 100644 --- a/utils/borsh.js +++ b/utils/borsh.js @@ -24,15 +24,15 @@ class BorshError extends Error { function serializeField (schema, value, fieldType, writer) { if (fieldType === 'u8') { - writer.write_u8(value) + writer.writeU8(value) } else if (fieldType === 'u64') { - writer.write_u64(value) + writer.writeU64(value) } else if (fieldType === 'u128') { - writer.write_u128(value) + writer.writeU128(value) } else if (fieldType === 'bool') { - return writer.write_u8(value ? 1 : 0) + return writer.writeU8(value ? 1 : 0) } else if (fieldType === 'string') { - return writer.write_string(value) + return writer.writeString(value) } else if (fieldType instanceof Array) { if (typeof fieldType[0] === 'number') { if (value.length !== fieldType[0]) { @@ -40,9 +40,9 @@ function serializeField (schema, value, fieldType, writer) { `Expecting byte array of length ${fieldType[0]}, but got ${value.length} bytes` ) } - writer.write_fixed_array(value) + writer.writeFixedArray(value) } else { - writer.write_array(value, (item) => { + writer.writeArray(value, (item) => { serializeField(schema, item, fieldType[0], writer) }) } @@ -53,9 +53,9 @@ function serializeField (schema, value, fieldType, writer) { } if (structSchema.kind === 'option') { if (value === null) { - writer.write_u8(0) + writer.writeU8(0) } else { - writer.write_u8(1) + writer.writeU8(1) serializeField(schema, value, structSchema.type, writer) } } else if (structSchema.kind === 'struct') { @@ -63,7 +63,7 @@ function serializeField (schema, value, fieldType, writer) { serializeField(schema, value[fieldName], fieldType, writer) ) } else if (structSchema.kind === 'function') { - writer.write_buffer(structSchema.ser(value)) + writer.writeBuffer(structSchema.ser(value)) } else { throw new Error( `Unexpected schema kind: ${structSchema.kind} for ${fieldType}` @@ -224,7 +224,7 @@ const signAndSendTransactionAsync = async ( const status = await account.connection.provider.status() const [txHash, signedTx] = await nearAPI.transactions.signTransaction( receiverId, - ++accessKey.nonce, + ++accessKey.accessKey.nonce, actions, nearAPI.utils.serialize.base_decode(status.sync_info.latest_block_hash), account.connection.signer, @@ -300,10 +300,13 @@ class BorshContract { value: async (args) => { args = serialize(borshSchema, d.inputFieldType, args) const result = await backoff(10, () => - this.account.connection.provider.query( - `call/${this.contractId}/${d.methodName}`, - nearAPI.utils.serialize.base_encode(args) - ) + this.account.connection.provider.query({ + request_type: 'call_function', + finality: 'final', + account_id: this.contractId, + method_name: d.methodName, + args_base64: args.toString('base64') + }) ) if (result.logs) { this.account.printLogs(this.contractId, result.logs) diff --git a/utils/helpers.js b/utils/helpers.js index 6f8be76d3..8aead9847 100644 --- a/utils/helpers.js +++ b/utils/helpers.js @@ -109,9 +109,10 @@ async function getAccountStatus (near, accountId) { async function accountExists (near, accountId) { const account = new nearAPI.Account(near.connection, accountId) try { - await account.fetchState() + await account.state() return true } catch (e) { + console.log(e) return false } } @@ -119,7 +120,7 @@ async function accountExists (near, accountId) { // Checks whether the account has the key specified in the keyStore. async function accountHasTheKey (near, accountId) { const account = new nearAPI.Account(near.connection, accountId) - const keyStoreKey = await near.config.deps.keyStore.getKey( + const keyStoreKey = await near.config.keyStore.getKey( near.config.networkId, accountId ) diff --git a/utils/package.json b/utils/package.json index ba8e9af07..15eb27dbd 100644 --- a/utils/package.json +++ b/utils/package.json @@ -25,7 +25,7 @@ "eth-object": "https://github.com/near/eth-object#383b6ea68c7050bea4cab6950c1d5a7fa553e72b", "eth-util-lite": "near/eth-util-lite#master", "lodash": "^4.17.20", - "near-api-js": "^0.26.0", + "near-api-js": "^1.1.0", "web3": "^1.6.0" } } diff --git a/utils/robust.js b/utils/robust.js index 4929a45c4..d62a360cb 100644 --- a/utils/robust.js +++ b/utils/robust.js @@ -286,7 +286,7 @@ const signAndSendTransaction = async ( let signedTx ;[txHash, signedTx] = await nearAPI.transactions.signTransaction( receiverId, - ++accessKey.nonce, + ++accessKey.accessKey.nonce, actions, nearAPI.utils.serialize.base_decode( status.sync_info.latest_block_hash diff --git a/utils/utils.js b/utils/utils.js index 34a88614e..0a0d23975 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -11,14 +11,14 @@ const PROJECT_KEY_DIR = './neardev' const DEFAULT_GAS = 1000000 async function setupNear (config) { - const deps = await createLocalKeyStore(config.networkId, config.keyPath) + const keyStore = await createLocalKeyStore(config.networkId, config.keyPath) if (config.keyPath) { delete config.keyPath } return nearAPI.connect({ networkId: config.networkId, nodeUrl: config.nearNodeUrl, - deps + keyStore }) } @@ -89,7 +89,7 @@ async function createLocalKeyStore (networkId, keyPath) { keyStore.setKey(networkId, account.account_id, keyPair).then(() => {}) keyStores.push(keyStore) } - return { keyStore: new nearAPI.keyStores.MergeKeyStore(keyStores) } + return new nearAPI.keyStores.MergeKeyStore(keyStores) } function getWeb3 (config) { diff --git a/yarn.lock b/yarn.lock index 30ed2a61d..db38480f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1700,6 +1700,11 @@ bn.js@4.11.6: resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.6.tgz#53344adb14617a13f6e8dd2ce28905d1c0ba3215" integrity sha1-UzRK2xRhehP26N0s4okF0cC6MhU= +bn.js@5.2.1: + version "5.2.1" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70" + integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ== + bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.11.0, bn.js@^4.11.6, bn.js@^4.11.8, bn.js@^4.11.9: version "4.12.0" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88" @@ -1747,6 +1752,15 @@ body-parser@^1.16.0: raw-body "2.4.2" type-is "~1.6.18" +borsh@^0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/borsh/-/borsh-0.7.0.tgz#6e9560d719d86d90dc589bca60ffc8a6c51fec2a" + integrity sha512-CLCsZGIBCFnPtkNnieW/a8wmreDmfUtjU2m9yHrzPXIlNbqVs0AQrSatSG6vdNYUqdc83tkQi2eHfF98ubzQLA== + dependencies: + bn.js "^5.2.0" + bs58 "^4.0.0" + text-encoding-utf-8 "^1.0.2" + brace-expansion@^1.1.7: version "1.1.11" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" @@ -2821,7 +2835,7 @@ error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" -error-polyfill@^0.1.2: +error-polyfill@^0.1.3: version "0.1.3" resolved "https://registry.yarnpkg.com/error-polyfill/-/error-polyfill-0.1.3.tgz#df848b61ad8834f7a5db69a70b9913df86721d15" integrity sha512-XHJk60ufE+TG/ydwp4lilOog549iiQF2OAPhkk9DdiYWMrltz5yhDz/xnKuenNwP7gy3dsibssO5QpVhkrSzzg== @@ -5863,20 +5877,20 @@ natural-compare@^1.4.0: resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc= -near-api-js@^0.26.0: - version "0.26.0" - resolved "https://registry.yarnpkg.com/near-api-js/-/near-api-js-0.26.0.tgz#1d13571e0ec107aaf61b908466c38110ba5bf97b" - integrity sha512-aeRU2oWo6qKJF2oM7IcZ10vEqohxk6palTTx7LBUBsaKjF8561gBNIPhnkndhSrpsVSA9NBibX80WfOmK1tqrw== +near-api-js@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/near-api-js/-/near-api-js-1.1.0.tgz#907e807f052c1f043c6fbf28f61872de3c02235a" + integrity sha512-qYKv1mYsaDZc2uYndhS+ttDhR9+60qFc+ZjD6lWsAxr3ZskMjRwPffDGQZYhC7BRDQMe1HEbk6d5mf+TVm0Lqg== dependencies: - "@types/bn.js" "^4.11.5" - bn.js "^5.0.0" + bn.js "5.2.1" + borsh "^0.7.0" bs58 "^4.0.0" depd "^2.0.0" - error-polyfill "^0.1.2" + error-polyfill "^0.1.3" http-errors "^1.7.2" js-sha256 "^0.9.0" mustache "^4.0.0" - node-fetch "^2.3.0" + node-fetch "^2.6.1" text-encoding-utf-8 "^1.0.2" tweetnacl "^1.0.1" @@ -5922,7 +5936,7 @@ node-addon-api@^2.0.0: resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-2.0.2.tgz#432cfa82962ce494b132e9d72a15b29f71ff5d32" integrity sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA== -node-fetch@^2.3.0, node-fetch@^2.6.7: +node-fetch@^2.6.1, node-fetch@^2.6.7: version "2.6.7" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== @@ -6810,7 +6824,7 @@ quick-lru@^5.1.1: eth-object "https://github.com/near/eth-object#383b6ea68c7050bea4cab6950c1d5a7fa553e72b" eth-util-lite near/eth-util-lite#master lodash "^4.17.20" - near-api-js "^0.26.0" + near-api-js "^1.1.0" web3 "^1.6.0" rainbow-token-connector@near/rainbow-token-connector#134b3b6ad900d90c6f993c52f4e3edf985aec61a: