Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More docs #65

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added doc/bridge/PolyBridge.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/bridge/PolyCrossChain.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions doc/bridge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
### Poly Bridge Overview


<div align=center><img width="700" src="PolyBridge.jpg"/></div>
<div align=center>Poly Bridge</div>


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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1|pendding
1|pending

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)


<div align=center><img width="800"src="PolyCrossChain.jpg"/></div>
<div align=center>Poly Cross Chain</div>


30 changes: 30 additions & 0 deletions doc/bridge/deployment_overview.md
Original file line number Diff line number Diff line change
@@ -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



27 changes: 27 additions & 0 deletions doc/bridge/effect_listen.md
Original file line number Diff line number Diff line change
@@ -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.



109 changes: 109 additions & 0 deletions doc/bridge/ethereum.md
Original file line number Diff line number Diff line change
@@ -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)


























11 changes: 11 additions & 0 deletions doc/bridge/fee_listen.md
Original file line number Diff line number Diff line change
@@ -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.
112 changes: 112 additions & 0 deletions doc/bridge/neo.md
Original file line number Diff line number Diff line change
@@ -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


























Loading