Skip to content

Commit

Permalink
Merge release v0.1.0 from develop to master (zenon-network#36)
Browse files Browse the repository at this point in the history
* Release v0.1.0 (zenon-network#34)

* Escape metadata string variables

* Fix linux metadata script

* Special char test ~!@#$%^&*()_+`-=:";'\|[]{}<>?,./

* Change metadata script with sed cmd

* Special char test ~`!@#$%^&*()_+-={}[]:;"'<>?,./|\

* Fix metadata ps script function on top

* Special char test ~`!@#$%^&*()_+-={}[]:;"'<>?,./|\

* Fix metadata scripts using raw strings

* Char test `~!@#$%^&*\t()_+-={}[]:";'|\<>?,./

* Fix metadata macos script

* Char test `~!@#$%^&*\t()_+-={}[]:";'|\<>?,./

* Char test `~!@#$%^&*\t()_+-={}[]:";'|\<>?,./

* Char test `~!@#$%^&*\t()_+-={}[]:";'|\<>?,./

* Char test `~!@#$%^&*\t()_+-={}[]:";'|\<>?,./

* Char test `~!@#$%^&*\t()_+-={}[]:";'|\<>?,./

* Fix pubspec

* Restore pubspec

* Fix failing build and release workflow (zenon-network#7)

The build and release workflow uses the latest Flutter SDK version that is available on the stable channel. The current codebase is not compatible with Flutter SDK versions 3.10.0 and newer, so the Flutter version must be constrained in the build and release workflow.

* [cicd] Release on tags

* [cicd] Fix tag releases lib-builder

* Updated native libraries

* [cicd] Make lib-builder only trigger manually

* [cicd] Fix SYRIUS_VERSION

* Updated native libraries

* Fix realtime statistics refresh (zenon-network#9)

* Implement P2P swaps for ZTS tokens (zenon-network#11)

* Set state when beneficiary address changes

* Fix realtime statistics refresh (2) (zenon-network#17)

* Adjust P2P swap expiration times (zenon-network#21)

* Update P2P swap card descriptions (zenon-network#20)

* Enable P2P swap UI on mainnet (zenon-network#22)

* Add warning banner onto the P2P swap page (zenon-network#23)

* Check for local time discrepancy when entering the P2P swap tab (zenon-network#25)

* Add hash back to auto-receive tx queue on all exceptions (zenon-network#24)

* Enable wakelock and disable auto-lock when incoming swap is active (zenon-network#19)

* Fix auto receive queue logic (zenon-network#27)

* Filter on all owned projects (zenon-network#10)

* Update README.md badges for hypercore-one

Signed-off-by: georgezgeorgez <[email protected]>

* Make P2P swap related duration constants global and improve the expiration times configuration (zenon-network#29)

* Call setState when updating the swap completed text (zenon-network#30)

* Improve the logic of the auto unlock worker (zenon-network#32)

* Prevent the same hash from being added twice into the auto receive tx pool (zenon-network#31)

* Prevent the same hash from being added twice into the auto receive tx pool

* Add comment to addHash function

* Integrate changes from master (zenon-network#36)

* Feat: Add deep linking - syrius://

* Update main_app_container.dart

* fix: MacOS deep link support

* Feat: Add UI for Wallet Connect

* feat: Enable pairing with dApps through WC

* chore: Add namespaces and more listeners

* Replace bodyText1 with bodyLarge

* fix: Change WC initialization

* chore: Update gitignore

* chore: Update repo after gitignore update

* feat: Add method that activates the pairing

* feat: Add feature that captures a part of the screen and listens to the clipboard

* feat: Build table that shows the current pairings

* feat: Add feature to scan the QR code from the screen

* fix: Remove Expanded widget from Pairings card widget tree

* feat: Listens to values in the clipboard in order to check for WC URI

* fix: Make access check for MacOS before scanning screen

* feat: Redirect to WC tab when a WC URI is detected

* fix: Rebuild WC URI input field when another URI is detected in the clipboard

* Updated native libraries

* fix: Recreate the windows folder

* feat: Add code that opens the app through deep linking

* refactor: Change API call when activating a pairing

* feat: Add possibility to deactivate a WC pair

* feat: Redirect to WC tab when opening the wallet through WC deep linking

* fix: Error initializing the WC uri input field

* feat: Improve validating the WC URI

* feat: Add handler for znn_net_info WC method

* feat: Add handler for znn_sign WC method

* refactor: Create function for signing with the key pair from the wallet file

* feat: Add handler for WC znn_send method

* feat: Change name of znn_net_info method to znn_info and refactor sending a block

* fix: Restyle the Topic column from the WC pairings table

* feat: Send back an account block to the dApp after executing the znn_send method

* feat: Send events to the dApp when the address or chain id were changed

* feat: Send error to the dApp when user rejects the transfer

* fix: Change the error type send to the dApp

* feat: Add confirmation dialogs before making an action sent from the dApp

* refactor

* feat: Fix dialog when dApp wants to send a tx

* fix: Reset the URI value from the change notifier once it's used

* fix: Don't redirect to WC when detecting a WC URI if the wallet is locked

* fix: Show WC URI detected notification if the user is already on the WC tab

* feat: Throw an error when trying to trigger an action through WC and wallet is locked

* feat: Reconnect to websocket when WC connection falls

* feat: Add methods to retrieve the active sessions and all sessions

* feat: Get the reference for getting the ZNN SDK

* feat: Change position of the WC Connect button and disable it in case the input is not valid

* refactor: Delete unused method

* feat: Send notification when user cancels the QR scanning

* feat: Keep the WC URI in memory when wallet is locked

* feat: Update WalletConnectPairingCard with the needed permissions

* feat: Update files

* feat: Wrap up WC

* fix: Clean up

* feat: Get WC project id from environment variable

* fix: Rebuild 'Connect' button when the URI input field is also rebuild

* feat: Rebuild pubspec.lock

* feat: Change the source of the ZNN SDK

* build: referenced wallet-connect sdk branch

* build: added required macos entitlements

* refactor: small refactor

* docs: updated README

* cicd: retrieve WALLET_CONNECT_PROJECT_ID

* cicd: added environment name

* cicd: updated flutter-action

* cicd: set linux directory permissions

* feat: added BigInt support

* fix: referenced latest SDK changes

* fix: desktop window

* fix: windows desktop window

* fix: bigInt decimal conversions

* chore: updated dependencies

* fix: tokenSymbol widget

* fix: minor UI fixes

* cicd: hardcoded flutter version for compatibility

* feat: Change caching the active sessions for a pairing

* fix: allow any ZTS in znn_send

* feat: added WalletConnect events

* fix: remove relayClient reconnect

* feat: Add widget for pairing session data

* feat: Tweak WC pairing flow

* fix: Emit the session event (address and chain id events) to each dApp with an active pair and session

* fix: add windows directory

* chore: update walletconnect_flutter_v2 to v2.0.4

* fix: BigInt fixes

* feat: Regenerate windows folder

* feat: Regenerate windows folder

* feat: Refresh WC URI input field after pairing

* feat: error notification for auto-receive

* chore: updated walletconnect_flutter_v2 to v2.0.6

* feat: Build WC uri card

* feat: Build WC QR card

* feat: Build WC camera card

* feat: Put the pairings and sessions widgets side by side

* feat: Change button name

* fix: flutter windows directory

* chore: update uni_links_desktop to v0.1.6

* fix: windows deep link handling

* feat: added notification for incoming links

* feat: Refresh pairing and session lists when connecting to dApp

* feat: Align pairing and session list widgets on top of each other

* refactor: Add the getter pairings to the WalletConnectService class

* feat: replaced uni_links with app_links

* fix: Revert changes to the pairing list widget

* fix: Make InfiniteScrollBloc handle case when the data request is not paginated

* fix: Don't dispose the pairings and sessions bloc

* fix: Also refresh sessions list after deleting a pairing

* fix: Check for broken WC URI

* fix: added refresh for onPairingCreate

* fix: Redirect to WC tab when an WC URI is detected while the wallet is locked

* fix: Don't cache results for blocs that don't handle paginated results

* fix: Decode WC URI before parsing

* feat: Upgrade project to Dart 3.0.1

* feat: Delete button that disconnects the WC session with the dApp

* feat: Throw error if trying to send tx from dApp while wallet is locked

* cicd: upgraded flutter to v3.10.2

* chore: update texts

* feat: Update WC dependency to 2.0.8

* fix: parse WalletConnect URI

* fix: Dart lint warnings

* feat: bump version to v0.0.7

* fix: Windows deep link

* Updated native libraries

* feat: Hard code chainId to 1 for WC

* fix: WalletConnect improvements

* fix: When to mark last page of the infinite scroll bloc

* fix: dialog navigator pop

* fix: added marquee for token balance

* feat: logging to disk

* refactor: renamed votePillar to delegateToPillar

* fix: WalletConnect issues

* feat: programmatically display WalletConnect tab

* feat: added deep link actions

* feat: update defaultValue for kWcProjectId

* chore: updated walletconnect_flutter_v2 to v2.0.12

* chore: update dependencies

* feat: added camera QR scanning for MacOS

* fix: WakelockPlus Linux support

* fix: replaced logger with Logger

* chore: added descriptions and code cleanup

* fix: wallet_connect_tab_child  import

* fix: minimum amount to send

* fix: refresh WalletConnectSessionsBloc

* fix: remainingZnnBudget decimals

* fix: onSessionDelete refresh

* Integrate changes from master with P2P swaps

---------

Co-authored-by: mik3mast3rs <[email protected]>
Co-authored-by: Alien Coder <[email protected]>
Co-authored-by: Github Actions <[email protected]>
Co-authored-by: Interstellar Traveler <[email protected]>

* Verify the uniqueness of the hashlock when joining a swap (zenon-network#37)

* Add option to delete swap history (zenon-network#38)

* Remove P2P swap warning banner and add a warning modal (zenon-network#41)

* Add deposit recovery feature (zenon-network#40)

* Add width constraints to shown amounts and token symbols (zenon-network#39)

* Add width constraints to shown amounts and token symbols

* Decrease P2P swap list item's max text width to prevent overflow

* Refactor swap expiration warnings and increase counter HTLC expiration time (zenon-network#42)

Signed-off-by: vilkris <[email protected]>

* Fix workflow file issues caused by upstream changes (zenon-network#44)

* Remove bridge tab and related widgets (zenon-network#43)

* Add link to P2P swap tutorial (zenon-network#45)

* Update pubspec.lock to latest ZNN SDK version

* Update version numbers and Git commit date format (zenon-network#46)

* Fix the extractDecimals extension method to handle zero decimals (zenon-network#47)

* Fix ExchangeRateWidget's rate calculation (zenon-network#48)

* Add documentation for how P2P swaps work (zenon-network#49)

* Add documentation for how P2P swaps work

* Add a note of the used hash function to the documentation

* fix: enabled transfers for minimum zts amount

* Fix typo in bullet point card (zenon-network#53)

* Merge master branch into develop (zenon-network#54)

* Feat: Add deep linking - syrius://

* Update main_app_container.dart

* fix: MacOS deep link support

* Feat: Add UI for Wallet Connect

* feat: Enable pairing with dApps through WC

* chore: Add namespaces and more listeners

* Replace bodyText1 with bodyLarge

* fix: Change WC initialization

* chore: Update gitignore

* chore: Update repo after gitignore update

* feat: Add method that activates the pairing

* feat: Add feature that captures a part of the screen and listens to the clipboard

* feat: Build table that shows the current pairings

* feat: Add feature to scan the QR code from the screen

* fix: Remove Expanded widget from Pairings card widget tree

* feat: Listens to values in the clipboard in order to check for WC URI

* fix: Make access check for MacOS before scanning screen

* feat: Redirect to WC tab when a WC URI is detected

* fix: Rebuild WC URI input field when another URI is detected in the clipboard

* Updated native libraries

* fix: Recreate the windows folder

* feat: Add code that opens the app through deep linking

* refactor: Change API call when activating a pairing

* feat: Add possibility to deactivate a WC pair

* feat: Redirect to WC tab when opening the wallet through WC deep linking

* fix: Error initializing the WC uri input field

* feat: Improve validating the WC URI

* feat: Add handler for znn_net_info WC method

* feat: Add handler for znn_sign WC method

* refactor: Create function for signing with the key pair from the wallet file

* feat: Add handler for WC znn_send method

* feat: Change name of znn_net_info method to znn_info and refactor sending a block

* fix: Restyle the Topic column from the WC pairings table

* feat: Send back an account block to the dApp after executing the znn_send method

* feat: Send events to the dApp when the address or chain id were changed

* feat: Send error to the dApp when user rejects the transfer

* fix: Change the error type send to the dApp

* feat: Add confirmation dialogs before making an action sent from the dApp

* refactor

* feat: Fix dialog when dApp wants to send a tx

* fix: Reset the URI value from the change notifier once it's used

* fix: Don't redirect to WC when detecting a WC URI if the wallet is locked

* fix: Show WC URI detected notification if the user is already on the WC tab

* feat: Throw an error when trying to trigger an action through WC and wallet is locked

* feat: Reconnect to websocket when WC connection falls

* feat: Add methods to retrieve the active sessions and all sessions

* feat: Get the reference for getting the ZNN SDK

* feat: Change position of the WC Connect button and disable it in case the input is not valid

* refactor: Delete unused method

* feat: Send notification when user cancels the QR scanning

* feat: Keep the WC URI in memory when wallet is locked

* feat: Update WalletConnectPairingCard with the needed permissions

* feat: Update files

* feat: Wrap up WC

* fix: Clean up

* feat: Get WC project id from environment variable

* fix: Rebuild 'Connect' button when the URI input field is also rebuild

* feat: Rebuild pubspec.lock

* feat: Change the source of the ZNN SDK

* build: referenced wallet-connect sdk branch

* build: added required macos entitlements

* refactor: small refactor

* docs: updated README

* cicd: retrieve WALLET_CONNECT_PROJECT_ID

* cicd: added environment name

* cicd: updated flutter-action

* cicd: set linux directory permissions

* feat: added BigInt support

* fix: referenced latest SDK changes

* fix: desktop window

* fix: windows desktop window

* fix: bigInt decimal conversions

* chore: updated dependencies

* fix: tokenSymbol widget

* fix: minor UI fixes

* cicd: hardcoded flutter version for compatibility

* feat: Change caching the active sessions for a pairing

* fix: allow any ZTS in znn_send

* feat: added WalletConnect events

* fix: remove relayClient reconnect

* feat: Add widget for pairing session data

* feat: Tweak WC pairing flow

* fix: Emit the session event (address and chain id events) to each dApp with an active pair and session

* fix: add windows directory

* chore: update walletconnect_flutter_v2 to v2.0.4

* fix: BigInt fixes

* feat: Regenerate windows folder

* feat: Regenerate windows folder

* feat: Refresh WC URI input field after pairing

* feat: error notification for auto-receive

* chore: updated walletconnect_flutter_v2 to v2.0.6

* feat: Build WC uri card

* feat: Build WC QR card

* feat: Build WC camera card

* feat: Put the pairings and sessions widgets side by side

* feat: Change button name

* fix: flutter windows directory

* chore: update uni_links_desktop to v0.1.6

* fix: windows deep link handling

* feat: added notification for incoming links

* feat: Refresh pairing and session lists when connecting to dApp

* feat: Align pairing and session list widgets on top of each other

* refactor: Add the getter pairings to the WalletConnectService class

* feat: replaced uni_links with app_links

* fix: Revert changes to the pairing list widget

* fix: Make InfiniteScrollBloc handle case when the data request is not paginated

* fix: Don't dispose the pairings and sessions bloc

* fix: Also refresh sessions list after deleting a pairing

* fix: Check for broken WC URI

* fix: added refresh for onPairingCreate

* fix: Redirect to WC tab when an WC URI is detected while the wallet is locked

* fix: Don't cache results for blocs that don't handle paginated results

* fix: Decode WC URI before parsing

* feat: Upgrade project to Dart 3.0.1

* feat: Delete button that disconnects the WC session with the dApp

* feat: Throw error if trying to send tx from dApp while wallet is locked

* cicd: upgraded flutter to v3.10.2

* chore: update texts

* feat: Update WC dependency to 2.0.8

* fix: parse WalletConnect URI

* fix: Dart lint warnings

* feat: bump version to v0.0.7

* fix: Windows deep link

* Updated native libraries

* feat: Hard code chainId to 1 for WC

* fix: WalletConnect improvements

* fix: When to mark last page of the infinite scroll bloc

* fix: dialog navigator pop

* fix: added marquee for token balance

* feat: logging to disk

* refactor: renamed votePillar to delegateToPillar

* fix: WalletConnect issues

* feat: programmatically display WalletConnect tab

* feat: added deep link actions

* feat: update defaultValue for kWcProjectId

* chore: updated walletconnect_flutter_v2 to v2.0.12

* chore: update dependencies

* feat: added camera QR scanning for MacOS

* fix: WakelockPlus Linux support

* fix: replaced logger with Logger

* chore: added descriptions and code cleanup

* fix: wallet_connect_tab_child  import

* fix: minimum amount to send

* fix: refresh WalletConnectSessionsBloc

* fix: remainingZnnBudget decimals

* fix: onSessionDelete refresh

* v0.0.7 -  BigInt support & WalletConnect implementation

* BigInt support & WalletConnect implementation
* Embedded node update: libznn libraries will mitigate the fork at height 5094735

---------

Co-authored-by: Github Actions <[email protected]>

* fix: enabled transfers for minimum zts amount (zenon-network#32)

---------

Co-authored-by: mik3mast3rs <[email protected]>
Co-authored-by: Alien Coder <[email protected]>
Co-authored-by: Github Actions <[email protected]>
Co-authored-by: Interstellar Traveler <[email protected]>
Co-authored-by: Sol Sanctum <[email protected]>

* Fix local time discrepancy warning with remote node

* Fix linter warning

* Update README.md badges for zenon network (zenon-network#55)

* Update ZNN SDK dependency to use Zenon Network repository (zenon-network#56)

---------

Signed-off-by: georgezgeorgez <[email protected]>
Signed-off-by: vilkris <[email protected]>
Co-authored-by: CryptoFish <[email protected]>
Co-authored-by: georgezgeorgez <[email protected]>
Co-authored-by: Github Actions <[email protected]>
Co-authored-by: CryptoFish <[email protected]>
Co-authored-by: Sol Sanctum <[email protected]>
Co-authored-by: mik3mast3rs <[email protected]>
Co-authored-by: Alien Coder <[email protected]>
Co-authored-by: Interstellar Traveler <[email protected]>

* Update libznn binaries to latest version (zenon-network#35)

---------

Signed-off-by: georgezgeorgez <[email protected]>
Signed-off-by: vilkris <[email protected]>
Co-authored-by: CryptoFish <[email protected]>
Co-authored-by: georgezgeorgez <[email protected]>
Co-authored-by: Github Actions <[email protected]>
Co-authored-by: CryptoFish <[email protected]>
Co-authored-by: Sol Sanctum <[email protected]>
Co-authored-by: mik3mast3rs <[email protected]>
Co-authored-by: Alien Coder <[email protected]>
Co-authored-by: Interstellar Traveler <[email protected]>
  • Loading branch information
9 people authored Oct 1, 2023
1 parent 8fec856 commit 267950f
Show file tree
Hide file tree
Showing 90 changed files with 5,553 additions and 595 deletions.
34 changes: 16 additions & 18 deletions .github/workflows/syrius_builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ name: Build and release syrius
on:
push:
branches-ignore:
- master
pull_request:
branches:
- dev
# Allows you to run this workflow manually from the Actions tab
- master
tags:
- '*'
workflow_dispatch:

env:
FLUTTER_VERSION: "3.10.x"

jobs:
build-macos:
environment: wallet-connect
env:
WALLET_CONNECT_PROJECT_ID: ${{ secrets.WC_PROJECT_ID }}
runs-on: macos-12
Expand All @@ -28,8 +28,8 @@ jobs:
- name: Setup Flutter
uses: subosito/[email protected]
with:
flutter-version: ${{env.FLUTTER_VERSION}}
channel: "stable"
flutter-version: "3.10.2"
- name: Check flutter version
run: flutter --version
- name: Build syrius desktop
Expand Down Expand Up @@ -57,7 +57,6 @@ jobs:
name: macos-artifacts
path: syrius-alphanet-macos-universal.dmg
build-windows:
environment: wallet-connect
env:
WALLET_CONNECT_PROJECT_ID: ${{ secrets.WC_PROJECT_ID }}
runs-on: windows-latest
Expand All @@ -67,8 +66,8 @@ jobs:
- name: Setup Flutter
uses: subosito/[email protected]
with:
flutter-version: ${{env.FLUTTER_VERSION}}
channel: "stable"
flutter-version: "3.10.2"
- name: Check flutter version
run: flutter --version
- name: Build syrius desktop
Expand All @@ -84,7 +83,6 @@ jobs:
name: windows-artifacts
path: syrius-alphanet-windows-amd64.zip
build-linux:
environment: wallet-connect
env:
WALLET_CONNECT_PROJECT_ID: ${{ secrets.WC_PROJECT_ID }}
runs-on: ubuntu-20.04
Expand All @@ -98,8 +96,8 @@ jobs:
- name: Setup Flutter
uses: subosito/[email protected]
with:
flutter-version: ${{env.FLUTTER_VERSION}}
channel: "stable"
flutter-version: "3.10.2"
- name: Set permissions
run: |
sudo chmod -R 777 linux/
Expand All @@ -123,19 +121,18 @@ jobs:
make-release:
needs: [build-macos, build-windows, build-linux]
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set variables
run: |
SYRIUS="v$(cat pubspec.yaml | grep version | sed 's/version://' | xargs)"
echo "Syrius Version: $SYRIUS"
echo "SYRIUS_VERSION=$SYRIUS" >> $GITHUB_ENV
echo "SYRIUS_VERSION=${{ github.ref }}" >> $GITHUB_ENV
echo "Syrius Version: $SYRIUS_VERSION"
GOZENON=$(curl -s https://raw.githubusercontent.com/zenon-network/go-zenon/master/metadata/version.go | grep Version | awk -F '"' '{print $2}')
echo "Go-Zenon Version: $GOZENON"
BODY=$(cat <<EOF
Syrius $SYRIUS features the pre-release version of the [go-zenon](https://github.com/zenon-network/go-zenon) $GOZENON full node.
Syrius $SYRIUS_VERSION features the pre-release version of the [go-zenon](https://github.com/zenon-network/go-zenon) $GOZENON full node.
Syrius for Windows requires Microsoft Visual C++ to be installed.
[Download Microsoft Visual C++](https://aka.ms/vs/16/release/vc_redist.x64.exe)
Expand Down Expand Up @@ -180,9 +177,10 @@ jobs:
uses: svenstaro/[email protected]
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: releases/*
release_name: ${{ env.SYRIUS_VERSION }}
tag: ${{ env.SYRIUS_VERSION }}-alphanet
prerelease: ${{ contains(env.SYRIUS_VERSION, '-') }}
tag: ${{ env.SYRIUS_VERSION }}
file_glob: true
file: releases/*
overwrite: true
body: ${{ env.BODY }}
7 changes: 0 additions & 7 deletions .github/workflows/syrius_lib_updater.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
name: Library updater for syrius

on:
push:
branches-ignore:
- master
pull_request:
branches:
- dev
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# s y r i u s

[![Build and release syrius](https://github.com/zenon-network/syrius/actions/workflows/syrius_builder.yml/badge.svg?branch=cicd)](https://github.com/zenon-network/syrius/actions/workflows/syrius_builder.yml) [![Library updater for syrius](https://github.com/zenon-network/syrius/actions/workflows/syrius_lib_updater.yml/badge.svg?branch=cicd)](https://github.com/zenon-network/syrius/actions/workflows/syrius_lib_updater.yml)
[![Build and release syrius](https://github.com/zenon-network/syrius/actions/workflows/syrius_builder.yml/badge.svg?branch=develop)](https://github.com/zenon-network/syrius/actions/workflows/syrius_builder.yml) [![Library updater for syrius](https://github.com/zenon-network/syrius/actions/workflows/syrius_lib_updater.yml/badge.svg?branch=develop)](https://github.com/zenon-network/syrius/actions/workflows/syrius_lib_updater.yml)

Cross-platform non-custodial wallet designed for Alphanet - Network of Momentum Phase 0.

Expand Down
4 changes: 4 additions & 0 deletions assets/svg/ic_completed_symbol.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/svg/ic_unsuccessful_symbol.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
110 changes: 110 additions & 0 deletions docs/p2p_swaps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# P2P Swaps in Syrius

The P2P Swap feature in Syrius offers users an easy and censorship resistant way of exchanging value, peer-to-peer, without intermediaries on Network of Momentum. With no fees, users can trade any ZTS token with any counterparty.

P2P Swaps use HTLCs to facilitate the swaps.

## Conducting a P2P Swap in Syrius
P2P Swaps have two parties, the starting party and the joining party. The two parties will first have to find each other (in a chatroom for example) and agree upon the amounts they want to swap. After this, they can use Syrius to conduct a trustless swap with no fees directly with each other.

### Example

Alice is the starting party for the swap and she wants to swap 100 ZNN for 1,000 QSR. Bob is the joining party and has agreed to be Alice's counterparty for the swap. Bob has provided Alice with his NoM address.

1. Alice starts a P2P swap in Syrius and deposits 100 ZNN for Bob. She then sends her deposit's ID to Bob via a messaging service (e.g. Telegram).
2. Bob uses the deposit ID to get the swap's details in Syrius and he can see that Alice has deposited 100 ZNN for him.
3. Bob joins the swap by depositing 1,000 QSR for Alice.
4. Alice sees that Bob has deposited the QSR and proceeds to complete the swap. Once Alice completes the swap, she receives 1,000 QSR.
5. Bob's Syrius sees that Alice has completed the swap and Syrius automatically proceeds to unlock the 100 ZNN For Bob.
6. The swap has now been successfuly completed.

The deposits are timelocked, so if either party backs out of the swap before it is completed, both parties can reclaim their deposits.

## Technical overview

The P2P swaps use the embedded HTLC contract to facilitate the swaps with HTLCs. A swap requires two HTLCs - the initial HTLC and the counter HTLC.

The following constants are used for HTLC based P2P swaps in Syrius:

```
kInitialHtlcDuration = Duration(hours: 8)
kCounterHtlcDuration = Duration(hours: 1)
kMaxAllowedInitialHtlcDuration = Duration(hours: 24)
kMinSafeTimeToFindPreimage = Duration(hours: 6)
kMinSafeTimeToCompleteSwap = Duration(minutes: 10)
```

### Starting the swap

When the starting party starts a swap in Syrius, depositing 100 ZNN, an HTLC is created with the following inputs:

```
hashLocked: ${joiningPartyAddress}
expirationTime: ${frontierMomentumTime} + ${kInitialHtlcDuration}
tokenStandard: zts1znnxxxxxxxxxxxxx9z4ulx
amount: 100000000000
hashType: 0
keyMaxSize: 255
hashLock: [A 32-byte hash of a preimage generated by Syrius]
```
The initial HTLC's expiration time is always set to 8 hours into the future. The preimage is stored into an encrypted database locally. Syrius hashes the preimage with the SHA3-256 hash function, so the `hashType` parameter is set to `0`.

### Joining the swap
The joining party has 1 hour to join the swap. The `kMinSafeTimeToFindPreimage` ensures that the joining party will have at least 6 hours to find the swap's preimage. Since the `kCounterHtlcDuration` makes sure that the counter HTLC's duration is 1 hour, the user cannot join the swap if the initial HTLC's time until expiration is less than the combined duration of `kMinSafeTimeToFindPreimage` and `kCounterHtlcDuration`.

Syrius will not allow the user to join a swap if the initial HTLC's duration exceeds the `kMaxAllowedInitialHtlcDuration` constant.

When the joining party joins the swap, depositing 1,000 QSR, an HTLC is created with the following inputs:
```
hashLocked: ${startingPartyAddress}
expirationTime: ${frontierMomentumTime} + ${kCounterHtlcDuration}
tokenStandard: zts1qsrxxxxxxxxxxxxxmrhjll
amount: 1000000000000
hashType: 0
keyMaxSize: 255
hashLock: ${initialHtlcHashlock}
```

In case the joining party does not join the swap, the starting party will have to wait until the initial HTLC expires. After the HTLC has expired, the funds can be reclaimed.

### Completing the swap
After both parties have deposited their funds, the swap can be completed.

#### The starting party

When the starting party completes the swap, the embedded HTLC contract's `Unlock` method is called with the following inputs:
```
id: ${counterHtlcId}
preimage: ${preimageFromLocalStorage}
```

The starting party has 50 minutes to complete the swap. Although the counter HTLCs duration is 1 hour, the unlock transaction sending has to be started at least 10 minutes (`kMinSafeTimeToCompleteSwap`) before the counter HTLC expires. This is to ensure that the transaction has enough time to get published and processed by the network so that the counter HTLC does not expire in between the time the user sends the transaction and the HTLC contract processes the transaction. This could lead to a situation where the preimage is published on-chain, but the starting party doesn't have access to the hashlocked funds anymore.

If the starting party does not complete the swap, both parties will have to wait for their HTLCs to expire to reclaim their funds.

#### The joining party
Once the starting party has unlocked the counter HTLC, the joining party's Syrius will actively monitor the chain to find the preimage the starting party published on chain when calling the HTLC contract's `Unlock` method.

The joining party should keep Syrius running until either the swap is completed, or the counter HTLC expires. This is to ensure that Syrius can find the preimage and unlock the funds deposited to the joining party. If Syrius is closed during this time, the joining party has at least 6 hours (`kMinSafeTimeToFindPreimage`) to reopen Syrius, so that the preimage can be found.

Once the preimage has been found, the embedded HTLC contract's `Unlock` method is automatically called by Syrius with the following inputs:

```
id: ${initialHtlcId}
preimage: ${preimageFoundOnChain}
```

### What if the joining party fails to find the preimage?
If the joining party fails to find the preimage and unlock the initial HTLC before it expires, access to the funds will be lost and the starting party will be able to reclaim the funds.

To reduce the risk of this happening, Syrius enables the computer's wakelock, so that the computer doesn't go into sleep mode while Syrius is monitoring the chain for the preimage after the joining party has joined the swap. Since the counter HTLC's duration is 1 hour, that is the maximum time that the joining party has to stay vigiliant during the swap. If Syrius is not running during this time and the starting party completes the swap, the joining party will have at least 6 hours to reopen Syrius.

[HTLC Watchtowers](https://github.com/hypercore-one/htlc-watchtower) can also be deployed by community members to further reduce the chance of users losing funds.


## The future of P2P swaps
HTLCs are the only way right now to facilitate trustless trading on Network of Momentum, but they are not necessarily the most convenient way to facilitate same chain P2P swaps. Superior ways to facilitate trading will hopefully be available in the future.

The Syrius implementation for P2P swaps has been designed in such a way, that the underlying primitives that the swaps are based upon can be changed, but the experience for the user can remain more or less the same.

While only ZTS to ZTS swaps are currently supported, HTLCs can be used to facilitate cross-chain swaps as well and supporting cross-chain swaps could be a future goal.
6 changes: 3 additions & 3 deletions lib/blocs/accelerator/project_list_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ class ProjectListBloc with RefreshBlocMixin {

/*
This method filters the projects according to the following rule:
if a user doesn't have a Pillar, then we only show him the active
projects
if a user doesn't have a Pillar, only show the active
projects or all owned projects
*/
Future<List<Project>> _filterProjectsAccordingToPillarInfo(
Set<Project> projectList) async {
Expand All @@ -142,7 +142,7 @@ class ProjectListBloc with RefreshBlocMixin {
.where(
(project) =>
project.status == AcceleratorProjectStatus.active ||
project.owner.toString() == kSelectedAddress,
kDefaultAddressList.contains(project.owner.toString()),
)
.toList();
if (activeProjects.isNotEmpty) {
Expand Down
23 changes: 15 additions & 8 deletions lib/blocs/auto_receive_tx_worker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:collection';

import 'package:json_rpc_2/json_rpc_2.dart';
import 'package:logging/logging.dart';
import 'package:zenon_syrius_wallet_flutter/blocs/auto_unlock_htlc_worker.dart';
import 'package:zenon_syrius_wallet_flutter/blocs/blocs.dart';
import 'package:zenon_syrius_wallet_flutter/main.dart';
import 'package:zenon_syrius_wallet_flutter/model/model.dart';
Expand All @@ -14,7 +15,6 @@ import 'package:znn_sdk_dart/znn_sdk_dart.dart';
class AutoReceiveTxWorker extends BaseBloc<WalletNotification> {
static AutoReceiveTxWorker? _instance;
Queue<Hash> pool = Queue<Hash>();
HashSet<Hash> processedHashes = HashSet<Hash>();
bool running = false;

static AutoReceiveTxWorker getInstance() {
Expand All @@ -23,10 +23,11 @@ class AutoReceiveTxWorker extends BaseBloc<WalletNotification> {
}

Future<void> autoReceive() async {
if (pool.isNotEmpty && !running) {
// Make sure that AutoUnlockHtlcWorker is not running since it should be
// given priority to send transactions.
if (pool.isNotEmpty && !running && !sl<AutoUnlockHtlcWorker>().running) {
running = true;
Hash currentHash = pool.first;
pool.removeFirst();
try {
String toAddress =
(await zenon!.ledger.getAccountBlockByHash(currentHash))!
Expand All @@ -45,17 +46,22 @@ class AutoReceiveTxWorker extends BaseBloc<WalletNotification> {
blockSigningKey: keyPair,
waitForRequiredPlasma: true,
);
pool.removeFirst();
_sendSuccessNotification(response, toAddress);
} on RpcException catch (e, stackTrace) {
_sendErrorNotification(e.toString());
Logger('AutoReceiveTxWorker')
.log(Level.WARNING, 'autoReceive', e, stackTrace);
if (e.message.compareTo('account-block from-block already received') !=
if (e.message.compareTo('account-block from-block already received') ==
0) {
pool.addFirst(currentHash);
pool.removeFirst();
} else {
_sendErrorNotification(e.toString());
}
} catch (e, stackTrace) {
Logger('AutoReceiveTxWorker')
.log(Level.WARNING, 'autoReceive', e, stackTrace);
_sendErrorNotification(e.toString());
}
running = false;
}
Expand Down Expand Up @@ -85,15 +91,16 @@ class AutoReceiveTxWorker extends BaseBloc<WalletNotification> {
}

Future<void> addHash(Hash hash) async {
if (!processedHashes.contains(hash)) {
if (!pool.contains(hash)) {
zenon!.stats.syncInfo().then((syncInfo) {
if (!processedHashes.contains(hash) &&
// Verify that the pool does not already contain the hash after the
// asynchronous request has completed and that the node is in sync.
if (!pool.contains(hash) &&
(syncInfo.state == SyncState.syncDone ||
(syncInfo.targetHeight > 0 &&
syncInfo.currentHeight > 0 &&
(syncInfo.targetHeight - syncInfo.currentHeight) < 3))) {
pool.add(hash);
processedHashes.add(hash);
}
});
}
Expand Down
Loading

0 comments on commit 267950f

Please sign in to comment.