-
Notifications
You must be signed in to change notification settings - Fork 5
151 lines (134 loc) · 6.59 KB
/
v2-prepare-unstakes.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: Prepare Late Unstakes V2
on:
workflow_dispatch:
repository_dispatch:
types: [trigger_unstakes_v2]
jobs:
unstakes:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@master
with:
fetch-depth: 20
- name: Load scoring unstakes details
run: |
set -ex
unstake_hints_json=$(git log -1 --name-only --pretty=format: --grep 'scoring run' | grep scoring-v2 | grep unstake-hints.json)
scoring_run_ui_id=$(git log -1 --name-only --pretty=format: --grep 'scoring run' | grep scoring-v2 | head -6 | tail -1 | awk -F / '{print $2}')
epoch=$(<<<"$scoring_run_ui_id" awk -F . '{print $1}')
if [[ -z $unstake_hints_json ]]
then
echo "Failed to find JSON with unstake hints in the PR!"
exit 1
fi
if [[ -z $epoch ]]
then
echo "Failed to detect epoch from the UI ID!"
exit 1
fi
echo "unstake_hints_json=$unstake_hints_json" >> $GITHUB_ENV
echo "epoch=$epoch" >> $GITHUB_ENV
echo "scoring_id=$scoring_run_ui_id" >> $GITHUB_ENV
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Configure image
run: |
images=$(aws ecr describe-images --repository-name marinade.finance/ds-scoring)
latest=$(<<<"$images" jq '.imageDetails[] | .imagePushedAt + " " + .imageTags[0]' -r | sort | tail -1 | cut -d' ' -f2)
echo "latest=$latest" >> $GITHUB_ENV
- name: Run compute unstakes
run: |
docker run --rm \
-e "DATA_PROVIDER_MODE=api" \
-e "VALIDATORS_URL=https://validators-api.marinade.finance/validators" \
-e "BLACKLIST_URL=https://raw.githubusercontent.com/marinade-finance/delegation-strategy-2/master/blacklist.csv" \
-e "REWARDS_API=https://validators-api.marinade.finance/rewards" \
-e "VEMNDE_VOTES_URL=https://snapshots-api.marinade.finance/v1/votes/vemnde/latest" \
-e "MSOL_VOTES_URL=https://snapshots-api.marinade.finance/v1/votes/msol/latest" \
-e "REWARDS_URL=https://validators-api.marinade.finance/rewards" \
-e "JITO_MEV_URL=https://validators-api.marinade.finance/mev" \
-e "BONDS_URL=https://validator-bonds-api.marinade.finance/bonds" \
-e "MARINADE_TVL_URL=http://api.marinade.finance/tlv" \
-v "/tmp/snapshot:/usr/src/app/snapshot" \
"$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" \
pnpm cli -- computeUnstakes
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: marinade.finance/ds-scoring
IMAGE_TAG: ${{ env.latest }}
- name: Merge unstakes
run: |
file1="/tmp/snapshot/unstake-hints.json"
file2="${{ env.unstake_hints_json }}"
output="merged.json"
temp=$(mktemp)
jq '.unstake_hints = []' "$file1" > "$output"
accounts=$(jq -r '.unstake_hints[].vote_account' "$file1" "$file2" | sort -u)
echo "$accounts" | while read -r account; do
[[ -z "$account" ]] && continue
hints1=$(jq -r --arg account "$account" '.unstake_hints[] | select(.vote_account == $account) | .hints[]' "$file1")
hints2=$(jq -r --arg account "$account" '.unstake_hints[] | select(.vote_account == $account) | .hints[]' "$file2")
hints_merged=$(echo -e "$hints1\n$hints2" | grep -v '^$' | sort | uniq | jq -R . | jq -s .)
base_entry=$(jq --arg account "$account" '.unstake_hints[] | select(.vote_account == $account)' "$file1")
if [[ -z "$base_entry" ]]; then
base_entry=$(jq --arg account "$account" '.unstake_hints[] | select(.vote_account == $account)' "$file2")
fi
updated_entry=$(echo "$base_entry" | jq --argjson hints "$hints_merged" '.hints = $hints')
jq --argjson entry "$updated_entry" '.unstake_hints += [$entry]' "$output" > "$temp" && mv "$temp" "$output"
done
total_marinade_stake=$(jq '[.unstake_hints[].marinade_stake | tonumber] | add' merged.json)
validators_count=$(jq '.unstake_hints | length' merged.json)
echo "total_marinade_stake=$total_marinade_stake" >> $GITHUB_ENV
echo "validators_count=$validators_count" >> $GITHUB_ENV
mv merged.json "${{ env.unstake_hints_json }}"
- name: Generate Unstakes Summary
run: |
total_marinade_stake="${{ env.total_marinade_stake }}"
validators_count="${{ env.validators_count }}"
cat > unstakes.md << EOF
# Unstakes results $scoring_id
| | Stake (SOL) | Validators |
|:------------------------|---------------:|---------------:|
| **Total unstakes** | $total_marinade_stake | $validators_count |
EOF
- name: Make a Pull Request
run: |
scoring_id="${{ env.scoring_id }}"
scoring_branch="unstakes/$scoring_id"
total_marinade_stake="${{ env.total_marinade_stake }}"
validators_count="${{ env.validators_count }}"
git config --global user.name 'Autonomous Scoring Pipeline'
git config --global user.email '[email protected]'
git checkout -b "$scoring_branch"
git add scoring-v2
[[ -n "$(git status --porcelain)" ]] && git commit -m "emergency unstakes for scoring run $scoring_id" && git push -u origin "$scoring_branch" || echo "No changes to be committed"
pr_body=$(cat unstakes.md)
pr_url=$(gh pr create -B master -H "$scoring_branch" --title "Publish V2 Emergency Unstakes ($scoring_id)" --body "$pr_body")
echo "pr_url=$pr_url" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Send Discord Notification
run: |
scoring_id="${{ env.scoring_id }}"
pr_url="${{ env.pr_url }}"
curl "$DISCORD_WEBHOOK" -H "Content-Type: application/json" -d '{
"username": "DS Scoring",
"avatar_url": "https://public.marinade.finance/ds-scoring-bot.png",
"embeds": [
{
"title": "Late Unstakes PR ('"$scoring_id"') is prepared.",
"url": "'"$pr_url"'",
"color": "5661687"
}
]
}'
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}