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

合约交易系统开发(开发案例)丨合约交易所系统开发(逻辑方案)/设计程序/成熟源码

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

  智能合约的生命周期根据其运行机制可概括为协商、开发、部署、运维、学习和自毁六个阶段,其中开发阶段包括合约上链前的合约测试,学习阶段包括智能合约的运行反馈与合约更新等.图2所示为智能合约的基础架构模型,模型自底向上由基础设施层、合约层、运维层、智能层、表现层和应用层组成,


  基础设施层:封装了支持智能合约及其衍生应用实现的所有基础设施,包括分布式账本及其关键技术、开发环境和可信数据源等,这些基础设施的选择将在一定程度上影响智能合约的设计模式和合约属性.


  struct TokenInfo{


  string symbol;//e.g.,"ETH","ADX"


  address tokenAddr;//ERC20 token address


  uint64 scaleFactor;//<original token amount>=<scaleFactor>x<DEx amountE8>/1e8


  uint minDeposit;//mininum deposit(original token amount)allowed for this token


  }


  struct TraderInfo{


  address withdrawAddr;


  uint8 feeRebatePercent;//range:[0,100]


  }


  struct TokenAccount{


  uint64 balanceE8;//available amount for trading


  uint64 pendingWithdrawE8;//the amount to be transferred out from this contract to the trader


  }


  struct Order{


  uint32 pairId;//<cashId>(16)<stockId>(16)


  uint8 action;//0 means BUY;1 means SELL


  uint8 ioc;//0 means a regular order;1 means an immediate-or-cancel(IOC)order


  uint64 priceE8;


  uint64 amountE8;


  uint64 expireTimeSec;


  }


  struct Deposit{


  address traderAddr;


  uint16 tokenCode;


  uint64 pendingAmountE8;//amount to be confirmed for trading purpose


  }


  struct DealInfo{


  uint16 stockCode;//stock token code


  uint16 cashCode;//cash token code


  uint64 stockDealAmountE8;


  uint64 cashDealAmountE8;


  }


  struct ExeStatus{


  uint64 logicTimeSec;//logic timestamp for checking order expiration


  uint64 lastOperationIndex;//index of the last executed operation


  }


  uint constant MAX_UINT256=2**256-1;


  uint16 constant MAX_FEE_RATE_E4=60;//upper limit of fee rate is 0.6%(60/1e4)


  //<original ETH amount in Wei>=<DEx amountE8>*<ETH_SCALE_FACTOR>/1e8


  uint64 constant ETH_SCALE_FACTOR=10**18;


  uint8 constant ACTIVE=0;


  uint8 constant CLOSED=2;


  bytes32 constant HASHTYPES=


  keccak256('string title','address market_address','uint64 nonce','uint64 expire_time_sec',


  'uint64 amount_e8','uint64 price_e8','uint8 immediate_or_cancel','uint8 action',


  'uint16 cash_token_code','uint16 stock_token_code');


  address public admin;//admin address,and it cannot be changed


  mapping(uint16=>TokenInfo)public tokens;//mapping of token code to token information


  uint8 public marketStatus;//market status:0-Active;1-Suspended;2-Closed


  uint16 public makerFeeRateE4;//maker fee rate(*10**4)


  uint16 public takerFeeRateE4;//taker fee rate(*10**4)


  uint16 public withdrawFeeRateE4;//withdraw fee rate(*10**4)


  uint64 public lastDepositIndex;//index of the last deposit operation


  ExeStatus public exeStatus;//status of operation execution


  mapping(address=>TraderInfo)public traders;//mapping of trade address to trader information


  mapping(uint176=>TokenAccount)public accounts;//mapping of trader token key to its account information


  mapping(uint224=>Order)public orders;//mapping of order key to order information


  mapping(uint64=>Deposit)public deposits;//mapping of deposit index to deposit information


合约交易系统开发(开发案例)丨合约交易所系统开发(逻辑方案)/设计程序/成熟源码的评论 (共 条)

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