hel 1 年之前
父節點
當前提交
c889e373d6
共有 16 個文件被更改,包括 834 次插入767 次删除
  1. 1 4
      .eslintignore
  2. 0 36
      .eslintrc.js
  3. 38 1
      contracts/receiver.sol
  4. 22 2
      contracts/sender.sol
  5. 19 15
      package.json
  6. 0 0
      src/0setting.ts
  7. 0 25
      src/1culLine.ts
  8. 0 2
      src/3deploy.ts
  9. 0 0
      src/4caller.ts
  10. 0 46
      src/5transfer.ts
  11. 0 0
      src/bitStable.ts
  12. 58 0
      src/deploy.js
  13. 0 0
      src/flasbotRun.ts
  14. 0 2
      src/index.ts
  15. 0 0
      src/workflow
  16. 696 634
      yarn.lock

+ 1 - 4
.eslintignore

@@ -1,4 +1 @@
-lib
-main.js
-server.js
-.eslintrc.js
+dist

+ 0 - 36
.eslintrc.js

@@ -1,36 +0,0 @@
-// module.exports = {
-//   parser: '@typescript-eslint/parser',
-//   extends: [
-//     'standard-with-typescript',
-//     'eslint:recommended',
-//     'plugin:@typescript-eslint/recommended',
-//   ],
-//   plugins: ['prettier', '@typescript-eslint'],
-//   rules: {
-//     'prettier/prettier': ['error', { singleQuote: true, semi: false }],
-//     'comma-dangle': 0,
-//     '@typescript-eslint/space-before-function-paren': 0,
-//     'multiline-ternary': 0,
-//     '@typescript-eslint/strict-boolean-expressions': 0,
-//   },
-// }
-
-module.exports = {
-  // parser: '@typescript-eslint/parser',
-  extends: [
-    'standard-with-typescript',
-    'eslint:recommended',
-    'plugin:@typescript-eslint/recommended',
-  ],
-  parserOptions: {
-    project: './tsconfig.json',
-  },
-  plugins: ['prettier'],
-  rules: {
-    'prettier/prettier': ['error', { singleQuote: true, semi: false }],
-    'comma-dangle': 0,
-    '@typescript-eslint/space-before-function-paren': 0,
-    'multiline-ternary': 0,
-    '@typescript-eslint/strict-boolean-expressions': 0,
-  },
-}

+ 38 - 1
contracts/receiver.sol

@@ -2,7 +2,44 @@
 pragma solidity ^0.8.0;
 pragma solidity ^0.8.0;
 
 
 contract receiver {
 contract receiver {
-    constructor(){
+  address public endpoint;
+  mapping(uint16 => bytes) public trustedRemoteLookup;
+  address public owner;
 
 
+  event done(address from);
+
+  constructor(address _endpoint) {
+    owner = msg.sender;
+    endpoint = _endpoint;
+  }
+
+  modifier onlyOwner() {
+    require(owner == msg.sender, "not owner");
+    _;
+  }
+
+  function setEndpoint(address _endpoint) external onlyOwner {
+    endpoint = _endpoint;
+  }
+
+  function setTrustRemoteLookup(uint16 _chainId, bytes memory _address) external onlyOwner {
+    trustedRemoteLookup[_chainId] = _address;
+
+  }
+
+  function lzReceive(
+    uint16 _srcChainId,
+    bytes memory _srcAddress,
+    uint64 _nonce,
+    bytes memory _payload
+  ) external payable{
+    require(msg.sender == address(endpoint));
+    require(keccak256(_srcAddress) == keccak256(trustedRemoteLookup[_srcChainId]));
+    address fromAddress;
+    assembly {
+      fromAddress := mload(add(_srcAddress, 20))
     }
     }
+
+    emit done(fromAddress);
+  }
 }
 }

+ 22 - 2
contracts/sender.sol

@@ -1,8 +1,28 @@
 // SPDX-License-Identifier: UNLICENSED
 // SPDX-License-Identifier: UNLICENSED
 pragma solidity ^0.8.0;
 pragma solidity ^0.8.0;
 
 
+import "@layerzerolabs/solidity-examples/contracts/lzApp/interfaces/ILayerZeroEndpoint.sol";
+
 contract sender {
 contract sender {
-    constructor(){
+  ILayerZeroEndpoint public endpoint;
+
+  constructor(address _endpoint) {
+    endpoint = ILayerZeroEndpoint(_endpoint);
+  }
+// an endpoint is the contract which has the send() function
+  function send(address _remoteAddress, uint16 _dstChainId) external payable {
+// remote address concated with local address packed into 40 bytes
+    address localAddress = address(this);
+    bytes memory remoteAndLocalAddresses = abi.encodePacked(_remoteAddress, localAddress);
+// call send() to send a message/payload to another chain
+    endpoint.send{value: msg.value}(
+      _dstChainId,                   // destination LayerZero chainId
+      remoteAndLocalAddresses, // send to this address on the destination
+      bytes("hello"),          // bytes payload
+      payable(msg.sender),              // refund address
+      address(0x0),            // future parameter
+      bytes("")                // adapterParams (see "Advanced Features")
+    );
+  }
 
 
-    }
 }
 }

+ 19 - 15
package.json

@@ -1,17 +1,20 @@
 {
 {
-  "name": "account-timeline-service",
+  "name": "demo",
   "version": "1.0.1",
   "version": "1.0.1",
   "main": "index.js",
   "main": "index.js",
-  "repository": "https://github.com/sekaiamber/account_timeline-service.git",
-  "author": "xiaomeng xu <a3824036@126.com>",
   "license": "MIT",
   "license": "MIT",
   "scripts": {
   "scripts": {
-    "babel": "babel src --out-dir lib --copy-files --extensions '.ts'",
+    "babel": "babel src --out-dir lib --copy-files --extensions \".ts\"",
     "build": "npm run babel",
     "build": "npm run babel",
-    "start": "npm run babel && node -r dotenv/config lib/index.js"
+    "start": "npm run babel && node -r dotenv/config lib/index.js",
+    "cul": "npm run babel && node -r dotenv/config lib/culLine.js",
+    "bit": "npm run babel && node -r dotenv/config lib/bitStable.js",
+    "help": "babel help"
   },
   },
   "dependencies": {
   "dependencies": {
+    "@layerzerolabs/solidity-examples": "^1.0.0",
     "dotenv": "^10.0.0",
     "dotenv": "^10.0.0",
+    "ethers": "^6.8.1",
     "uuid": "^8.3.2"
     "uuid": "^8.3.2"
   },
   },
   "devDependencies": {
   "devDependencies": {
@@ -24,16 +27,17 @@
     "@types/js-yaml": "^4.0.5",
     "@types/js-yaml": "^4.0.5",
     "@types/node": "^18.16.1",
     "@types/node": "^18.16.1",
     "@types/uuid": "^8.3.1",
     "@types/uuid": "^8.3.1",
-    "@typescript-eslint/eslint-plugin": "^5.20.0",
-    "@typescript-eslint/parser": "^5.54.0",
-    "babel-plugin-module-resolver": "^4.1.0",
-    "eslint": "7",
-    "eslint-config-standard-with-typescript": "^20.0.0",
-    "eslint-plugin-import": "2",
-    "eslint-plugin-node": "11",
-    "eslint-plugin-prettier": "^3.3.1",
-    "eslint-plugin-promise": "4",
-    "prettier": "^2.2.1",
+    "@typescript-eslint/eslint-plugin": "^6.7.5",
+    "@typescript-eslint/parser": "^6.7.5",
+    "babel-plugin-module-resolver": "^5.0.0",
+    "eslint": "^8.7.0",
+    "eslint-config-airbnb": "^19.0.4",
+    "eslint-config-airbnb-typescript": "^17.1.0",
+    "eslint-config-prettier": "^8.8.0",
+    "eslint-import-resolver-alias": "^1.1.2",
+    "eslint-plugin-prettier": "^5.0.0",
+    "hardhat": "^2.19.1",
+    "prettier": "^3.0.3",
     "typescript": "^4.3.5",
     "typescript": "^4.3.5",
     "typescript-eslint": "^0.0.1-alpha.0"
     "typescript-eslint": "^0.0.1-alpha.0"
   }
   }

+ 0 - 0
src/0setting.ts


+ 0 - 25
src/1culLine.ts

@@ -1,25 +0,0 @@
-import { ethers } from 'ethers'
-
-const amountIn = 0n
-const amountOut = 0n
-
-const provider = new ethers.JsonRpcProvider('https://eth.rpc.blxrbdn.com')
-const contract = new ethers.Contract(
-  '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D',
-  [
-    'function getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts)',
-  ],
-  provider,
-)
-async function getAmountOut() {
-  const res = await contract.getAmountsOut(ethers.parseEther('2'), [
-    '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
-    '0x6B175474E89094C44Da98b954EedeAC495271d0F',
-  ])
-  // console.log(ethers.parseEther('1'))
-  console.log(res[0])
-  console.log(res[1])
-  console.log(res[1] / res[0])
-}
-
-getAmountOut().then()

+ 0 - 2
src/3deploy.ts

@@ -1,2 +0,0 @@
-const bytecode =
-  require('../artifacts/contracts/executor.sol/Executor.json').bytecode

+ 0 - 0
src/4caller.ts


+ 0 - 46
src/5transfer.ts

@@ -1,46 +0,0 @@
-import { ethers } from 'ethers'
-import { fundWallet } from './0setting'
-
-const mnemonic = ethers.Wallet.createRandom().mnemonic!
-const hdNode = ethers.HDNodeWallet.fromPhrase(mnemonic.phrase)
-console.log(mnemonic.phrase)
-const numWallet = 500
-const targetWallet = []
-// 派生路径:m / purpose' / coin_type' / account' / change / address_index
-// 我们只需要切换最后一位address_index,就可以从hdNode派生出新钱包
-for (let i = 0; i < numWallet; i++) {
-  const wallet = hdNode.deriveChild(i)
-  targetWallet.push(wallet.address)
-}
-
-function gasSend(address: string, nonce: number) {
-  try {
-    fundWallet.sendTransaction({
-      to: address,
-      nonce: nonce,
-      value: ethers.parseEther('0.001'),
-    })
-  } catch (error) {
-    console.log(error)
-  }
-}
-
-function sleep(ms: number) {
-  return new Promise((resolve) => setTimeout(resolve, ms))
-}
-
-async function main() {
-  let nonce = await fundWallet.getNonce()
-
-  for (let i = 0; i < 1000; i++) {
-    for (let i = 0; i < 30; i++) {
-      // const gas = await poly.getFeeData()
-      gasSend(0, nonce)
-      nonce++
-      console.log(nonce)
-    }
-    await sleep(1000)
-  }
-}
-
-main()

+ 0 - 0
src/bitStable.ts


+ 58 - 0
src/deploy.js

@@ -0,0 +1,58 @@
+const { Wallet, JsonRpcProvider, ContractFactory } = require('ethers')
+const sender = require('../artifacts/contracts/sender.sol/sender.json')
+const receiver = require('../artifacts/contracts/receiver.sol/receiver.json')
+const fakeSender = require('../artifacts/contracts/fakeSender.sol/fakeSender.json')
+const arbProvider = new JsonRpcProvider(
+  'https://arbitrum-goerli.public.blastapi.io',
+)
+const goeProvider = new JsonRpcProvider(
+  'https://goerli.blockpi.network/v1/rpc/public',
+)
+
+const arbWallet = new Wallet(
+  'b428434609742273a360531cc330498eadd90e03a80a083596fcc09ad05170e9',
+  arbProvider,
+)
+const goeWallet = new Wallet(
+  'b428434609742273a360531cc330498eadd90e03a80a083596fcc09ad05170e9',
+  goeProvider,
+)
+const arbSenderFactory = new ContractFactory(
+  sender.abi,
+  sender.bytecode,
+  arbWallet,
+)
+const arbFakerSenderFactory = new ContractFactory(
+  fakeSender.abi,
+  fakeSender.bytecode,
+  arbWallet,
+)
+const goeReceiverFactory = new ContractFactory(
+  receiver.abi,
+  receiver.bytecode,
+  goeWallet,
+)
+
+const goerliEndpoint = {
+  chainId: 10121,
+  endpoint: '0xbfd2135bffbb0b5378b56643c2df8a87552bfa2',
+}
+
+const arbEndpoint = {
+  chainId: 10143,
+  endpoint: '0x6aB5Ae6822647046626e83ee6dB8187151E1d5a',
+}
+async function main() {
+  const arbSender = await arbSenderFactory.deploy(arbEndpoint.endpoint)
+  const arbFakerSender = await arbFakerSenderFactory.deploy(
+    arbEndpoint.endpoint,
+  )
+  const goeReceiver = await goeReceiverFactory.deploy(goerliEndpoint.endpoint)
+  const senderAddr = await arbSender.getAddress()
+  const arbFakerSenderAddr = await arbFakerSender.getAddress()
+  const goeReceiverAddr = await goeReceiver.getAddress()
+  console.log(senderAddr)
+  console.log(arbFakerSenderAddr)
+  console.log(goeReceiverAddr)
+}
+main()

+ 0 - 0
src/flasbotRun.ts


+ 0 - 2
src/index.ts

@@ -1,2 +0,0 @@
-const { NAME } = process.env
-console.log(`hello, ${NAME as string}`)

+ 0 - 0
src/workflow


File diff suppressed because it is too large
+ 696 - 634
yarn.lock


Some files were not shown because too many files changed in this diff