Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .run/(VB) Index Alpha.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="(VB) Index Alpha" type="NodeJSConfigurationType" singleton="false" application-parameters="--force-clean --db-schema=testnet_alpha --unfinalized-blocks=true --batch-size=100 --timeout=360000 --scale-batch-size=false --store-cache-async=true --store-flush-interval=1 --enable-cache=false --kyve-endpoint=false --query-limit=1000 --pg-pool-min=300 --pg-pool-max=500 --pg-pool-acquire=30000 --pg-pool-idle=10000 --pg-pool-evict=12000" path-to-node="$USER_HOME$/.nvm/versions/node/v18.20.3/bin/node" node-parameters="--max-old-space-size=16384" path-to-js-file="node_modules/@subql/node-cosmos/bin/run" typescript-loader="bundled" working-dir="$PROJECT_DIR$">
<envs>
<env name="BATCH_SIZE" value="100" />
<env name="CHAIN_ID" value="pocket_alpha" />
<env name="DB_HOST" value="localhost" />
<env name="DB_PASS" value="postgres" />
<env name="DB_PORT" value="5432" />
<env name="DB_USER" value="postgres" />
<env name="ENDPOINT" value="https://shannon-testnet-grove-rpc.alpha.poktroll.com" />
<env name="NODE_ENV" value="development" />
<env name="NODE_OPTIONS" value="--max-old-space-size=8192" />
<env name="POCKETDEX_DB_BATCH_SIZE" value="5000" />
<env name="POCKETDEX_DB_PAGE_LIMIT" value="1000" />
<env name="POCKETDEX_GENESIS" value="https://raw.githubusercontent.com/pokt-network/pocket-network-genesis/refs/heads/master/shannon/testnet-alpha/genesis.json" />
<env name="TZ" value="utc" />
</envs>
<method v="2">
<option name="NpmBeforeRunTask" enabled="true">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="build" />
</scripts>
<arguments value="--mode=development" />
<node-interpreter value="project" />
<envs>
<env name="CHAIN_ID" value="pocket-alpha" />
<env name="DB_HOST" value="localhost" />
<env name="DB_PASS" value="postgres" />
<env name="DB_PORT" value="5432" />
<env name="DB_USER" value="postgres" />
<env name="DEBUG_BLOCK" value="false" />
<env name="ENDPOINT" value="https://shannon-testnet-grove-rpc.alpha.poktroll.com" />
<env name="NODE_ENV" value="development" />
<env name="TZ" value="utc" />
</envs>
</option>
</method>
</configuration>
</component>
9 changes: 0 additions & 9 deletions .run/(VB) Index Beta.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@
<env name="TZ" value="utc" />
</envs>
<method v="2">
<option name="NpmBeforeRunTask" enabled="true">
<package-json value="$PROJECT_DIR$/package.json"/>
<command value="run"/>
<scripts>
<script value="vendors:build"/>
</scripts>
<node-interpreter value="$USER_HOME$/.nvm/versions/node/v18.20.3/bin/node"/>
<envs/>
</option>
<option name="NpmBeforeRunTask" enabled="true">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
Expand Down
44 changes: 44 additions & 0 deletions .run/(VB) Index MainNet.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="(VB) Index MainNet" type="NodeJSConfigurationType" singleton="false" application-parameters="--force-clean --db-schema=mainnet --unfinalized-blocks=true --batch-size=1 --timeout=360000 --scale-batch-size=false --store-cache-async=true --store-flush-interval=1 --enable-cache=false --kyve-endpoint=false --query-limit=1000 --pg-pool-min=300 --pg-pool-max=500 --pg-pool-acquire=30000 --pg-pool-idle=10000 --pg-pool-evict=12000" path-to-node="$USER_HOME$/.nvm/versions/node/v18.20.3/bin/node" node-parameters="--max-old-space-size=8192" path-to-js-file="node_modules/@subql/node-cosmos/bin/run" typescript-loader="bundled" working-dir="$PROJECT_DIR$">
<envs>
<env name="BATCH_SIZE" value="100" />
<env name="CHAIN_ID" value="pocket" />
<env name="DB_HOST" value="localhost" />
<env name="DB_PASS" value="postgres" />
<env name="DB_PORT" value="5432" />
<env name="DB_SCHEMA" value="mainnet" />
<env name="DB_USER" value="postgres" />
<env name="ENDPOINT" value="https://shannon-grove-rpc.mainnet.poktroll.com" />
<env name="NODE_ENV" value="development" />
<env name="NODE_OPTIONS" value="--max-old-space-size=8192" />
<env name="POCKETDEX_DB_BATCH_SIZE" value="5000" />
<env name="POCKETDEX_DB_PAGE_LIMIT" value="1000" />
<env name="POCKETDEX_GENESIS" value="https://raw.githubusercontent.com/pokt-network/pocket-network-genesis/refs/heads/master/shannon/mainnet/genesis.json" />
<env name="TZ" value="utc" />
</envs>
<method v="2">
<option name="NpmBeforeRunTask" enabled="true">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="build" />
</scripts>
<arguments value="--mode=development" />
<node-interpreter value="project" />
<envs>
<env name="BATCH_SIZE" value="100" />
<env name="CHAIN_ID" value="pocket" />
<env name="DB_SCHEMA" value="mainnet" />
<env name="DB_HOST" value="localhost" />
<env name="DB_PASS" value="postgres" />
<env name="DB_PORT" value="5432" />
<env name="DB_USER" value="postgres" />
<env name="DEBUG_BLOCK" value="false" />
<env name="ENDPOINT" value="https://shannon-grove-rpc.mainnet.poktroll.com" />
<env name="NODE_ENV" value="development" />
<env name="TZ" value="utc" />
</envs>
</option>
</method>
</configuration>
</component>
19 changes: 19 additions & 0 deletions .run/FC Alpha.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="FC Alpha" type="NodeJSConfigurationType" singleton="false"
application-parameters="force-clean -f . --db-schema=testnet_alpha --profiler"
path-to-node="$USER_HOME$/.nvm/versions/node/v18.20.3/bin/node"
path-to-js-file="node_modules/@subql/node-cosmos/bin/run" typescript-loader="bundled"
working-dir="$PROJECT_DIR$">
<envs>
<env name="CHAIN_ID" value="pocket-alpha"/>
<env name="DB_HOST" value="localhost"/>
<env name="DB_PASS" value="postgres"/>
<env name="DB_PORT" value="5432"/>
<env name="DB_USER" value="postgres"/>
<env name="ENDPOINT" value="https://shannon-testnet-grove-rpc.alpha.poktroll.com"/>
<env name="NODE_ENV" value="development"/>
<env name="TZ" value="utc"/>
</envs>
<method v="2"/>
</configuration>
</component>
4 changes: 4 additions & 0 deletions project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ const project: CosmosProject = {
"EventSupplierStaked",
"EventSupplierUnbondingBegin",
"EventSupplierUnbondingEnd",
"EventSupplierServiceConfigActivated",
],
},
],
Expand Down Expand Up @@ -399,6 +400,7 @@ const project: CosmosProject = {
"EventMorseAccountClaimed",
"EventMorseApplicationClaimed",
"EventMorseSupplierClaimed",
"EventMorseAccountRecovered",
],
},
],
Expand All @@ -411,6 +413,7 @@ const project: CosmosProject = {
"MsgClaimMorseAccount",
"MsgClaimMorseApplication",
"MsgClaimMorseSupplier",
"MsgRecoverMorseAccount",
],
},
],
Expand All @@ -420,6 +423,7 @@ const project: CosmosProject = {
{
startBlock: 1,
// migration at 25507 on alpha
// msg grants at 23196 on alpha
kind: CosmosDatasourceKind.Runtime,
mapping: {
file: "./dist/index.js",
Expand Down
62 changes: 61 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,33 @@ enum SettlementOpReason {
TLM_GLOBAL_MINT_REIMBURSEMENT_REQUEST_ESCROW_MODULE_TRANSFER
}

enum MorseSupplierClaimSignerType {
# Unspecified signer type
MORSE_SUPPLIER_CLAIM_SIGNER_TYPE_UNSPECIFIED

# signer === addr === operator === owner
# Custodial signer type
# - The Morse node address is NOT EMPTY (i.e. operator)
# - The Morse output address is EMPTY (i.e. owner)
# - Implies that the operator and owner are THE SAME offchain identity
MORSE_SUPPLIER_CLAIM_CUSTODIAL_SIGNED_BY_NODE_ADDR

# signer === operator === addr && owner !== operator
# Non-custodial signer type
# - The Morse node address is NOT EMPTY (i.e. operator)
# - The Morse output address is NOT EMPTY (i.e. owner)
# - Implies that the operator and owner are MOST LIKELY DIFFERENT offchain identities
# - The operator is the one signing the supplier claim
MORSE_SUPPLIER_CLAIM_NON_CUSTODIAL_SIGNED_BY_NODE_ADDR
# signer === owner && owner !== addr
# Owner non-custodial signer type
# - The Morse node address is EMPTY (i.e. operator)
# - The Morse output address is NOT EMPTY (i.e. owner)
# - Implies that the operator and owner are MOST LIKELY different offchain identities
# - The owner is the one signing the supplier claim
MORSE_SUPPLIER_CLAIM_NON_CUSTODIAL_SIGNED_BY_OWNER
}

### JSON FIELDS

type EventAttribute @jsonField(indexed: false) {
Expand Down Expand Up @@ -717,6 +744,16 @@ type SupplierServiceConfig @entity {
service: Service!
revShare: [SupplierRevShare]!
endpoints: [SupplierEndpoint]!
# activation block per EventSupplierServiceConfigActivated event
activatedAt: Block
activatedEvent: EventSupplierServiceConfigActivated
}

type EventSupplierServiceConfigActivated @entity {
id: ID!
event: Event!
block: Block!
activatedServicesConfig: [SupplierServiceConfig] @derivedFrom(field: "activatedEvent")
}

type EventSupplierUnbondingBegin @entity {
Expand Down Expand Up @@ -1147,10 +1184,17 @@ type MorseClaimableAccount @entity {
supplierStakeAmount: BigInt!
applicationStakeAmount: BigInt!

# Only applicable to morse node/supplier accounts
morseOutputAddress: String
# the datetime after which the Morse node/supplier unbonding period will have elapsed.
unstakingTime: Date

# to be filled when claiming
shannonDestAddress: String
claimedAtHeight: BigInt
claimedAt: Block
claimed: Boolean!
transaction: Transaction
claimedMsg: Message

# TODO(@Alann27): the denominations are really needed? We know for sure that they are upokt
unstakedBalanceDenom: String!
Expand All @@ -1175,6 +1219,19 @@ type MsgClaimMorseAccount @entity {
message: Message!
}

type MsgRecoverMorseAccount @entity {
id: ID!
authority: ModuleAccount!
shannonDestAddress: Account!
morseSrcAddress: String!
recoveredBalanceAmount: BigInt!
recoveredBalanceDenom: String!

block: Block!
transaction: Transaction!
message: Message!
}

type MsgClaimMorseApplication @entity {
id: ID!
application: Application!
Expand Down Expand Up @@ -1211,6 +1268,9 @@ type MsgClaimMorseSupplier @entity {
morsePublicKey: String!
morseSrcAddress: String!
morseSignature: String!
morseNodeAddress: String
signerIsOutputAddress: Boolean
claimSignerType: MorseSupplierClaimSignerType
# Retrieved from the event
stakeAmount: BigInt!
stakeDenom: String!
Expand Down
79 changes: 79 additions & 0 deletions src/mappings/dbFunctions/dataByDelegatorAddressesAndBlocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Used to get the proof, claim and slash data between blocks and for the list of delegator addresses
export function getDataByDelegatorAddressesAndBlocksFn (dbSchema: string): string {
return `CREATE OR REPLACE FUNCTION ${dbSchema}.get_data_by_delegator_addresses_and_blocks(
addresses TEXT[],
start_height BIGINT,
end_height BIGINT
)
RETURNS jsonb
LANGUAGE sql
STABLE
AS $$
WITH matched_suppliers AS (
SELECT DISTINCT ON (elem->>'address')
ssc.supplier_id,
elem->>'address' AS address
FROM ${dbSchema}.supplier_service_configs ssc
INNER JOIN ${dbSchema}.suppliers s ON s.id = ssc.supplier_id
CROSS JOIN jsonb_array_elements(ssc.rev_share) AS elem
WHERE elem->>'address' = ANY (addresses)
AND upper_inf(ssc._block_range)
AND s.stake_status = 'Staked'
AND upper_inf(s._block_range)
),

claim_agg AS (
SELECT
mcc.supplier_id,
COUNT(DISTINCT mcc.id) AS claim_count,
SUM(r.num_relays) AS claim_relays,
SUM(r.num_claimed_computed_units) AS claim_computed_units,
SUM(r.claimed_amount) AS claim_upokt
FROM ${dbSchema}.msg_create_claims mcc
INNER JOIN ${dbSchema}.relays r ON r.msg_create_claim_id = mcc.id
WHERE mcc.block_id BETWEEN start_height AND end_height
GROUP BY mcc.supplier_id
),

proof_agg AS (
SELECT
ecs.supplier_id,
COUNT(DISTINCT ecs.id) AS proof_count,
SUM(ecs.num_relays) AS proof_relays,
SUM(ecs.num_claimed_computed_units) AS proof_computed_units,
SUM(ecs.claimed_amount) AS proof_upokt
FROM ${dbSchema}.event_claim_settleds ecs
WHERE ecs.block_id BETWEEN start_height AND end_height
GROUP BY ecs.supplier_id
),

slashed_agg AS (
SELECT
ess.supplier_id,
SUM(ess.previous_stake_amount - ess.after_stake_amount) AS slashed
FROM ${dbSchema}.event_supplier_slasheds ess
WHERE ess.block_id BETWEEN start_height AND end_height
GROUP BY ess.supplier_id
)

SELECT jsonb_agg(
jsonb_build_object(
'address', ms.address,
'proof_relays', COALESCE(p.proof_relays, 0),
'proof_computed_units', COALESCE(p.proof_computed_units, 0),
'proof_upokt', COALESCE(p.proof_upokt, 0),
'proof_amount', COALESCE(p.proof_count, 0),
'claim_relays', COALESCE(c.claim_relays, 0),
'claim_computed_units', COALESCE(c.claim_computed_units, 0),
'claim_upokt', COALESCE(c.claim_upokt, 0),
'claim_amount', COALESCE(c.claim_count, 0),
'slashed', COALESCE(s.slashed, 0)
)
)
FROM matched_suppliers ms
LEFT JOIN claim_agg c ON c.supplier_id = ms.supplier_id
LEFT JOIN proof_agg p ON p.supplier_id = ms.supplier_id
LEFT JOIN slashed_agg s ON s.supplier_id = ms.supplier_id;
$$;
`
}
Loading