VenusProtocol / venus-js

Venus Protocol JavaScript SDK
BSD 3-Clause "New" or "Revised" License
13 stars 19 forks source link

PR : Verified comptroller methods #1

Closed z-th-btc closed 4 years ago

z-th-btc commented 4 years ago

Description

Fixed and verified comptroller enterMarkets, exitMarkets methods.

How to test

const Web3 = require('web3'); const web3 = new Web3(provider);

(async function () {

const block = await venus._provider.provider.getBlockNumber(); console.log('block', block);

const gasPrice = new BigNumber(await web3.eth.getGasPrice()).times(1.5).dp(0, 2).toNumber(); let preDefinedGasValue = new BigNumber(500000).dp(0, 2).toNumber(); let nonce = await web3.eth.getTransactionCount('0x58E312B1b0A16dF7F3D103cAB7BE438de301e534'); // const gasLimit = new BigNumber(preDefinedGasValue).multipliedBy(new BigNumber(gasPrice)).dp(0, 2).toNumber(); const gasLimit = new BigNumber(150000).dp(0, 2).toNumber();

const options = { gasPrice: 0x${gasPrice.toString(16)}, gas: 0x${preDefinedGasValue.toString(16)}, value: '0x00', nonce: 0x${nonce.toString(16)}, // chainId, // from: options.from, gasLimit: 0x${gasLimit.toString(16)}, } console.log('options object', options); const trx = await venus.enterMarkets(Venus.SXP, options); // Use [] for multiple console.log('Ethers.js transaction object', trx);

})().catch(console.error);


- Result

block 3779166 Ethers.js options object { gasPrice: '0x6fc23ac00', gas: '0x7a120', value: '0x00', nonce: '0xa', gasLimit: '0x249f0' } --- vToken addresses: [ '0x74469281310195A04840Daf6EdF576F559a3dE80' ] --- comptroller address: 0x94d1820b2D1c7c7452A163983Dc888CEC546b77D Ethers.js transaction object { nonce: 10, gasPrice: BigNumber { _hex: '0x06fc23ac00', _isBigNumber: true }, gasLimit: BigNumber { _hex: '0x0249f0', _isBigNumber: true }, to: '0x94d1820b2D1c7c7452A163983Dc888CEC546b77D', value: BigNumber { _hex: '0x00', _isBigNumber: true }, data: '0xc29982380000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000074469281310195a04840daf6edf576f559a3de80', chainId: 97, v: 229, r: '0xdf051aa5e3c3c1d8b4a326c9e6dc69eaba5e2436774e06d0cacfc624a0ec8dc5', s: '0x209724744e7c3ce37d49705d7d07f58b8a17d15e10a6ae5806e8a206fb67d2c4', from: '0x58E312B1b0A16dF7F3D103cAB7BE438de301e534', hash: '0x69895d4377a057c2363e1e6cefa88512d295a8a6f46738803000ee14eacba06c', wait: [Function] }


- Transaction detail
![image](https://user-images.githubusercontent.com/42106554/99694767-7e961680-2ad8-11eb-8256-fd3c3da61577.png)