PAXG質押挖礦節點系統開發/dapp單雙幣挖礦/流動性挖礦/詳情說明/案例分析/原始碼部署

xiaofufu發表於2023-05-19

      區塊鏈本質上是一種去中心化的分散式資料庫,是分散式資料儲存、多中心的點對點傳輸、共識機制和加密演算法等多種技術在網際網路時代的創新應用模式。


  區塊鏈(Blockchain)是一種由多方共同維護,使用密碼學保證傳輸和訪問安全,能夠實現資料一致儲存、難以篡改、防止抵賴的記賬技術,也稱為分散式賬本技術(Distributed Ledger Technology)。


  從本質上看,I35開閥7O98邏輯O7I8 區塊鏈是透過去中心化和去信任化,集體維護、分散式儲存的可靠資料庫。


  通俗地說,可以把區塊鏈比作一種“賬本”。傳統賬本由一方“集中記賬”,V++Mrsfu123 這種新式“賬本”則可以在網際網路上由多方參與、共享,各參與方都可以“記賬”並備份,而每個備份就是一個“區塊”。


  每個“區塊”與下一個“區塊”按時間順序線性相連,其結構特徵使記錄無法被篡改和偽造。


  pragma solidity=0.6.6;


  import'uniswap/lib/contracts/libraries/TransferHelper.sol';


  import'./interfaces/IUniswapV2Migrator.sol';


  import'./interfaces/V1/IUniswapV1Factory.sol';


  import'./interfaces/V1/IUniswapV1Exchange.sol';


  import'./interfaces/IUniswapV2Router01.sol';


  import'./interfaces/IERC20.sol';


  //該合約負責將V1遷移到V2


  contract UniswapV2Migrator is IUniswapV2Migrator{


  IUniswapV1Factory immutable factoryV1;//immutable相當於常量,可以在建構函式中設定,之後不能修改訪問他們相對來說更節省gas


  IUniswapV2Router01 immutable router;


  constructor(address _factoryV1,address _router)public{


  factoryV1=IUniswapV1Factory(_factoryV1);


  router=IUniswapV2Router01(_router);


  }


  //needs to accept ETH from any v1 exchange and the router.ideally this could be enforced,as in the router,


  //but it's not possible because it requires a call to the v1 factory,which takes too much gas


  //該函式旨在表明本合約可以接受其他地址的ETH轉賬


  receive()external payable{}


  function migrate(address token,uint amountTokenMin,uint amountETHMin,address to,uint deadline)//應該是V1主動呼叫本函式進行遷移


  external


  override


  {


  //V1是token/ETH交易對因此輸入token即可查詢對應地址


  IUniswapV1Exchange exchangeV1=IUniswapV1Exchange(factoryV1.getExchange(token));


  uint liquidityV1=exchangeV1.balanceOf(msg.sender);


  //將流動性代幣UNI1轉移到本合約中


  require(exchangeV1.transferFrom(msg.sender,address(this),liquidityV1),'TRANSFER_FROM_FAILED');


  //在本合約移除流動性銷燬UNI1返回token/ETH到本合約中


  (uint amountETHV1,uint amountTokenV1)=exchangeV1.removeLiquidity(liquidityV1,1,1,uint(-1));


  //授權給router合約進行路徑查詢後的token轉賬


  TransferHelper.safeApprove(token,address(router),amountTokenV1);


  //透過router為該token/ETH池子新增流動性


  (uint amountTokenV2,uint amountETHV2,)=router.addLiquidityETH{value:amountETHV1}(


  token,


  amountTokenV1,


  amountTokenMin,


  amountETHMin,


  to,


  deadline


  );


  if(amountTokenV1>amountTokenV2){


  TransferHelper.safeApprove(token,address(router),0);//be a good blockchain citizen,reset allowance to 0


  TransferHelper.safeTransfer(token,msg.sender,amountTokenV1-amountTokenV2);


  }else if(amountETHV1>amountETHV2){


  //addLiquidityETH guarantees that all of amountETHV1 or amountTokenV1 will be used,hence this else is safe


  TransferHelper.safeTransferETH(msg.sender,amountETHV1-amountETHV2);


  }


  }


  }


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69956839/viewspace-2953233/,如需轉載,請註明出處,否則將追究法律責任。

相關文章