diff --git a/doc/bridge/PolyBridge.jpg b/doc/bridge/PolyBridge.jpg new file mode 100644 index 00000000..b20a1c40 Binary files /dev/null and b/doc/bridge/PolyBridge.jpg differ diff --git a/doc/bridge/PolyCrossChain.jpg b/doc/bridge/PolyCrossChain.jpg new file mode 100644 index 00000000..53aecbb8 Binary files /dev/null and b/doc/bridge/PolyCrossChain.jpg differ diff --git a/doc/bridge/README.md b/doc/bridge/README.md new file mode 100644 index 00000000..31c1acb6 --- /dev/null +++ b/doc/bridge/README.md @@ -0,0 +1,69 @@ +### Poly Bridge Overview + + +
+
Poly Bridge
+ + +Poly bridge monitors the target chains, parse the blocks, and find the cross chain transactions, then write into the state database(mysql), with which the bridge server will be able to expose APIs to check cross chain transactions status. + + +For each target chain, the listener process, at a specified interval, check the latest block height from time to time. If a new block is found and added on the chain, the listener will verify if the block get enough confirmations, then parse the block to find the wrapper transactions(ERC20, NFT) and ECCM event(Lock/Unlock Event), then write into the database. + + +Data parsed from the chain blocks include: +##### Wrapper Transaction + +Wrapper transactions (ERC20, NFT, etc), parsed from the blocks will be inserted or updated into the database table with hash the primary key. + +##### Proxy Lock Events + +Proxy lock events indicating a cross chain source transaction has be processed by the source chain relayer, will be inserted or updated into the database table. + +##### Proxy Unlock Events + +Proxy unlock events indicating a cross chain target transaction has be processed by the target chain relayer, will be inserted or updated into the database table. + +##### Poly Transaction + +Poly Transactions happen on the poly chain. Its status will be updated into the database as well to track the cross chain transaction status. + +## HTTP API + +### Transaction Status + +Status Code|Description +:--:|:--: +0|finished +1|pendding +2|source done +3|source confirmed +4|poly confirmed + +### Server Address +* [testnet](https://bridge.poly.network/testnet/v1/) +* [mainnet](https://bridge.poly.network/v1/) + +### Endpoints +* [GET /](#get-/) +* [POST tokens](#post-tokens) +* [POST token](#post-token) +* [POST tokenbasics](#post-tokenbasics) +* [POST tokenmap](#post-tokenmap) +* [POST tokenmapreverse](#post-tokenmapreverse) +* [POST getfee](#post-getfee) +* [POST checkfee](#post-checkfee) +* [POST transactions](#post-transactions) +* [POST transactionsofaddress](#post-transactionsofaddress) +* [POST transactionofhash](#post-transactionofhash) +* [POST transactionsofstate](#post-transactionsofstate) +* [POST transactionofcurve](#post-transactionofcurve) +* [POST transactionsofunfinished](#post-transactionsofunfinished) +* [POST transactionsofasset](#post-transactionsofasset) +* [POST expecttime](#post-expecttime) + + +
+
Poly Cross Chain
+ + diff --git a/doc/bridge/deployment_overview.md b/doc/bridge/deployment_overview.md new file mode 100644 index 00000000..55177419 --- /dev/null +++ b/doc/bridge/deployment_overview.md @@ -0,0 +1,30 @@ +## Dev Deployment Status + +#### Listener +Chain/Role|Node Count +:--:|:--: +Ethereum | 2 +HECO | 2 +BSC | 2 +OK | 2 +ONTOLOGY | 2 +NEO | 2 +POLY | 2 +API | 2 + +fee | 1 +price | 1 +effect | 1(logs -> ops -> dingding) + + +#### Nodes +Env,Role|Node +:--:|:--: +Dev | +Test | +Prod | + +### Poly + + + diff --git a/doc/bridge/effect_listen.md b/doc/bridge/effect_listen.md new file mode 100644 index 00000000..8003169b --- /dev/null +++ b/doc/bridge/effect_listen.md @@ -0,0 +1,27 @@ +## Status Check + +`crosschaineffect` is used to do periodical checks on the processing of cross chain transactions. Some logging will be triggered at bad situations and be monitored by the logging center to trigger alarms in IM channels. + + +#### Update Poly transaction source Hash + +One step is status check is to find the poly transactions with fake source hash, which is emitted from the transaction events before sumbitting to polynetowrk, it will be updated with the real source transaction hash by matching the fake source hash id with the source transaction `key` field. + +#### Transaction status check + +Unfinished cross chain transactions will be regularly checked. + +#### Update cross chain transaction status + +Based on the collected data from chains, the cross chain transaction status will be updated. Normally, the confirmations of wrapper transactions and destination transactions(on target chain) will be verified. + +#### Update average cross chain transction time expense + +The average time expense of cross chain transactions will be updated. + +#### Chain listener status check + +Chain status collected from chains will be used to verify if the listeners are still running. + + + diff --git a/doc/bridge/ethereum.md b/doc/bridge/ethereum.md new file mode 100644 index 00000000..08cf756a --- /dev/null +++ b/doc/bridge/ethereum.md @@ -0,0 +1,109 @@ +## Ethereum(ERC20 and ERC721) Chain Listener + + +With the specified wrapper contract addresses, the ethereum chain listener will monitor the matched emitted contract events to find the desired `PolyWrapperLock` event and `PolyWrapperSpeedUp` event. Currently, two contract addresses were specified for wrapper smart contract with the second will use the cross chain asset as fee instead. The `PolyWrapperSpeedUp ` event will replace the transaction fee with a newer one normally to speed up the process. Besides the contract for asset of type ERC20, the NFT contract was deployed too and to be monitored in a similar way as the ERC20. + +#### Wrapper Transaction + +Field|Description +:--:|:--: +Hash | Txid[2:] +User | event.Sender[2:] +DstChainId | event.ToChainId +DstUser | event.ToAddress +FeeTokenHash| event.FromAsset (Zero for the new version) +FeeAmount | event.Fee +ServerId | event.Id +BlockHeight | block.Height + + +#### CCM transaction + +In a similar way, the proxy lock/unlock event will be collected while listening, for both the ERC20 and NFT contract. In the process, the eccm locked/unlocked events will collected first if matching with the specified the ECCM contract address. + +Source Transaction + +Field|Description +:--:|:--: +ChainId | CurrentChainId +Hash | event.TxHash[2:] +State | 1 +Fee | execution.GasConsumed +Time | block.Time +Height | block.Height +User | event.Sender[2:] +DstChainId | event.ToChainId +Contract | event.ProxyOrAssetContract[2:] +Key | event.TxId +Param | event.RawData +SrcTransfer | srcTransfer +Standard | TokenTypeErc20 or TokenTypeErc721 + +Source Transfer (Proxy lock event) + +Field|Description +:--:|:--: +ChainId | CurrentChainId +TxHash | event.TxHash[2:] +Time | block.Time +From | event.Sender[2:] +To | event.ProxyOrAssetContract[2:] +Asset | eventSrc.FromAssetHash[2:] +Amount | eventSrc.Amount (eventSrc.TokenId for NFT) +DstChainId | eventSrc.ToChainId +DstUser | eventSrc.ToAddress +DstAsset | eventSrc.ToAssetHash + +Destination Transaction + +Field|Description +:--:|:--: +ChainId | CurrentChainId +Hash | event.TxHash[2:] +State | 1 +Fee | execution.GasConsumed +Time | block.Time +Height | block.Height +SrcChainId | event.FromChainId +Contract | event.ToContract +PolyHash | event.CrossChainTxHash +DstTransfer | dstTransfer +Standard | TokenTypeErc20 or TokenTypeErc721 + +Destination Transfer (Proxy unlock event) + +Field|Description +:--:|:--: +ChainId | CurrentChainId +TxHash | event.TxHash[2:] +Time | block.Time +From | event.ToContract +To | eventDst.ToAddress[2:] +Asset | eventDst.ToAssetHash[2:] +Amount | eventDst.Amount(eventDst.TokenId for NFT) + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/bridge/fee_listen.md b/doc/bridge/fee_listen.md new file mode 100644 index 00000000..e7faad1c --- /dev/null +++ b/doc/bridge/fee_listen.md @@ -0,0 +1,11 @@ +## Fee Listener + +Chain suggested fee is monitored for several chains, with the value updated into the database to be used in bridge page for fee suggestions. + +#### Ethereum/HECO/BSC/OK Fee + +Via sdk, the suggested gas price is retrieved, with defined gas limit, the max fee is got. Based on the max fee, the min fee and the proxy fee is calculated. + +#### NEO/Ontology Fee + +Rather than fetching from the chain, the initial gas price is hard coded as 1. \ No newline at end of file diff --git a/doc/bridge/neo.md b/doc/bridge/neo.md new file mode 100644 index 00000000..653762ce --- /dev/null +++ b/doc/bridge/neo.md @@ -0,0 +1,112 @@ +## NEO Chain Listener + + +Neo chain listener will go through the transactions included in the new block, and only check against the transactions with type `InvocationTransaction`. When such a transaction was found, the transaction execution notification will be checked . + +#### Wrapper Transaction +The transaction with execution notification matching the defined wrapper contract and with a valid parsed method(`PolyWrapperLock`) will be treated as a wrapper transaction. + +Field|Description +:--:|:--: +Hash | Txid[2:] +User | notify.State.Value[2].Value +DstChainId | notify.State.Value[3].Value +DstUser | notify.State.Value[4].Value +FeeTokenHash| notify.State.Value[1].Value +FeeAmount | notify.State.Value[6].Value +ServerId | notify.State.Value[7].Value +Status | STATE_SOURCE_DONE +Time | block.Time +BlockHeight | block.Height +SrcChainId | CurrentChainId + + +#### CCM transaction + +If matching the CCM contract, and the parsed method is `CrossChainLockEvent`, the transaction will be treated as a source transaction. + +Field|Description +:--:|:--: +ChainId | CurrentChainId +Hash | Txid[2:] +State | 1 +Fee | execution.GasConsumed +Time | block.Time +Height | block.Height +User | srcTransfer.From +DstChainId | notify.State.Value[3].Value +Contract | notify.State.Value[2].Value +Key | notify.State.Value[4].Value +Param | notify.State.Value[5].Value +SrcTransfer | srcTransfer + +Method `Lock` and `LockEvent` indicate it's a Source Transfer. + +Field|Description +:--:|:--: +ChainId | CurrentChainId +TxHash | Txid[2:] +Time | block.Time +From | notifySrc.State.Value[2].Value +To | notify.State.Value[2].Value +Asset | notifySrc.State.Value[1].Value +Amount | notifySrc.State.Value[6].Value +DstChainId | notifySrc.State.Value[3].Value +DstUser | notifySrc.State.Value[5].Value +DstAsset | notifySrc.State.Value[4].Value + + +If matching the CCM contract, and the parsed method is `CrossChainUnLockEvent`, the transaction will be treated as a destination transaction. + +Field|Description +:--:|:--: +ChainId | CurrentChainId +Hash | Txid[2:] +State | 1 +Fee | execution.GasConsumed +Time | block.Time +Height | block.Height +SrcChainId | notify.State.Value[1].Value +Contract | notify.State.Value[2].Value +PolyHash | notify.State.Value[3].Value +DstTransfer | dstTransfer + + + +Method `Unlock` and `UnlockEvent` indicate it's a Destination Transfer. + +Field|Description +:--:|:--: +ChainId | CurrentChainId +TxHash | TxId[2:] +Time | block.Time +From | notify.State.Value[2].Value +To | notifyDst.State.Value[2].Value +Asset | notifyDst.State.Value[1].Value +Amount | notifyDst.State.Value[3].Value + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/bridge/ontology.md b/doc/bridge/ontology.md new file mode 100644 index 00000000..c3aa71e2 --- /dev/null +++ b/doc/bridge/ontology.md @@ -0,0 +1,112 @@ +## Ontology Chain Listener + + +Ontology chain listener will go through the event notifications emitted in the new block. The specified wrapper contract address and CCM contract address will be used to detect the contract events. The parsed method in the event notification will be used to identify the cross chain transaction type which is one of wrapper transaction, source transaction and destination transaction. + +#### Wrapper Transaction +The transaction with execution notification matching the defined wrapper contract and with a valid parsed method(`PolyWrapperLock`) will be treated as a wrapper transaction. + +Field|Description +:--:|:--: +Hash | event.TxHash +User | notify.State.Value[2].Value +DstChainId | notify.State.Value[3].Value +DstUser | notify.State.Value[4].Value +FeeTokenHash| notify.State.Value[1].Value +FeeAmount | notify.State.Value[6].Value +ServerId | notify.State.Value[7].Value +Status | STATE_SOURCE_DONE +Time | block.Time +BlockHeight | block.Height +SrcChainId | CurrentChainId + + +#### CCM transaction + +If matching the CCM contract, and the parsed method is `makeFromOntProof`, the transaction will be treated as a source transaction. + +Field|Description +:--:|:--: +ChainId | CurrentChainId +Hash | event.TxHash +State | event.State +Fee | event.GasConsumed +Time | block.Time +Height | block.Height +User | srcTransfer.From +DstChainId | notify.State.Value[2].Value +Contract | notify.State.Value[5].Value +Key | notify.State.Value[4].Value +Param | notify.State.Value[6].Value +SrcTransfer | srcTransfer + +Method `lock` indicates it's a Source Transfer. + +Field|Description +:--:|:--: +ChainId | CurrentChainId +TxHash | event.TxHash +Time | block.Time +From | notifySrc.State.Value[2].Value +To | notify.State.Value[5].Value +Asset | notifySrc.State.Value[1].Value +Amount | notifySrc.State.Value[6].Value +DstChainId | notifySrc.State.Value[3].Value +DstUser | notifySrc.State.Value[5].Value +DstAsset | notifySrc.State.Value[4].Value + + +If matching the CCM contract, and the parsed method is `verifyToOntProof`, the transaction will be treated as a destination transaction. + +Field|Description +:--:|:--: +ChainId | CurrentChainId +Hash | event.TxHash +State | event.State +Fee | event.GasConsumed +Time | block.Time +Height | block.Height +SrcChainId | notify.State.Value[3].Value +Contract | notify.State.Value[5].Value +PolyHash | notify.State.Value[1].Value +DstTransfer | dstTransfer + + + +Method `unlock` indicates it's a Destination Transfer. + +Field|Description +:--:|:--: +ChainId | CurrentChainId +TxHash | event.TxHash +Time | block.Time +From | notify.State.Value[5].Value +To | notifyDst.State.Value[2].Value +Asset | notifyDst.State.Value[1].Value +Amount | notifyDst.State.Value[3].Value + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/bridge/poly.md b/doc/bridge/poly.md new file mode 100644 index 00000000..855b649e --- /dev/null +++ b/doc/bridge/poly.md @@ -0,0 +1,18 @@ +## Poly Network Listener + +Poly network listener monitor the poly chain blocks to track the state update of cross chain transactions on the middle chain. + +The smart contract events emitted will be checked one by one. When the contract address matches the defined poly contract address, and the parsed method is either `makeProof` or `btcTxToRelay`, the execution notification will be parsed and recorded. + +Field|Description +:--:|:--: +ChainId | CurrentChainId +Hash | event.TxHash +State | event.State +Fee | 0 +Time | block.Time +Height | block.Height +SrcChainId | notify.States[1] +DstChainId | notify.States[2] +SrcHash | notify.States[3] + diff --git a/doc/bridge/price_listen.md b/doc/bridge/price_listen.md new file mode 100644 index 00000000..0e377df8 --- /dev/null +++ b/doc/bridge/price_listen.md @@ -0,0 +1,6 @@ +## Price Listener +Coin prices are monitored to and updated into the databases. These values will be used to estimate the transaction fee when target chain fee coin differs from the initial fee coin, especially during submitting cross chain transaction on to the target chain. + +#### Coin Markets +The prices source markets includes `coinmarketcap`, `binance` and `self(hosted by ourselves)`. Some coins have multiple prices sources, the average price will be used at this condition. +