-
Notifications
You must be signed in to change notification settings - Fork 0
41 lines (37 loc) · 1.69 KB
/
Copy pathupdate-supply.yml
File metadata and controls
41 lines (37 loc) · 1.69 KB
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
name: update-supply
on:
schedule:
- cron: "*/15 * * * *"
workflow_dispatch:
permissions:
contents: write
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Fetch supply from Solana
env:
RPC_URL: ${{ secrets.RPC_URL }}
run: |
RPC="${RPC_URL:-https://api.mainnet-beta.solana.com}"
MINT="4svsyTi5yRpVUUHFcKqDozCuEdhhP3H1VPy4xuTQpump"
EXCLUDED="" # space-separated wallet addresses (team, locked, bonding curve)
call() { curl -s -X POST "$RPC" -H 'Content-Type: application/json' -d "$1"; }
TOTAL=$(call '{"jsonrpc":"2.0","id":1,"method":"getTokenSupply","params":["'$MINT'"]}' | jq -r '.result.value.uiAmountString')
[ -z "$TOTAL" ] || [ "$TOTAL" = "null" ] && { echo "RPC failed"; exit 1; }
EXCL=0
for W in $EXCLUDED; do
BAL=$(call '{"jsonrpc":"2.0","id":1,"method":"getTokenAccountsByOwner","params":["'$W'",{"mint":"'$MINT'"},{"encoding":"jsonParsed"}]}' \
| jq '[.result.value[].account.data.parsed.info.tokenAmount.uiAmount] | add // 0')
EXCL=$(awk -v a="$EXCL" -v b="$BAL" 'BEGIN{printf "%.6f", a+b}')
done
CIRC=$(awk -v t="$TOTAL" -v e="$EXCL" 'BEGIN{printf "%.6f", t-e}' | sed -E 's/\.?0+$//')
printf "%s" "$TOTAL" > totalcoins.txt
printf "%s" "$CIRC" > circulating.txt
- name: Commit if changed
run: |
git config user.name "github-actions"
git config user.email "actions@github.com"
git add totalcoins.txt circulating.txt
git diff --cached --quiet || (git commit -m "update supply" && git pull --rebase && git push)