Skip to content

Commit 456d803

Browse files
authored
fix: pwr mint burn collector (#72)
1 parent a4d1f72 commit 456d803

File tree

8 files changed

+149
-16
lines changed

8 files changed

+149
-16
lines changed

cmd/yaci/postgres_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func testExtractBlocksAndTxs(t *testing.T) {
6060

6161
transactions := getJSONResponse(t, RestTxEndpoint, nil)
6262
require.NotEmpty(t, transactions)
63-
// The number of transactions is 42 as defined in the `compose.yaml` file under the `manifest-ledger-tx` service
64-
require.Len(t, transactions, 42)
63+
// The number of transactions is 48 as defined in the `compose.yaml` file under the `manifest-ledger-tx` service
64+
require.Len(t, transactions, 48)
6565
})
6666
}
6767

@@ -181,13 +181,16 @@ func testPrometheusMetrics(t *testing.T) {
181181
body := string(resp.Body())
182182
require.Contains(t, body, "yaci_addresses_total_unique_user{source=\"postgres\"} 3")
183183
require.Contains(t, body, "yaci_addresses_total_unique_group{source=\"postgres\"} 3")
184-
require.Contains(t, body, "yaci_transactions_total_count{source=\"postgres\"} 42")
184+
require.Contains(t, body, "yaci_transactions_total_count{source=\"postgres\"} 48")
185185
// 3000000umfx were burned by the MFX to PWR conversion
186186
// 123umfx were burned by a POA proposal
187187
require.Contains(t, body, "yaci_tokenomics_total_burn_amount{source=\"postgres\"} 3.000123e+06")
188188
require.Contains(t, body, "yaci_tokenomics_total_payout_amount{source=\"postgres\"} 7.54321e+06")
189189
// 6000000factory/.../upwr were minted by the MFX to PWR conversion
190-
require.Contains(t, body, "yaci_tokenomics_total_pwr_minted_amount{source=\"postgres\"} 6e+06")
190+
// 123factory/.../upwr were minted by a POA proposal
191+
require.Contains(t, body, "yaci_tokenomics_total_pwr_minted_amount{source=\"postgres\"} 6.000123e+06")
192+
// 12factory/.../upwr were burned by a POA proposal
193+
require.Contains(t, body, "yaci_tokenomics_total_pwr_burned_amount{source=\"postgres\"} 12")
191194
require.Contains(t, body, "yaci_locked_tokens_count{amount=\"2000000000\",denom=\"umfx\",source=\"postgres\"} 1")
192195
})
193196
}

docker/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ GRPC="9090"
2020
GRPC_WEB="9091"
2121
ROSETTA="8080"
2222
TIMEOUT_COMMIT="3s"
23-
VOTING_TIMEOUT="5s"
23+
VOTING_TIMEOUT="10s"
2424
DENOM=umfx
2525
BOND_DENOM=upoa
2626
POA_ADMIN_ADDRESS="manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"group_policy_address": "${POA_ADMIN_ADDRESS}",
3+
"messages": [
4+
{
5+
"@type": "/osmosis.tokenfactory.v1beta1.MsgBurn",
6+
"sender": "${POA_ADMIN_ADDRESS}",
7+
"burnFromAddress": "${ADDR1}",
8+
"amount": {
9+
"denom": "factory/${POA_ADMIN_ADDRESS}/upwr",
10+
"amount": "12"
11+
}
12+
}
13+
],
14+
"metadata": "",
15+
"title": "Burn 12 upwr",
16+
"summary": "This proposal will burn 12 upwr",
17+
"proposers": [
18+
"${ADDR1}"
19+
]
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"group_policy_address": "${POA_ADMIN_ADDRESS}",
3+
"messages": [
4+
{
5+
"@type": "/osmosis.tokenfactory.v1beta1.MsgMint",
6+
"sender": "${POA_ADMIN_ADDRESS}",
7+
"mintToAddress": "${ADDR1}",
8+
"amount": {
9+
"denom": "factory/${POA_ADMIN_ADDRESS}/upwr",
10+
"amount": "123"
11+
}
12+
}
13+
],
14+
"metadata": "",
15+
"title": "Mint 123 upwr",
16+
"summary": "This proposal will mint 123 upwr",
17+
"proposers": [
18+
"${ADDR1}"
19+
]
20+
}

docker/infra/scripts/init_manifest_ledger.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ update_test_genesis '.app_state["group"]["group_seq"]="1"'
2626
update_test_genesis '.app_state["group"]["groups"]=[{"id":"1","admin":"'${POA_ADMIN_ADDRESS}'","metadata":"AQ==","version":"2","total_weight":"2","created_at":"2024-05-16T15:10:54.372190727Z"}]'
2727
update_test_genesis '.app_state["group"]["group_members"]=[{"group_id":"1","member":{"address":"'${ADDR1}'","weight":"1","metadata":"user1","added_at":"2024-05-16T15:10:54.372190727Z"}},{"group_id":"1","member":{"address":"'${ADDR2}'","weight":"1","metadata":"user2","added_at":"2024-05-16T15:10:54.372190727Z"}}]'
2828
update_test_genesis '.app_state["group"]["group_policy_seq"]="1"'
29-
update_test_genesis '.app_state["group"]["group_policies"]=[{"address":"'${POA_ADMIN_ADDRESS}'","group_id":"1","admin":"'${POA_ADMIN_ADDRESS}'","metadata":"AQ==","version":"2","decision_policy":{"@type":"/cosmos.group.v1.ThresholdDecisionPolicy","threshold":"1","windows":{"voting_period":"5s","min_execution_period":"0s"}},"created_at":"2024-05-16T15:10:54.372190727Z"}]'
29+
update_test_genesis '.app_state["group"]["group_policies"]=[{"address":"'${POA_ADMIN_ADDRESS}'","group_id":"1","admin":"'${POA_ADMIN_ADDRESS}'","metadata":"AQ==","version":"2","decision_policy":{"@type":"/cosmos.group.v1.ThresholdDecisionPolicy","threshold":"1","windows":{"voting_period":"'${VOTING_TIMEOUT}'","min_execution_period":"0s"}},"created_at":"2024-05-16T15:10:54.372190727Z"}]'
3030
update_test_genesis '.app_state["tokenfactory"]["factory_denoms"]=[{"denom":"factory/manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj/upwr","authority_metadata":{"admin":"manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj"}}]'
3131
update_test_genesis '.app_state["bank"]["denom_metadata"] |= . + [{"description":"PWR","denom_units":[{"denom":"factory/manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj/upwr","exponent":0,"aliases":["PWR"]},{"denom":"PWR","exponent":6,"aliases":["factory/manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj/upwr"]}],"base":"factory/manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj/upwr","display":"PWR","name":"POWER","symbol":"PWR","uri":"","uri_hash":""}]'
3232
update_test_genesis '.app_state["wasm"]["params"]["code_upload_access"]["permission"]="Everybody"'

docker/infra/scripts/init_manifest_ledger_txs.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fi
2222
# $1 = command, rest = optional flags
2323
function run_tx() {
2424
manifestd "$@" ${COMMON_MANIFESTD_ARGS} && sleep ${TIMEOUT_COMMIT}
25+
printf "\n"
2526
TX_COUNT=$((TX_COUNT + 1))
2627
}
2728

@@ -31,6 +32,7 @@ function run_proposal() {
3132
manifestd tx group vote ${PROPOSAL_ID} "$2" VOTE_OPTION_YES '' ${COMMON_MANIFESTD_ARGS} --note "${3}-vote" "${@:4}" && sleep ${TIMEOUT_COMMIT}
3233
sleep ${VOTING_TIMEOUT} # Wait for the voting period to end
3334
manifestd tx group exec ${PROPOSAL_ID} ${COMMON_MANIFESTD_ARGS} --note "${3}-exec" "${@:4}" && sleep ${TIMEOUT_COMMIT}
35+
printf "\n"
3436
PROPOSAL_ID=$((PROPOSAL_ID + 1))
3537
TX_COUNT=$((TX_COUNT + 3))
3638
}
@@ -50,43 +52,82 @@ echo "-> Converting 3 MFX to 6 PWR"
5052
run_tx tx wasm execute ${CONVERT_WASM_ADDRESS} '{"convert":{}}' --from $KEY --note "tx-mint-from-converter" --amount 3000000umfx
5153

5254
## Bank module
55+
echo "-> Bank send"
5356
run_tx tx bank send $ADDR1 ${POA_ADMIN_ADDRESS} 10000${DENOM} --from $KEY --note "tx-send-to-poa-admin"
57+
58+
echo "-> Bank multi-send"
5459
run_tx tx bank multi-send $ADDR1 $ADDR2 ${POA_ADMIN_ADDRESS} 10000${DENOM} --from $KEY --note "tx-multi-send-to-poa-admin"
5560

5661
## Vesting
62+
echo "-> Creating periodic vesting account"
5763
run_tx tx vesting create-periodic-vesting-account ${VESTING_ADDR} /generated/vesting_period.json --from $KEY --note "tx-create-periodic-vesting-account"
5864

5965
## Tokenfactory module
66+
echo "-> Create new denom (TF)"
6067
run_tx tx tokenfactory create-denom ufoobar --from $KEY --note "tx-create-denom-ufoobar"
68+
69+
echo "-> Modify new denom metadata(TF)"
6170
run_tx tx tokenfactory modify-metadata factory/$ADDR1/ufoobar FOOBAR "This is the foobar token" 6 --from $KEY --note "tx-modify-metadata-foobar"
71+
72+
echo "-> Mint new denom (TF)"
6273
run_tx tx tokenfactory mint-to $ADDR1 2000000factory/$ADDR1/ufoobar --from $KEY --note "tx-mint-to"
74+
75+
echo "-> Burn new denom (TF)"
6376
run_tx tx tokenfactory burn-from $ADDR1 1000000factory/$ADDR1/ufoobar --from $KEY --note "tx-burn-from"
77+
78+
echo "-> Change admin of new denom (TF)"
6479
run_tx tx tokenfactory change-admin factory/$ADDR1/ufoobar $ADDR2 --from $KEY --note "tx-change-admin"
6580

6681
## Manifest module
82+
echo "-> Payout proposal (Manifest)"
6783
run_proposal "payout.json" "$ADDR1" "tx-payout-proposal" --from $KEY
84+
85+
echo "-> BurnHeldBalance proposal (Manifest)"
6886
run_proposal "burn.json" "$ADDR1" "tx-burn-proposal" --from $KEY
6987

7088
# Submit and withdraw payout and burn proposals to make sure collector works properly
89+
echo "-> Submit and withdraw payout proposal (Manifest)"
7190
run_tx tx group submit-proposal "/proposals/payout.json" --note "tx-payout-proposal-submit-2" --from $KEY
7291
run_tx tx group withdraw-proposal $PROPOSAL_ID $ADDR1 --note "tx-payout-proposal-withdraw" --from $KEY
7392
PROPOSAL_ID=$((PROPOSAL_ID + 1))
93+
94+
echo "-> Submit and withdraw burn proposal (Manifest)"
7495
run_tx tx group submit-proposal "/proposals/burn.json" --note "tx-burn-proposal-submit-2" --from $KEY
7596
run_tx tx group withdraw-proposal $PROPOSAL_ID $ADDR1 --note "tx-burn-proposal-withdraw" --from $KEY
7697
PROPOSAL_ID=$((PROPOSAL_ID + 1))
7798

99+
echo "-> Mint UPWR proposal (Manifest)"
100+
run_proposal "mint_upwr.json" "$ADDR1" "tx-mint-upwr-proposal" --from $KEY
101+
102+
echo "-> Burn UPWR proposal (Manifest)"
103+
run_proposal "burn_upwr.json" "$ADDR1" "tx-burn-upwr-proposal" --from $KEY
104+
78105
### Group module
79106
echo ${GROUP_MEMBERS} > members.json && cat members.json
80107
echo ${DECISION_POLICY} > policy.json && cat policy.json
108+
echo "-> Create group with policy"
81109
run_tx tx group create-group-with-policy $ADDR1 "" "" members.json policy.json --from $KEY --group-policy-as-admin --note "tx-create-group-with-policy"
110+
111+
echo "-> Send to user group"
82112
run_tx tx bank send $ADDR1 ${USER_GROUP_ADDRESS} 10000${DENOM} --from $KEY --note "tx-send-to-user-group"
113+
114+
echo "-> Create denom proposal (TF)"
83115
run_proposal "create_denom.json" "$ADDR1" "tx-create-denom-proposal" --from $KEY
116+
117+
echo "-> Mint new denom proposal (TF)"
84118
run_proposal "mint_new_denom.json" "$ADDR1" "tx-mint-new-denom-proposal" --from $KEY
119+
120+
echo "-> Send new denom proposal (TF)"
85121
run_proposal "send_new_denom.json" "$ADDR1" "tx-send-new-denom-proposal" --from $KEY
122+
123+
echo "-> Update group members proposal"
86124
run_proposal "update_group_members.json" "$ADDR1" "tx-update-group-members-proposal" --from $KEY
87125

88126
### Error transactions
127+
echo "-> Send tx that will error (Manifest)"
89128
run_tx tx bank send $ADDR2 $ADDR1 100000000001000000${DENOM} --from $KEY --note "tx-send-addr2-to-addr1-error"
129+
130+
echo "-> Send proposal that will error (Manifest)"
90131
run_proposal "send_error.json" "$ADDR1" "tx-send-proposal-error" --from $KEY
91132

92133
echo "Total transactions: $TX_COUNT"

docker/yaci/scripts/yaci_tx_check.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ function check_addr_txs() {
4848

4949
# Address-specific configurations
5050
declare -A ADDRESS_EXPECTED_TXS=(
51-
["${ADDR1}"]="43"
51+
["${ADDR1}"]="51"
5252
["${ADDR2}"]="12"
5353
["${USER_GROUP_ADDRESS}"]="15"
54-
["${POA_ADMIN_ADDRESS}"]="14"
54+
["${POA_ADMIN_ADDRESS}"]="20"
5555
["${VESTING_ADDR}"]="1"
5656
)
5757

@@ -102,6 +102,14 @@ declare -a ADDRESS1_TX_CHECKS=(
102102
"tx-payout-proposal-withdraw:false"
103103
"tx-burn-proposal-submit-2:false"
104104
"tx-burn-proposal-withdraw:false"
105+
"tx-mint-upwr-proposal-submit:false"
106+
"tx-mint-upwr-proposal-submit:true"
107+
"tx-mint-upwr-proposal-vote:false"
108+
"tx-mint-upwr-proposal-exec:false"
109+
"tx-burn-upwr-proposal-submit:false"
110+
"tx-burn-upwr-proposal-submit:true"
111+
"tx-burn-upwr-proposal-vote:false"
112+
"tx-burn-upwr-proposal-exec:false"
105113
)
106114

107115
declare -a ADDRESS2_TX_CHECKS=(
@@ -149,6 +157,12 @@ declare -a POA_ADMIN_ADDRESS_TX_CHECKS=(
149157
"tx-grant-proposal-submit:true"
150158
"tx-payout-proposal-submit-2:false"
151159
"tx-burn-proposal-submit-2:false"
160+
"tx-mint-upwr-proposal-submit:false"
161+
"tx-mint-upwr-proposal-submit:true"
162+
"tx-mint-upwr-proposal-exec:false"
163+
"tx-burn-upwr-proposal-submit:false"
164+
"tx-burn-upwr-proposal-submit:true"
165+
"tx-burn-upwr-proposal-exec:false"
152166
)
153167

154168
declare -A ADDRESS_TX_CHECKS=(

internal/metrics/collectors/total_pwr_minted.go renamed to internal/metrics/collectors/total_pwr_minted_burned.go

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import (
88
"github.com/prometheus/client_golang/prometheus"
99
)
1010

11-
// TotalPwrMintAmountQuery expected format of the cosmwasm event attribute for mint amounts, e.g., 123456upwr
12-
// Note: only counts PWR minted via the tf_mint event (i.e., via the tf_mint function)
13-
const TotalPwrMintAmountQuery = `
11+
// TotalPwrMintBurnAmountQuery expected format of the event attribute for mint/burn amounts, e.g., 123456upwr
12+
const TotalPwrMintBurnAmountQuery = `
1413
WITH pwr_minted AS (
1514
WITH tf_mint_events AS (
1615
SELECT
@@ -27,18 +26,45 @@ const TotalPwrMintAmountQuery = `
2726
JOIN api.messages_main m
2827
ON m.id = b.id
2928
AND m.message_index = b.msg_index
30-
AND m.type = '/cosmwasm.wasm.v1.MsgExecuteContract'
3129
JOIN LATERAL regexp_matches(
3230
b.amount_raw,
3331
'^([0-9]+)([[:alnum:]_\/\.]+)$'
3432
) AS rm(captures) ON TRUE
3533
WHERE (rm.captures)[2] = 'factory/manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj/upwr'
34+
),
35+
pwr_burned AS (
36+
WITH burn_events AS (
37+
SELECT
38+
e.id,
39+
e.event_index,
40+
MAX(e.attr_value) FILTER (WHERE e.attr_key = 'amount') AS amount_raw,
41+
MAX(e.msg_index) AS msg_index
42+
FROM api.events_main e
43+
WHERE e.event_type = 'burn'
44+
GROUP BY e.id, e.event_index
45+
)
46+
SELECT COALESCE(SUM((rm.captures)[1]::numeric), 0) AS amount
47+
FROM burn_events b
48+
JOIN api.messages_main m
49+
ON m.id = b.id
50+
AND m.message_index = b.msg_index
51+
JOIN api.transactions_main tx
52+
ON tx.id = b.id
53+
AND tx.error IS NULL
54+
JOIN LATERAL regexp_matches(
55+
b.amount_raw,
56+
'^([0-9]+)([[:alnum:]_\/\.]+)$'
57+
) AS rm(captures) ON TRUE
58+
WHERE (rm.captures)[2] = 'factory/manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj/upwr'
3659
)
37-
SELECT amount FROM pwr_minted;
60+
SELECT
61+
(SELECT amount FROM pwr_minted) as total_pwr_minted,
62+
(SELECT amount FROM pwr_burned) as total_pwr_burned;
3863
`
3964

4065
type TotalPwrMintedCollector struct {
4166
totalPwrMintedAmount *prometheus.Desc
67+
totalPwrBurnedAmount *prometheus.Desc
4268
db *sql.DB
4369
}
4470

@@ -47,7 +73,13 @@ func NewTotalPwrMintedCollector(db *sql.DB) *TotalPwrMintedCollector {
4773
db: db,
4874
totalPwrMintedAmount: prometheus.NewDesc(
4975
prometheus.BuildFQName("yaci", "tokenomics", "total_pwr_minted_amount"),
50-
"Total PWR minted",
76+
"Total upwr minted",
77+
nil,
78+
prometheus.Labels{"source": "postgres"},
79+
),
80+
totalPwrBurnedAmount: prometheus.NewDesc(
81+
prometheus.BuildFQName("yaci", "tokenomics", "total_pwr_burned_amount"),
82+
"Total upwr burned",
5183
nil,
5284
prometheus.Labels{"source": "postgres"},
5385
),
@@ -56,17 +88,20 @@ func NewTotalPwrMintedCollector(db *sql.DB) *TotalPwrMintedCollector {
5688

5789
func (c *TotalPwrMintedCollector) Describe(ch chan<- *prometheus.Desc) {
5890
ch <- c.totalPwrMintedAmount
91+
ch <- c.totalPwrBurnedAmount
5992
}
6093

6194
func (c *TotalPwrMintedCollector) Collect(ch chan<- prometheus.Metric) {
62-
var mintAmount float64
63-
err := c.db.QueryRow(TotalPwrMintAmountQuery).Scan(&mintAmount)
95+
var mintAmount, burnAmount float64
96+
err := c.db.QueryRow(TotalPwrMintBurnAmountQuery).Scan(&mintAmount, &burnAmount)
6497
if err != nil {
6598
ch <- prometheus.NewInvalidMetric(c.totalPwrMintedAmount, err)
99+
ch <- prometheus.NewInvalidMetric(c.totalPwrBurnedAmount, err)
66100
return
67101
}
68102

69103
ch <- prometheus.MustNewConstMetric(c.totalPwrMintedAmount, prometheus.CounterValue, mintAmount)
104+
ch <- prometheus.MustNewConstMetric(c.totalPwrBurnedAmount, prometheus.CounterValue, burnAmount)
70105
}
71106

72107
func init() {

0 commit comments

Comments
 (0)