Skip to content

Commit

Permalink
support of Rink-xDAi MOONs and BRICKs extesnsion added
Browse files Browse the repository at this point in the history
  • Loading branch information
akolotov committed May 30, 2021
1 parent 2211adf commit 939a672
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 30 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
db
.env
docker-compose.yml.example
docker-compose.yml
.git
.ipynb_checkpoints
.ipynb_checkpoints
README.md
42 changes: 16 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This service is monitoring transfers executed through the OmniBridge on the xDai
3. Run the service

```bash
docker run -ti --rm -v $(pwd)/db:/db --env-file .env omnibridge/bridge-faucet:latest
docker run -ti --rm -v $(pwd)/db:/db --env-file .env omnibridge/faucet:latest
```

_Note:_ the source mount point after the key `-v` is the directory created on the step 2. The destination mount point is the directory specified in the variable `JSON_DB_DIR`.
Expand Down Expand Up @@ -53,28 +53,18 @@ This service is monitoring transfers executed through the OmniBridge on the xDai

The following environment variables may be used to configure the faucet behavior:

1. `XDAI_RPC` -- JSON RPC endpoint the faucet uses to monitor OB events and get data. **Default:** `https://xdai.poanetwork.dev`.

2. `BSC_OB` -- an address of BSC-xDai OB mediator on the xDai side. **Default:** `0x59447362798334d3485c64D1e4870Fde2DDC0d75`.

3. `ETH_OB` -- an address of ETH-xDai OB mediator on the xDai side. **Default:** `0xf6A78083ca3e2a662D6dd1703c939c8aCE2e268d`.

4. `FAUCET_PRIVKEY` -- a private key of an account holding xdai to reward. **No default value!**.

5. `GAS_PRICE` -- the gas price (in gwei) the faucet uses for reward transactions. **Default:** `1`.

6. `GAS_LIMIT` -- the gas limit the faucet uses for reward transactions. **Default:** `30000`.

7. `REWARD` -- amount of xdai used as reward. **Default:** `0.005`.

8. `POLLING_INTERVAL` -- amount of time (in seconds) between two subsequent cycles to discover OB transfers and send rewards. **Default:** `60`.

9. `INITIAL_START_BLOCK` -- a block the first faucet's attempt to discover OB transfers starts from. **No default value!**.

10. `FINALIZATION_INTERVAL` -- a number of blocks starting from the chain head to consider the chain as finalized. **Default:** `12`.

11. `JSON_DB_DIR` -- a directory where the faucet service keeps its data. **No default value!**.

12. `JSON_START_BLOCK` -- a name of JSON file where the last observed block is stored. **Default:** `faucet_start_block.json`.

13. `JSON_CONTRACTS` -- a name of JSON file where addresses of recipient-contracts are stored. **Default:** `xdai-contracts.json`.
1. `XDAI_RPC` - JSON RPC endpoint the faucet uses to monitor OB events and get data. **Default:** `https://xdai.poanetwork.dev`.
2. `BSC_OB` - an address of BSC-xDai OB mediator on the xDai side. **Default:** `0x59447362798334d3485c64D1e4870Fde2DDC0d75`.
3. `ETH_OB` - an address of ETH-xDai OB mediator on the xDai side. **Default:** `0xf6A78083ca3e2a662D6dd1703c939c8aCE2e268d`.
4. `MOONS_EXT` - an address of Rinkeby-xDai ERC20-to-ERC677 mediator for MOONs tokens on the xDai side. **Default:** `0x1E0507046130c31DEb20EC2f870ad070Ff266079`.
5. `BRICKS_EXT` - an address of Rinkeby-xDai ERC20-to-ERC677 mediator for BRICKs tokens on the xDai side. **Default:** `0xf85b17E64Bc788D0CB1A8c8C87c0d74e520c2A54`.
6. `FAUCET_PRIVKEY` - a private key of an account holding xdai to reward. **No default value!**.
7. `GAS_PRICE` - the gas price (in gwei) the faucet uses for reward transactions. **Default:** `1`.
8. `GAS_LIMIT` - the gas limit the faucet uses for reward transactions. **Default:** `30000`.
9. `REWARD` - amount of xdai used as reward. **Default:** `0.005`.
10. `POLLING_INTERVAL` - amount of time (in seconds) between two subsequent cycles to discover OB transfers and send rewards. **Default:** `60`.
11. `INITIAL_START_BLOCK` - a block the first faucet's attempt to discover OB transfers starts from. **No default value!**.
12. `FINALIZATION_INTERVAL` - a number of blocks starting from the chain head to consider the chain as finalized. **Default:** `12`.
13. `JSON_DB_DIR` - a directory where the faucet service keeps its data. **No default value!**.
14. `JSON_START_BLOCK` - a name of JSON file where the last observed block is stored. **Default:** `faucet_start_block.json`.
15. `JSON_CONTRACTS` - a name of JSON file where addresses of recipient-contracts are stored. **Default:** `xdai-contracts.json`.
75 changes: 73 additions & 2 deletions bridge-faucet.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
BSC_OB = getenv('BSC_OB', '0x59447362798334d3485c64D1e4870Fde2DDC0d75')
ETH_OB = getenv('ETH_OB', '0xf6A78083ca3e2a662D6dd1703c939c8aCE2e268d')

MOONS_EXT = getenv('MOONS_EXT', '0x1E0507046130c31DEb20EC2f870ad070Ff266079')
BRICKS_EXT = getenv('BRICKS_EXT', '0xf85b17E64Bc788D0CB1A8c8C87c0d74e520c2A54')

FAUCET_PRIVKEY = getenv('FAUCET_PRIVKEY', None)

GAS_PRICE = int(getenv('GAS_PRICE', 1))
Expand Down Expand Up @@ -51,6 +54,8 @@
info(f'XDAI_RPC = {XDAI_RPC}')
info(f'BSC_OB = {BSC_OB}')
info(f'ETH_OB = {ETH_OB}')
info(f'MOONS_EXT = {MOONS_EXT}')
info(f'BRICKS_EXT = {BRICKS_EXT}')
info(f'FAUCET_PRIVKEY = ...')
info(f'GAS_PRICE = {GAS_PRICE}')
info(f'GAS_LIMIT = {GAS_LIMIT}')
Expand Down Expand Up @@ -100,10 +105,42 @@
]
"""

# TokensBridged(address recipient, uint256 value, bytes32 messageId)
EXT_ABI = """
[
{
"type":"event",
"name":"TokensBridged",
"inputs":[
{
"type":"address",
"name":"recipient",
"indexed":true
},
{
"type":"uint256",
"name":"value",
"indexed":false
},
{
"type":"bytes32",
"name":"messageId",
"indexed":true
}
],
"anonymous":false
}
]
"""

xdai_w3 = Web3(HTTPProvider(XDAI_RPC))

bsc_ob = xdai_w3.eth.contract(abi = ABI, address = BSC_OB)
eth_ob = xdai_w3.eth.contract(abi = ABI, address = ETH_OB)

moons_mediator = xdai_w3.eth.contract(abi = EXT_ABI, address = MOONS_EXT)
bricks_mediator = xdai_w3.eth.contract(abi = EXT_ABI, address = BRICKS_EXT)

faucet = Account.privateKeyToAccount(FAUCET_PRIVKEY)

try:
Expand Down Expand Up @@ -138,7 +175,7 @@
'address': filter.address,
'topics': filter.topics})
except:
raise BaseException('Cannot get BSC-xDAI OB OB logs')
raise BaseException('Cannot get BSC-xDAI OB logs')
info(f'Found {len(bsc_logs)} TokensBridged events on BSC-xDAI OB')

filter = eth_ob.events.TokensBridged.build_filter()
Expand All @@ -149,9 +186,31 @@
'address': filter.address,
'topics': filter.topics})
except:
raise BaseException('Cannot get ETH-xDAI OB OB logs')
raise BaseException('Cannot get ETH-xDAI OB logs')
info(f'Found {len(eth_logs)} TokensBridged events on ETH-xDAI OB')

filter = moons_mediator.events.TokensBridged.build_filter()
info(f'Looking for TokensBridged events on MOONs extension from {start_block} to {last_block}')
try:
moons_logs = xdai_w3.eth.getLogs({'fromBlock': start_block,
'toBlock': last_block,
'address': filter.address,
'topics': filter.topics})
except:
raise BaseException('Cannot get MOONs extension logs')
info(f'Found {len(moons_logs)} TokensBridged events on MOONs extension')

filter = bricks_mediator.events.TokensBridged.build_filter()
info(f'Looking for TokensBridged events on BRICKs extension from {start_block} to {last_block}')
try:
bricks_logs = xdai_w3.eth.getLogs({'fromBlock': start_block,
'toBlock': last_block,
'address': filter.address,
'topics': filter.topics})
except:
raise BaseException('Cannot get BRICKs extension logs')
info(f'Found {len(bricks_logs)} TokensBridged events on BRICKs extension')

recipients = set()

for log in bsc_logs:
Expand All @@ -165,6 +224,18 @@
recipients.add(recipient)
info(f'Identified {len(recipients) - tmp} tokens recipients from ETH-xDAI OB events')

tmp = len(recipients)
for log in moons_logs:
recipient = moons_mediator.events.TokensBridged().processLog(log).args.recipient
recipients.add(recipient)
info(f'Identified {len(recipients) - tmp} tokens recipients from MOONs extension events')

tmp = len(recipients)
for log in bricks_logs:
recipient = bricks_mediator.events.TokensBridged().processLog(log).args.recipient
recipients.add(recipient)
info(f'Identified {len(recipients) - tmp} tokens recipients from BRICKs extension events')

try:
with open(f'{JSON_DB_DIR}/{JSON_CONTRACTS}') as f:
contracts = load(f)
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.9"

services:
faucet:
image: omnibridge/bridge-faucet:latest
image: omnibridge/faucet:latest
container_name: bridge-faucet
environment:
# faucet account's private key must be here (without 0x)
Expand Down

0 comments on commit 939a672

Please sign in to comment.