Skip to content

Commit

Permalink
Update deploy branch (#88)
Browse files Browse the repository at this point in the history
* Set extrinsicHash as optional

* ISSUE-39: Fee calculation with withdraw (#42)

* Update polkadot api

* Check erasStakersClipped exists

* Update readme and package name

* Set extrinsic hash for stacke change as optional

* Fix failed reward destribution handling

* Adding GitHub Actions for deploy to staging (#63)

* add statemine

Signed-off-by: Stepan Lavrentev <lawrentievsv@gmail.com>

* fix constraint

* ISSUE-51: Assets transfer history

* NOVA_3665: switch <action>.multi to multiQuery (#40)

* ISSUE-39: Fee calculation with withdraw (#42)

* Update polkadot api

* Check erasStakersClipped exists

* Update readme and package name

* Set extrinsic hash as optional

* Custom asset transfer

* first iteration

* fix scripts

* fix

* fix deploy branch

* fix

* Transform assetTransfer to jsonfield

* upgrade polkadot/api to 7

* fix schema

* rename

* update workflows

* Fix for assettransfer checking

* add more networks in list

* add tests for promote to prod

* add new networks

* Fix transfer problem

* fix bifrost and karura

* Add failed transfer all handlers

* add promotion to prod with checks

* add more networks

* add networks and fix

* Don't create receiver history element for transferAll

* temporal --force

* remove --force

* add fix for moonbeam

* fix version for moonriver

* fix shiden

* change acala url

* add new networks

* Merge pull request #77 from nova-wallet/add-evm-hash-support

Add evm hash support

* update moonbeam types

* kusama rewards fix

* Merge pull request #80 from nova-wallet/fix/change-kintsugi-account-type

Fix: change kintsugi account type

* change some parameters for GHA

* Delete robonomics

* Improving Usability of Development

* Add manual deploy workflow

Co-authored-by: asmadek <alma2610@ya.ru>

* ISSUE-85: fix extrinsic creation for evm transactions

* Add configs for networks

* Revert "Add configs for networks"

This reverts commit 7cb93e2.

* Fuxing problems after first iteration (#87)

* update trigger for workflow

* add script to update projects description

* Fix readme

* subsocial types version

* turn off auto deployment

* Prepare to pull request to deploy branch

Co-authored-by: asmadek <alma2610@ya.ru>
Co-authored-by: Stepan Lavrentev <40560660+stepanLav@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Stepan Lavrentev <lawrentievsv@gmail.com>
  • Loading branch information
4 people authored Apr 12, 2022
1 parent eacf557 commit 015ad94
Show file tree
Hide file tree
Showing 95 changed files with 1,653 additions and 220 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/manual_deploy_to_stg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Manual deploy to staging

on:
workflow_dispatch:
inputs:
networks:
description: 'Which networks will deploy?'
required: true
type: string

env:
SUBQUERY_CLI_VERSION: 0.2.5
SUBQUERY_ORG: nova-wallet
INDEXER_IMAGE_VERSION: v0.31.1
QUERY_IMAGE_VERSION: v0.13.0

jobs:

setup:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
run: |
list_elements=(${{ github.event.inputs.networks }})
JSON="{\"include\":["
for item in ${list_elements[*]}
do
JSONline="{\"chain\": \"$item\"},"
if [[ "$JSON" != *"$JSONline"* ]]; then
JSON="$JSON$JSONline"
fi
echo $item
done <<< "$DIFF"
# Remove last "," and add closing brackets
if [[ $JSON == *, ]]; then
JSON="${JSON%?}"
fi
JSON="$JSON]}"
echo $JSON
echo "::set-output name=matrix::$( echo "$JSON" )"
deploy-subquery:
needs: setup
name: Deploy subquery
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 5
matrix: ${{fromJson(needs.setup.outputs.matrix)}}

steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: |
mkdir -p $HOME/.local/bin
curl -LO https://github.com/fewensa/subquery-cli/releases/download/v${{ env.SUBQUERY_CLI_VERSION }}/subquery-linux-x86_64.zip
unzip subquery-linux-x86_64.zip -d $HOME/.local/bin/
rm -rf subquery-linux-x86_64.zip
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v5.1

- name: Deploy
run: |
subquery --token ${{ secrets.SUBQUERY_TOKEN }} deployment deploy \
--org ${{ env.SUBQUERY_ORG }} \
--key nova-wallet-${{ matrix.chain }} \
--branch deploy \
--sub-folder ./networks/${{ matrix.chain }} \
--type stage \
--indexer-image-version ${{ env.INDEXER_IMAGE_VERSION }} \
--query-image-version ${{ env.QUERY_IMAGE_VERSION }} \
--indexer-batch-size 15
43 changes: 43 additions & 0 deletions .github/workflows/pr_by_push_to_master.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Make pull request to deploy branch after push to master

on:
push:
branches:
- 'master'

jobs:
create_pull_request:
runs-on: ubuntu-latest
steps:
- name: Checkout to current branch
uses: actions/checkout@master
with:
ref: ${{ github.ref }}

- name: Prepare brach to commit
run: bash ./scripts/prepare_folders.sh

- name: Commit files
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add -f networks/**/
git commit -m "Prepare to pull request to deploy branch"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: refs/heads/update-deploy-${{github.run_number}}

- uses: repo-sync/pull-request@v2
name: pull-request
with:
source_branch: "update-deploy-${{github.run_number}}"
destination_branch: "deploy"
pr_title: "Update deploy branch"
pr_body: |
Update deploy branch
pr_reviewer: "stepanLav"
pr_draft: false
github_token: ${{ secrets.GITHUB_TOKEN }}
77 changes: 77 additions & 0 deletions .github/workflows/update_stg_by_push_to_deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Deploy subquery to stage (without reindex)

on:
workflow_dispatch

env:
SUBQUERY_CLI_VERSION: 0.2.5
SUBQUERY_ORG: nova-wallet
INDEXER_IMAGE_VERSION: v0.31.1
QUERY_IMAGE_VERSION: v0.13.0

jobs:
setup:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v2

- id: set-matrix
run: |
folders=($(ls ./networks))
JSON="{\"include\":["
for item in ${folders[*]}
do
JSONline="{\"chain\": \"$item\"},"
if [[ "$JSON" != *"$JSONline"* ]]; then
JSON="$JSON$JSONline"
fi
echo $item
done <<< "$DIFF"
# Remove last "," and add closing brackets
if [[ $JSON == *, ]]; then
JSON="${JSON%?}"
fi
JSON="$JSON]}"
echo $JSON
echo "::set-output name=matrix::$( echo "$JSON" )"
deploy-subquery:
needs: setup
name: Deploy subquery
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 5
matrix: ${{fromJson(needs.setup.outputs.matrix)}}

steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: |
mkdir -p $HOME/.local/bin
curl -LO https://github.com/fewensa/subquery-cli/releases/download/v${{ env.SUBQUERY_CLI_VERSION }}/subquery-linux-x86_64.zip
unzip subquery-linux-x86_64.zip -d $HOME/.local/bin/
rm -rf subquery-linux-x86_64.zip
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v5.1

- name: Deploy
run: |
subquery --token ${{ secrets.SUBQUERY_TOKEN }} deployment deploy \
--org ${{ env.SUBQUERY_ORG }} \
--key nova-wallet-${{ matrix.chain }} \
--branch deploy \
--sub-folder ./networks/${{ matrix.chain }} \
--type stage \
--indexer-image-version ${{ env.INDEXER_IMAGE_VERSION }} \
--query-image-version ${{ env.QUERY_IMAGE_VERSION }} \
--indexer-batch-size 15
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ yarn.lock
.vscode
__pycache__
temporary
.pytest_cache
.pytest_cache
networks/**/src
networks/**/docker-compose.yml
networks/**/local-runner.sh
networks/**/schema.graphql
networks/**/tsconfig.json
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# SubQuery Nova projects

This repo contains implementation of [SubQuery](https://github.com/subquery/subql) project for many substrate projects which support Nova-wallet.
This repo contains implementation of [SubQuery](https://github.com/subquery/subql) project for many substrate networks which Nova-wallet supports.

# Get Started
### 1. Run script for prepare project to run
```shell
sh ./scripts/prepare_folders.sh
```

### 2. For local run you can use special script in each network directory
```shell
sh ./networks/${network}/local-runner.sh
Expand Down
35 changes: 31 additions & 4 deletions networks/acala/src/mappings/HistoryElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
isOrmlTransfer,
isNativeTransferAll,
isOrmlTransferAll,
isEvmTransaction,
isEvmExecutedEvent,
} from "./common";
import {CallBase} from "@polkadot/types/types/calls";
import {AnyTuple} from "@polkadot/types/types/codec";
Expand All @@ -32,11 +34,13 @@ export async function handleHistoryElement(extrinsic: SubstrateExtrinsic): Promi
} else {
await saveExtrinsic(extrinsic)
}
} else if (isEvmTransaction(extrinsic.extrinsic.method) && extrinsic.success) {
await saveEvmExtrinsic(extrinsic)
}
}

function createHistoryElement (extrinsic: SubstrateExtrinsic, address: string, suffix: string = '') {
let extrinsicHash = extrinsic.extrinsic.hash.toString();
function createHistoryElement (extrinsic: SubstrateExtrinsic, address: string, suffix: string = '', hash?: string) {
let extrinsicHash = hash || extrinsic.extrinsic.hash.toString();
let blockNumber = extrinsic.block.block.header.number.toNumber();
let extrinsicIdx = extrinsic.idx
let extrinsicId = extrinsicIdFromBlockAndIdx(blockNumber, extrinsicIdx)
Expand Down Expand Up @@ -78,7 +82,7 @@ async function saveFailedTransfers(transfers: Array<TransferData>, extrinsic: Su
await Promise.allSettled(promises)
}

async function saveExtrinsic(extrinsic: SubstrateExtrinsic): Promise<void> {
async function saveExtrinsic(extrinsic: SubstrateExtrinsic): Promise<void> {
const element = createHistoryElement(extrinsic, extrinsic.extrinsic.signer.toString())

element.extrinsic = {
Expand All @@ -91,6 +95,29 @@ async function saveExtrinsic(extrinsic: SubstrateExtrinsic): Promise<void> {
await element.save()
}

async function saveEvmExtrinsic(extrinsic: SubstrateExtrinsic): Promise<void> {
const executedEvent = extrinsic.events.find(isEvmExecutedEvent)
if (!executedEvent) {
return
}

const addressFrom = executedEvent.event.data?.[0]?.toString();
const hash = executedEvent.event.data?.[2]?.toString();
const success = !!(executedEvent.event.data?.[3].toJSON() as any).succeed;

const element = createHistoryElement(extrinsic, addressFrom, '', hash)

element.extrinsic = {
hash,
module: extrinsic.extrinsic.method.section,
call: extrinsic.extrinsic.method.method,
success,
fee: calculateFeeAsString(extrinsic)
}

await element.save()
}

/// Success Transfer emits Transfer event that is handled at Transfers.ts handleTransfer()
function findFailedTransferCalls(extrinsic: SubstrateExtrinsic): Array<TransferData> | null {
if (extrinsic.success) {
Expand All @@ -104,7 +131,7 @@ function findFailedTransferCalls(extrinsic: SubstrateExtrinsic): Array<TransferD

let sender = extrinsic.extrinsic.signer
return transferCallsArgs.map(([isTransferAll, address, amount, assetId]) => {
const transfer: Transfer = {
const transfer: Transfer = {
amount: amount.toString(),
from: sender.toString(),
to: address,
Expand Down
3 changes: 2 additions & 1 deletion networks/acala/src/mappings/Rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ async function handleRewardForTxHistory(rewardEvent: SubstrateEvent): Promise<vo
initialCallIndex,
(currentCallIndex, eventAccount) => {
if (payoutValidators.length > currentCallIndex + 1) {
return payoutValidators[currentCallIndex + 1] == eventAccount ? currentCallIndex + 1 : currentCallIndex
const index = payoutValidators.indexOf(eventAccount)
return index !== -1 && index > currentCallIndex ? index : currentCallIndex
} else {
return currentCallIndex
}
Expand Down
35 changes: 31 additions & 4 deletions networks/altair/src/mappings/HistoryElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
isOrmlTransfer,
isNativeTransferAll,
isOrmlTransferAll,
isEvmTransaction,
isEvmExecutedEvent,
} from "./common";
import {CallBase} from "@polkadot/types/types/calls";
import {AnyTuple} from "@polkadot/types/types/codec";
Expand All @@ -32,11 +34,13 @@ export async function handleHistoryElement(extrinsic: SubstrateExtrinsic): Promi
} else {
await saveExtrinsic(extrinsic)
}
} else if (isEvmTransaction(extrinsic.extrinsic.method) && extrinsic.success) {
await saveEvmExtrinsic(extrinsic)
}
}

function createHistoryElement (extrinsic: SubstrateExtrinsic, address: string, suffix: string = '') {
let extrinsicHash = extrinsic.extrinsic.hash.toString();
function createHistoryElement (extrinsic: SubstrateExtrinsic, address: string, suffix: string = '', hash?: string) {
let extrinsicHash = hash || extrinsic.extrinsic.hash.toString();
let blockNumber = extrinsic.block.block.header.number.toNumber();
let extrinsicIdx = extrinsic.idx
let extrinsicId = extrinsicIdFromBlockAndIdx(blockNumber, extrinsicIdx)
Expand Down Expand Up @@ -78,7 +82,7 @@ async function saveFailedTransfers(transfers: Array<TransferData>, extrinsic: Su
await Promise.allSettled(promises)
}

async function saveExtrinsic(extrinsic: SubstrateExtrinsic): Promise<void> {
async function saveExtrinsic(extrinsic: SubstrateExtrinsic): Promise<void> {
const element = createHistoryElement(extrinsic, extrinsic.extrinsic.signer.toString())

element.extrinsic = {
Expand All @@ -91,6 +95,29 @@ async function saveExtrinsic(extrinsic: SubstrateExtrinsic): Promise<void> {
await element.save()
}

async function saveEvmExtrinsic(extrinsic: SubstrateExtrinsic): Promise<void> {
const executedEvent = extrinsic.events.find(isEvmExecutedEvent)
if (!executedEvent) {
return
}

const addressFrom = executedEvent.event.data?.[0]?.toString();
const hash = executedEvent.event.data?.[2]?.toString();
const success = !!(executedEvent.event.data?.[3].toJSON() as any).succeed;

const element = createHistoryElement(extrinsic, addressFrom, '', hash)

element.extrinsic = {
hash,
module: extrinsic.extrinsic.method.section,
call: extrinsic.extrinsic.method.method,
success,
fee: calculateFeeAsString(extrinsic)
}

await element.save()
}

/// Success Transfer emits Transfer event that is handled at Transfers.ts handleTransfer()
function findFailedTransferCalls(extrinsic: SubstrateExtrinsic): Array<TransferData> | null {
if (extrinsic.success) {
Expand All @@ -104,7 +131,7 @@ function findFailedTransferCalls(extrinsic: SubstrateExtrinsic): Array<TransferD

let sender = extrinsic.extrinsic.signer
return transferCallsArgs.map(([isTransferAll, address, amount, assetId]) => {
const transfer: Transfer = {
const transfer: Transfer = {
amount: amount.toString(),
from: sender.toString(),
to: address,
Expand Down
3 changes: 2 additions & 1 deletion networks/altair/src/mappings/Rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ async function handleRewardForTxHistory(rewardEvent: SubstrateEvent): Promise<vo
initialCallIndex,
(currentCallIndex, eventAccount) => {
if (payoutValidators.length > currentCallIndex + 1) {
return payoutValidators[currentCallIndex + 1] == eventAccount ? currentCallIndex + 1 : currentCallIndex
const index = payoutValidators.indexOf(eventAccount)
return index !== -1 && index > currentCallIndex ? index : currentCallIndex
} else {
return currentCallIndex
}
Expand Down
Loading

0 comments on commit 015ad94

Please sign in to comment.