欢迎光临散文网 会员登陆 & 注册

合约交易/秒合约/永续合约/合约跟单/交易所系统开发成熟案例/需求方案/搭建项目/源码

2023-07-05 10:24 作者:bili_36625761919  | 我要投稿

  区块链是什么?一句话,它是一种特殊的分布式数据库。首先,区块链的主要作用是储存信息。Any information that needs to be saved can be written to or read from the blockchain,so it is a database.


  Secondly,anyone can set up a server,join the blockchain network,and become a node.区块链的世界里面,没有中心节点,每个节点都是平等的,都保存着整个数据库。你可以向任何一个节点,写入/读取数据,因为所有节点最后都会同步,保证区块链一致。


  event DeployMarketEvent();


  event ChangeMarketStatusEvent(uint8 status);


  event SetTokenInfoEvent(uint16 tokenCode,string symbol,address tokenAddr,uint64 scaleFactor,uint minDeposit);


  event SetWithdrawAddrEvent(address trader,address withdrawAddr);


  event DepositEvent(address trader,uint16 tokenCode,string symbol,uint64 amountE8,uint64 depositIndex);


  event WithdrawEvent(address trader,uint16 tokenCode,string symbol,uint64 amountE8,uint64 lastOpIndex);


  event TransferFeeEvent(uint16 tokenCode,uint64 amountE8,address toAddr);


  //`balanceE8`is the total balance after this deposit confirmation


  event ConfirmDepositEvent(address trader,uint16 tokenCode,uint64 balanceE8);


  //`amountE8`is the post-fee initiated withdraw amount


  //`pendingWithdrawE8`is the total pending withdraw amount after this withdraw initiation


  event InitiateWithdrawEvent(address trader,uint16 tokenCode,uint64 amountE8,uint64 pendingWithdrawE8);


  event MatchOrdersEvent(address trader1,uint64 nonce1,address trader2,uint64 nonce2);


  event HardCancelOrderEvent(address trader,uint64 nonce);


  event SetFeeRatesEvent(uint16 makerFeeRateE4,uint16 takerFeeRateE4,uint16 withdrawFeeRateE4);


  event SetFeeRebatePercentEvent(address trader,uint8 feeRebatePercent);


  function Dex2(address admin_)public{


  admin=admin_;


  setTokenInfo(0/*tokenCode*/,"ETH",0/*tokenAddr*/,ETH_SCALE_FACTOR,0/*minDeposit*/);


  emit DeployMarketEvent();


  }


  function()external{


  revert();


  }


  //Change the market status of DEX.


  function changeMarketStatus(uint8 status_)external{


  if(msg.sender!=admin)revert();


  if(marketStatus==CLOSED)revert();//closed is forever


  marketStatus=status_;


  emit ChangeMarketStatusEvent(status_);


  }


  //Each trader can specify a withdraw address(but cannot change it later).Once a trader's


  //withdraw address is set,following withdrawals of this trader will go to the withdraw address


  //instead of the trader's address.


  function setWithdrawAddr(address withdrawAddr)external{


  if(withdrawAddr==0)revert();


  if(traders[msg.sender].withdrawAddr!=0)revert();//cannot change withdrawAddr once set


  traders[msg.sender].withdrawAddr=withdrawAddr;


  emit SetWithdrawAddrEvent(msg.sender,withdrawAddr);


  }


  //Deposit ETH from msg.sender for the given trader.


  function depositEth(address traderAddr)external payable{


  if(marketStatus!=ACTIVE)revert();


  if(traderAddr==0)revert();


  if(msg.value<tokens[0].minDeposit)revert();


  if(msg.data.length!=4+32)revert();//length condition of param count


  uint64 pendingAmountE8=uint64(msg.value/(ETH_SCALE_FACTOR/10**8));//msg.value is in Wei


  if(pendingAmountE8==0)revert();


  uint64 depositIndex=++lastDepositIndex;


  setDeposits(depositIndex,traderAddr,0,pendingAmountE8);


  emit DepositEvent(traderAddr,0,"ETH",pendingAmountE8,depositIndex);


  }


  //Deposit token(other than ETH)from msg.sender for a specified trader.


合约交易/秒合约/永续合约/合约跟单/交易所系统开发成熟案例/需求方案/搭建项目/源码的评论 (共 条)

分享到微博请遵守国家法律