diff --git a/.gitignore b/.gitignore index 6704566..9fa78db 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,9 @@ dist # TernJS port file .tern-port + +.idea/ + +package-lock.json +package.json +git \ No newline at end of file diff --git a/Class 1/silent_homework/approve.js b/Class 1/silent_homework/approve.js new file mode 100644 index 0000000..57fff59 --- /dev/null +++ b/Class 1/silent_homework/approve.js @@ -0,0 +1,23 @@ +module.exports=[{ + "constant": false, + "inputs": [ + { + "name": "guy", + "type": "address" + }, + { + "name": "wad", + "type": "uint256" + } +], + "name": "approve", + "outputs": [ + { + "name": "", + "type": "bool" + } +], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" +}] \ No newline at end of file diff --git a/Class 1/silent_homework/erc20.js b/Class 1/silent_homework/erc20.js new file mode 100644 index 0000000..b38a43d --- /dev/null +++ b/Class 1/silent_homework/erc20.js @@ -0,0 +1,327 @@ +module.exports = [ + { + constant: true, + inputs: [], + name: 'name', + outputs: [{ name: '', type: 'bytes32' }], + payable: false, + stateMutability: 'view', + type: 'function' + }, + { + constant: false, + inputs: [], + name: 'stop', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: false, + inputs: [ + { name: 'guy', type: 'address' }, + { name: 'wad', type: 'uint256' } + ], + name: 'approve', + outputs: [{ name: '', type: 'bool' }], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: false, + inputs: [{ name: 'owner_', type: 'address' }], + name: 'setOwner', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: true, + inputs: [], + name: 'totalSupply', + outputs: [{ name: '', type: 'uint256' }], + payable: false, + stateMutability: 'view', + type: 'function' + }, + { + constant: false, + inputs: [ + { name: 'src', type: 'address' }, + { name: 'dst', type: 'address' }, + { name: 'wad', type: 'uint256' } + ], + name: 'transferFrom', + outputs: [{ name: '', type: 'bool' }], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: true, + inputs: [], + name: 'decimals', + outputs: [{ name: '', type: 'uint256' }], + payable: false, + stateMutability: 'view', + type: 'function' + }, + { + constant: false, + inputs: [ + { name: 'guy', type: 'address' }, + { name: 'wad', type: 'uint256' } + ], + name: 'mint', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: false, + inputs: [{ name: 'wad', type: 'uint256' }], + name: 'burn', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: false, + inputs: [{ name: 'name_', type: 'bytes32' }], + name: 'setName', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: true, + inputs: [{ name: 'src', type: 'address' }], + name: 'balanceOf', + outputs: [{ name: '', type: 'uint256' }], + payable: false, + stateMutability: 'view', + type: 'function' + }, + { + constant: true, + inputs: [], + name: 'stopped', + outputs: [{ name: '', type: 'bool' }], + payable: false, + stateMutability: 'view', + type: 'function' + }, + { + constant: false, + inputs: [{ name: 'authority_', type: 'address' }], + name: 'setAuthority', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: true, + inputs: [], + name: 'owner', + outputs: [{ name: '', type: 'address' }], + payable: false, + stateMutability: 'view', + type: 'function' + }, + { + constant: true, + inputs: [], + name: 'symbol', + outputs: [ {"internalType": "string", + "name": "", + "type": "string"}], + payable: false, + stateMutability: 'view', + type: 'function' + }, + { + constant: false, + inputs: [ + { name: 'guy', type: 'address' }, + { name: 'wad', type: 'uint256' } + ], + name: 'burn', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: false, + inputs: [{ name: 'wad', type: 'uint256' }], + name: 'mint', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: false, + inputs: [ + { name: 'dst', type: 'address' }, + { name: 'wad', type: 'uint256' } + ], + name: 'transfer', + outputs: [{ name: '', type: 'bool' }], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: false, + inputs: [ + { name: 'dst', type: 'address' }, + { name: 'wad', type: 'uint256' } + ], + name: 'push', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: false, + inputs: [ + { name: 'src', type: 'address' }, + { name: 'dst', type: 'address' }, + { name: 'wad', type: 'uint256' } + ], + name: 'move', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: false, + inputs: [], + name: 'start', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: true, + inputs: [], + name: 'authority', + outputs: [{ name: '', type: 'address' }], + payable: false, + stateMutability: 'view', + type: 'function' + }, + { + constant: false, + inputs: [{ name: 'guy', type: 'address' }], + name: 'approve', + outputs: [{ name: '', type: 'bool' }], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: true, + inputs: [ + { name: 'src', type: 'address' }, + { name: 'guy', type: 'address' } + ], + name: 'allowance', + outputs: [{ name: '', type: 'uint256' }], + payable: false, + stateMutability: 'view', + type: 'function' + }, + { + constant: false, + inputs: [ + { name: 'src', type: 'address' }, + { name: 'wad', type: 'uint256' } + ], + name: 'pull', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [{ name: 'symbol_', type: 'bytes32' }], + payable: false, + stateMutability: 'nonpayable', + type: 'constructor' + }, + { + anonymous: false, + inputs: [ + { indexed: true, name: 'guy', type: 'address' }, + { indexed: false, name: 'wad', type: 'uint256' } + ], + name: 'Mint', + type: 'event' + }, + { + anonymous: false, + inputs: [ + { indexed: true, name: 'guy', type: 'address' }, + { indexed: false, name: 'wad', type: 'uint256' } + ], + name: 'Burn', + type: 'event' + }, + { + anonymous: false, + inputs: [{ indexed: true, name: 'authority', type: 'address' }], + name: 'LogSetAuthority', + type: 'event' + }, + { + anonymous: false, + inputs: [{ indexed: true, name: 'owner', type: 'address' }], + name: 'LogSetOwner', + type: 'event' + }, + { + anonymous: true, + inputs: [ + { indexed: true, name: 'sig', type: 'bytes4' }, + { indexed: true, name: 'guy', type: 'address' }, + { indexed: true, name: 'foo', type: 'bytes32' }, + { indexed: true, name: 'bar', type: 'bytes32' }, + { indexed: false, name: 'wad', type: 'uint256' }, + { indexed: false, name: 'fax', type: 'bytes' } + ], + name: 'LogNote', + type: 'event' + }, + { + anonymous: false, + inputs: [ + { indexed: true, name: 'src', type: 'address' }, + { indexed: true, name: 'guy', type: 'address' }, + { indexed: false, name: 'wad', type: 'uint256' } + ], + name: 'Approval', + type: 'event' + }, + { + anonymous: false, + inputs: [ + { indexed: true, name: 'src', type: 'address' }, + { indexed: true, name: 'dst', type: 'address' }, + { indexed: false, name: 'wad', type: 'uint256' } + ], + name: 'Transfer', + type: 'event' + } +]; \ No newline at end of file diff --git a/Class 1/silent_homework/pancakeabi.js b/Class 1/silent_homework/pancakeabi.js new file mode 100644 index 0000000..968e9ab --- /dev/null +++ b/Class 1/silent_homework/pancakeabi.js @@ -0,0 +1,983 @@ +module.exports=[ + { + "inputs": [ + { + "internalType": "address", + "name": "_factory", + "type": "address" + }, + { + "internalType": "address", + "name": "_WETH", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + + ], + "name": "WETH", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenA", + "type": "address" + }, + { + "internalType": "address", + "name": "tokenB", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amountADesired", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountBDesired", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountAMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountBMin", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "addLiquidity", + "outputs": [ + { + "internalType": "uint256", + "name": "amountA", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountB", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amountTokenDesired", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountTokenMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETHMin", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "addLiquidityETH", + "outputs": [ + { + "internalType": "uint256", + "name": "amountToken", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETH", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + + ], + "name": "factory", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "reserveIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "reserveOut", + "type": "uint256" + } + ], + "name": "getAmountIn", + "outputs": [ + { + "internalType": "uint256", + "name": "amountIn", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "reserveIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "reserveOut", + "type": "uint256" + } + ], + "name": "getAmountOut", + "outputs": [ + { + "internalType": "uint256", + "name": "amountOut", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountOut", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + } + ], + "name": "getAmountsIn", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountIn", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + } + ], + "name": "getAmountsOut", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountA", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "reserveA", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "reserveB", + "type": "uint256" + } + ], + "name": "quote", + "outputs": [ + { + "internalType": "uint256", + "name": "amountB", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenA", + "type": "address" + }, + { + "internalType": "address", + "name": "tokenB", + "type": "address" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountAMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountBMin", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "removeLiquidity", + "outputs": [ + { + "internalType": "uint256", + "name": "amountA", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountB", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountTokenMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETHMin", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "removeLiquidityETH", + "outputs": [ + { + "internalType": "uint256", + "name": "amountToken", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETH", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountTokenMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETHMin", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "removeLiquidityETHSupportingFeeOnTransferTokens", + "outputs": [ + { + "internalType": "uint256", + "name": "amountETH", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountTokenMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETHMin", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "approveMax", + "type": "bool" + }, + { + "internalType": "uint8", + "name": "v", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + } + ], + "name": "removeLiquidityETHWithPermit", + "outputs": [ + { + "internalType": "uint256", + "name": "amountToken", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETH", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountTokenMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETHMin", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "approveMax", + "type": "bool" + }, + { + "internalType": "uint8", + "name": "v", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + } + ], + "name": "removeLiquidityETHWithPermitSupportingFeeOnTransferTokens", + "outputs": [ + { + "internalType": "uint256", + "name": "amountETH", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenA", + "type": "address" + }, + { + "internalType": "address", + "name": "tokenB", + "type": "address" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountAMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountBMin", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "approveMax", + "type": "bool" + }, + { + "internalType": "uint8", + "name": "v", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + } + ], + "name": "removeLiquidityWithPermit", + "outputs": [ + { + "internalType": "uint256", + "name": "amountA", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountB", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountOut", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapETHForExactTokens", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountOutMin", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapExactETHForTokens", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountOutMin", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapExactETHForTokensSupportingFeeOnTransferTokens", + "outputs": [ + + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountOutMin", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapExactTokensForETH", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountOutMin", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapExactTokensForETHSupportingFeeOnTransferTokens", + "outputs": [ + + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountOutMin", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapExactTokensForTokens", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountOutMin", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapExactTokensForTokensSupportingFeeOnTransferTokens", + "outputs": [ + + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountInMax", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapTokensForExactETH", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountInMax", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapTokensForExactTokens", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" + } +] \ No newline at end of file diff --git a/Class 1/silent_homework/read.js b/Class 1/silent_homework/read.js new file mode 100644 index 0000000..89d46fc --- /dev/null +++ b/Class 1/silent_homework/read.js @@ -0,0 +1,44 @@ +var Web3 = require('web3'); + +//创建 rpc 连接字符串 +var rpcstring = 'https://bsc-dataseed1.binance.org/' +//创建ws连接字符串 +var wstring = 'wss://bsc-ws-node.nariox.org:443'; +var wscweb3 = new Web3(new Web3.providers.WebsocketProvider(wstring)); +var rpcweb3 = new Web3(new Web3.providers.HttpProvider(rpcstring)); +web3 = rpcweb3; +var address="0x512aaD1d0E1492a9C4075aBa58cE1a944A74f973" + +const getBNBBalance = async (address) => { + let result = await web3.eth.getBalance(address) + let balance=web3.utils.fromWei(result.toString(),"ether") + console.log("地址" + address + "有" + balance + "个BNB"); + return balance; +} + +const erc20 = require('./erc20.js') +const getTokenBalance = async (tokenaddress, address) => { + //创建代币的智能合约函数 + var tokenContract = new web3.eth.Contract(erc20, tokenaddress); + + //调用代币的智能合约获取余额功能 + let result = await tokenContract.methods.balanceOf(address).call(); + //获得代币有多少位小数 + let decimals = await tokenContract.methods.decimals().call(); + let tokenbalance = web3.utils.fromWei(result.toString(10), "ether"); + + //获得代币的符号 + let symbol = await tokenContract.methods.symbol().call(); + + //打印结果 + console.log("地址" + address + "代币:" + symbol + "的数量是:" + tokenbalance); + return tokenbalance; +} + +getBNBBalance(address); +var tentokenaddress=new Array("0x0eb3a705fc54725037cc9e008bdede697f62f335","0xd2ff8c018a22ff06f4be781090579d0490b9a69f","0x9e3a9F1612028eeE48F85cA85f8Bed2f37d76848","0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c","0xc66e4de0d9b4f3cb3f271c37991fe62f154471eb","0x3fcca8648651e5b974dd6d3e50f61567779772a8","0xb16600c510b0f323dee2cb212924d90e58864421","0x5ece3f1542c4e1a06767457e4d8286bea772fc41","0x5190b01965b6e3d786706fd4a999978626c19880","0xc409ec8a33f31437ed753c82eed3c5f16d6d7e22"); + +for(let i in tentokenaddress){ + getTokenBalance(tentokenaddress[i],address); +} + diff --git a/Class 1/silent_homework/swap.js b/Class 1/silent_homework/swap.js new file mode 100644 index 0000000..55998bf --- /dev/null +++ b/Class 1/silent_homework/swap.js @@ -0,0 +1,131 @@ +var Web3 = require('web3'); +var EthereumTx = require('ethereumjs-tx').Transaction; +const util = require('ethereumjs-util') +const ethereumjs_common = require ('ethereumjs-common').default; + +var BSC_MAIN = ethereumjs_common.forCustomChain ('mainnet', { networkId: 56, chainId: 56, name: 'bnb' }, 'petersburg'); + + +//创建 rpc 连接字符串 +var rpcstring = 'https://bsc-dataseed1.binance.org/' +//创建ws连接字符串 +var wstring = 'wss://bsc-ws-node.nariox.org:443'; +var wscweb3 = new Web3(new Web3.providers.WebsocketProvider(wstring)); +var rpcweb3 = new Web3(new Web3.providers.HttpProvider(rpcstring)); +var web3 = rpcweb3; + +function getPriKey(prikeystring) { + const privKey =Buffer.from(prikeystring, "hex"); + return privKey; +} + +//这里是将交易用私钥签名部分 +function getEthRawTx(fromAddress, toAddress, input, nonceNum, privKey, gasPrice, nbnb, gaslimit) { + + var rawTransaction = { + from: fromAddress, + nonce: web3.utils.toHex(nonceNum), + gasLimit: web3.utils.toHex(gaslimit), + gasPrice: web3.utils.toHex(gasPrice), + to: toAddress, + value: web3.utils.toHex(nbnb), + data: web3.utils.toHex(input), + }; + const tx = new EthereumTx(rawTransaction,{common: BSC_MAIN}); + tx.sign(privKey); + const serializedTx = tx.serialize(); + return serializedTx; +} + +//将签名的内容发送到区块链网络中 +const signTransaction = async (fromAddress, toAddress, input, nonceNum, privKey, gasPrice, nbnb, gaslimit) => { + var serializedTx = getEthRawTx(fromAddress, toAddress, input, nonceNum, privKey, gasPrice, nbnb, gaslimit) + // Comment out these three lines if you don't really want to send the TX right now + console.log(`Attempting to send signed tx: ${serializedTx.toString('hex')}`); + var receipt = await web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex')); + console.log(`Receipt info: ${JSON.stringify(receipt, null, '\t')}`); + if (receipt.status == true) { + return true; + } + return false; +} + +const sendtx = async (prikeystring,contractaddress,value,input) => { + var priKey = getPriKey(prikeystring); + //获得自己的地址 + var fromAddress = "0x" + util.privateToAddress(priKey).toString('hex'); + value = web3.utils.toWei((value).toString(10), 'ether'); + //设置gasprice 为 5G wei + var gasPrice = web3.utils.toWei((5).toString(10), 'Gwei'); + //设置 gaslimit 为 420000 + var gaslimit = 420000 + console.log("从该地址发送:" + fromAddress) + //获得下一次交易的数 + var nonceCnt = await web3.eth.getTransactionCount(fromAddress); + let result = await signTransaction(fromAddress, contractaddress, input, nonceCnt, priKey, gasPrice, value, gaslimit) + if (result) { + console.log("发送成功") + } + else { + console.log("发送失败") + } +} + +const pancakeabi = require('./pancakeabi.js') +const moment = require("moment"); +function swapETHForExactTokensinput(abi,bnbnum,tokenaddress,initialrate,slippage,delaymin,accountaddress){ + var wbnbadddress="0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c" + var path = [wbnbadddress,tokenaddress]; + var amountOut= (bnbnum*(100 - slippage) / 100 * initialrate).toFixed(12); + var amountOutMin = web3.utils.toWei(amountOut.toString(10), "ether"); + var moment = require('moment'); + const now = moment().unix(); + const DEADLINE = now + 60 * delaymin; + var deadline = (DEADLINE).toString(10); + var input = web3.eth.abi.encodeFunctionCall(abi[17],[amountOutMin,path,accountaddress,deadline]); + return input; +} + +function approvetokeninput(contractaddress,num){ + const approve=require('./approve.js') + approvenum = web3.utils.toWei(num.toString(10), "ether"); + var input = web3.eth.abi.encodeFunctionCall(approve[0],[contractaddress,approvenum]); + return input; +} + +function approvetoken(prikeystring,tokencontractaddress,num,contractyouwanttoapprove){ + sendtx(prikeystring,tokencontractaddress,0,approvetokeninput(contractyouwanttoapprove,num)) +} + +function swapETHForExactTokens(prikeystring,routeraddress,abi,bnbnum,tokenaddress,initialrate,slippage,delaymin,toaddress){ + const input=swapETHForExactTokensinput(abi,bnbnum,tokenaddress,initialrate,slippage,delaymin,toaddress) + sendtx(prikeystring,routeraddress,bnbnum,input) +} + +function swapExactTokensForTokensinput(abi,tokenAnum,tokenA_address,tokenB_address,initialrate,slippage,delaymin,accountaddress){ + var amountIn=web3.utils.toWei(tokenAnum.toString(10), "ether"); + var amountOut=(tokenAnum*(100 - slippage) / 100 * initialrate).toFixed(12); + var amountOutMin = web3.utils.toWei(amountOut.toString(10), "ether"); + var path = [tokenA_address,tokenB_address]; + var moment = require('moment'); + const now = moment().unix(); + const DEADLINE = now + 60 * delaymin; + var deadline = (DEADLINE).toString(10); + var input = web3.eth.abi.encodeFunctionCall(abi[21],[amountIn,amountOutMin,path,accountaddress,deadline]); + return input; +} + +function swapExactTokensForTokens(prikeystring,routeraddress,abi,tokenAnum,tokenA_address,tokenB_address,initialrate,slippage,delaymin,toaddress){ + sendtx(prikeystring,routeraddress,0,swapExactTokensForTokensinput(abi,tokenAnum,tokenA_address,tokenB_address,initialrate,slippage,delaymin,toaddress)) +} + +var prikeystring=""; +var toAddress="0x0000158a8A7419a291187d20e47f748a5eA1824C"; +var atomaddress="0x0eb3a705fc54725037cc9e008bdede697f62f335"; +var pancakerouter="0x10ed43c718714eb63d5aa57b78b54704e256024e"; +var wbnbaddress="0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"; + + +swapETHForExactTokens(prikeystring,pancakerouter,pancakeabi,0.0001,atomaddress,14.39,1,10,toAddress) +approvetoken(prikeystring,atomaddress,1,pancakerouter) +swapExactTokensForTokens(prikeystring,pancakerouter, pancakeabi,0.002,atomaddress,wbnbaddress,0.0691,1,10,toAddress) \ No newline at end of file diff --git a/Class 1/silent_homework/transfer.js b/Class 1/silent_homework/transfer.js new file mode 100644 index 0000000..cf63d81 --- /dev/null +++ b/Class 1/silent_homework/transfer.js @@ -0,0 +1,112 @@ +var Web3 = require('web3'); +var EthereumTx = require('ethereumjs-tx').Transaction; +const util = require('ethereumjs-util') +const ethereumjs_common = require ('ethereumjs-common').default; + +var BSC_MAIN = ethereumjs_common.forCustomChain ('mainnet', { networkId: 56, chainId: 56, name: 'bnb' }, 'petersburg'); + + +//创建 rpc 连接字符串 +var rpcstring = 'https://bsc-dataseed1.binance.org/' +//创建ws连接字符串 +var wstring = 'wss://bsc-ws-node.nariox.org:443'; +var wscweb3 = new Web3(new Web3.providers.WebsocketProvider(wstring)); +var rpcweb3 = new Web3(new Web3.providers.HttpProvider(rpcstring)); +var web3 = rpcweb3; + +function getPriKey(prikeystring) { + const privKey =Buffer.from(prikeystring, "hex"); + return privKey; +} + +//这里是将交易用私钥签名部分 +function getEthRawTx(fromAddress, toAddress, input, nonceNum, privKey, gasPrice, nbnb, gaslimit) { + + var rawTransaction = { + from: fromAddress, + nonce: web3.utils.toHex(nonceNum), + gasLimit: web3.utils.toHex(gaslimit), + gasPrice: web3.utils.toHex(gasPrice), + to: toAddress, + value: web3.utils.toHex(nbnb), + data: web3.utils.toHex(input), + }; + const tx = new EthereumTx(rawTransaction,{common: BSC_MAIN}); + tx.sign(privKey); + const serializedTx = tx.serialize(); + return serializedTx; +} + +//将签名的内容发送到区块链网络中 +const signTransaction = async (fromAddress, toAddress, input, nonceNum, privKey, gasPrice, nbnb, gaslimit) => { + var serializedTx = getEthRawTx(fromAddress, toAddress, input, nonceNum, privKey, gasPrice, nbnb, gaslimit) + // Comment out these three lines if you don't really want to send the TX right now + console.log(`Attempting to send signed tx: ${serializedTx.toString('hex')}`); + var receipt = await web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex')); + console.log(`Receipt info: ${JSON.stringify(receipt, null, '\t')}`); + if (receipt.status == true) { + return true; + } + return false; +} + + + +const sendbnb = async (prikeystring,toAddress,nsendBNB) => { + var priKey = getPriKey(prikeystring); + //获得自己的地址 + var fromAddress = "0x" + util.privateToAddress(priKey).toString('hex'); + var nbnb = web3.utils.toWei((nsendBNB).toString(10), 'ether'); + //设置gasprice 为 5G wei + var gasPrice = web3.utils.toWei((5).toString(10), 'Gwei'); + //设置 gaslimit 为 420000 + var gaslimit = 420000 + //没有调用智能合约,将input设置为空 + var input = "" + //获得下一次交易的数 + console.log("从该地址发送:" + fromAddress) + var nonceCnt = await web3.eth.getTransactionCount(fromAddress); + let result = await signTransaction(fromAddress, toAddress, input, nonceCnt, priKey, gasPrice, nbnb, gaslimit) + if (result) { + console.log("发送成功") + } + else { + console.log("发送失败") + } +} +const transferabi=require('./transferabi.js') + +function transfertokeninput (num,toaddress){ + var weinum= web3.utils.toWei(num.toString(), "ether"); + var input = web3.eth.abi.encodeFunctionCall(transferabi[0],[toaddress,weinum]); + return input; +} + +const sendtx = async (prikeystring,contractaddress,value,input) => { + var priKey = getPriKey(prikeystring); + //获得自己的地址 + var fromAddress = "0x" + util.privateToAddress(priKey).toString('hex'); + value = web3.utils.toWei((value).toString(10), 'ether'); + //设置gasprice 为 5G wei + var gasPrice = web3.utils.toWei((5).toString(10), 'Gwei'); + //设置 gaslimit 为 420000 + var gaslimit = 420000 + console.log("从该地址发送:" + fromAddress) + //获得下一次交易的数 + var nonceCnt = await web3.eth.getTransactionCount(fromAddress); + let result = await signTransaction(fromAddress, contractaddress, input, nonceCnt, priKey, gasPrice, value, gaslimit) + if (result) { + console.log("发送成功") + } + else { + console.log("发送失败") + } +} +function sendcustomtoken(prikeystring,tokencontractaddress,num,toAddress){ + sendtx(prikeystring,tokencontractaddress,0,transfertokeninput(num,toAddress)); +} +var prikeystring=""; +var toAddress="0x512aaD1d0E1492a9C4075aBa58cE1a944A74f973"; +var wbnbAddress="0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c" +sendbnb(prikeystring,toAddress,0.001); +sendcustomtoken(prikeystring,wbnbAddress,0.01,toAddress) diff --git a/Class 1/silent_homework/transferabi.js b/Class 1/silent_homework/transferabi.js new file mode 100644 index 0000000..02ebdee --- /dev/null +++ b/Class 1/silent_homework/transferabi.js @@ -0,0 +1,25 @@ +module.exports=[ + { + "constant": false, + "inputs": [ + { + "name": "dst", + "type": "address" + }, + { + "name": "wad", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] \ No newline at end of file diff --git a/Class 1/source/test.js b/Class 1/source/test.js index b25f5bc..ffbc34d 100644 --- a/Class 1/source/test.js +++ b/Class 1/source/test.js @@ -184,7 +184,7 @@ const send = async () => { -const pancake = require('./pancake.js') +const pancake = require('./pancakeabi.js') //获取input内容 function swaptokeninput(wbnbadddress, toaddress, tokenamountIn, amountOut, tokenaddress, tokendecimals = 18,) {