Skip to content

Commit

Permalink
feat: seed genesis data at project initiation
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed May 3, 2024
1 parent 9fc1b43 commit 80b8891
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
21 changes: 14 additions & 7 deletions project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ const project: CosmosProject = {
]),
},
dataSources: [
{
kind: CosmosDatasourceKind.Runtime,
startBlock: 1,
endBlock: 1,
mapping: {
file: "./dist/index.js",
handlers: [
{
kind: CosmosHandlerKind.Block,
handler: "initiateBalancesTable",
},
],
},
},
{
kind: CosmosDatasourceKind.Runtime,
// First block of mainnet is 2115669
Expand Down Expand Up @@ -118,13 +132,6 @@ const project: CosmosProject = {
type: "burn",
},
},
// {
// handler: "handleTransferEvent",
// kind: CosmosHandlerKind.Event,
// filter: {
// type: "transfer",
// },
// },
// Distribution Events
{
handler: "handleBalanceEvent",
Expand Down
16 changes: 15 additions & 1 deletion src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import {
VaultManagerMetricsDaily,
PsmMetricDaily,
ReserveAllocationMetricsDaily,
Balances,
} from "../types";
import { CosmosEvent } from "@subql/types-cosmos";
import { CosmosBlock, CosmosEvent } from "@subql/types-cosmos";
import {
b64encode,
b64decode,
Expand Down Expand Up @@ -230,3 +231,16 @@ export async function handleBalanceEvent(
const formattedAmount = BigInt(Math.round(Number(amount.slice(0, -4))));
await balancesKit.updateBalance(address, formattedAmount, operation);
}

export async function initiateBalancesTable(block: CosmosBlock): Promise<void> {
const newBalance = new Balances(
'agoric1estsewt6jqsx77pwcxkn5ah0jqgu8rhgflwfdl'
);
newBalance.address = 'agoric1estsewt6jqsx77pwcxkn5ah0jqgu8rhgflwfdl';
newBalance.balance = BigInt(999999995000000000);
newBalance.denom = 'ubld';

await newBalance.save();

logger.info(`Balances Table Initiated`);
}

0 comments on commit 80b8891

Please sign in to comment.