Skip to content

Commit

Permalink
Merge branch 'main' into rs-index-wallet-balances
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed May 29, 2024
2 parents f3896d4 + 49d5bd3 commit d9e5b0c
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 94 deletions.
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120,
"overrides": [
{
"files": ".prettierrc",
"options": { "parser": "json" }
}
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"pub": "subql publish",
"codegen": "subql codegen",
"start:docker": "docker-compose pull && docker-compose up --remove-orphans",
"dev": "network=local && subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans",
"dev": "subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans",
"prepack": "rm -rf dist && npm run build",
"test": "jest",
"subql": "subql codegen --help",
Expand Down
40 changes: 20 additions & 20 deletions project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,26 @@ const project: CosmosProject = {
// },
// },
// },
{
handler: "handleIbcSendPacketEvent",
kind: CosmosHandlerKind.Event,
filter: {
type: "send_packet",
messageFilter: {
type: "/ibc.applications.transfer.v1.MsgTransfer",
},
},
},
{
handler: "handleIbcReceivePacketEvent",
kind: CosmosHandlerKind.Event,
filter: {
type: "recv_packet",
messageFilter: {
type: "/ibc.core.channel.v1.MsgRecvPacket",
},
},
},
// {
// handler: "handleIbcSendPacketEvent",
// kind: CosmosHandlerKind.Event,
// filter: {
// type: "send_packet",
// messageFilter: {
// type: "/ibc.applications.transfer.v1.MsgTransfer",
// },
// },
// },
// {
// handler: "handleIbcReceivePacketEvent",
// kind: CosmosHandlerKind.Event,
// filter: {
// type: "recv_packet",
// messageFilter: {
// type: "/ibc.core.channel.v1.MsgRecvPacket",
// },
// },
// },
{
handler: "handleStateChangeEvent",
kind: CosmosHandlerKind.Event,
Expand Down
7 changes: 7 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,10 @@ type VaultStatesDaily @entity {
liquidated: BigInt!
liquidatedClosed: BigInt!
}

type Balances @entity {
id: ID!
address: String @index
balance: BigInt
denom: String @index
}
1 change: 1 addition & 0 deletions src/mappings/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const VAULT_STATES = {
CLOSED: 'closed',
LIQUIDATING: 'liquidating',
LIQUIDATED: 'liquidated',
LIQUIDATED_CLOSED: 'liquidatedClosed',
};

export const VALUE_KEY = b64encode('value');
Expand Down
4 changes: 2 additions & 2 deletions src/mappings/events/boardAux.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BoardAux } from "../../types";
import { BoardAux } from '../../types';

export const boardAuxEventKit = (block: any, data: any, module: string, path: string) => {
async function saveBoardAux(payload: any): Promise<Promise<any>[]> {
Expand All @@ -8,7 +8,7 @@ export const boardAuxEventKit = (block: any, data: any, module: string, path: st
block.block.header.time as any,
payload.allegedName,
payload.displayInfo.assetKind,
payload.displayInfo.decimalPlaces ?? 0
payload.displayInfo.decimalPlaces ?? 0,
).save();

return [boardAux];
Expand Down
15 changes: 5 additions & 10 deletions src/mappings/events/priceFeed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OraclePrice, OraclePriceDaily } from "../../types";
import { dateToDayKey } from "../utils";
import { OraclePrice, OraclePriceDaily } from '../../types';
import { dateToDayKey } from '../utils';

export const priceFeedEventKit = (block: any, data: any, module: string, path: string) => {
async function savePriceFeed(payload: any): Promise<Promise<any>[]> {
Expand All @@ -22,7 +22,7 @@ export const priceFeedEventKit = (block: any, data: any, module: string, path: s
BigInt(payload.amountIn.__value),
BigInt(payload.amountOut.__value),
typeInName,
typeOutName
typeOutName,
).save();

return [oraclePrice, oraclePriceDaily];
Expand All @@ -49,15 +49,10 @@ export const priceFeedEventKit = (block: any, data: any, module: string, path: s
}

async function getOraclePriceDaily(feedName: string, dateKey: number): Promise<OraclePriceDaily> {
const id = feedName + ":" + dateKey.toString();
const id = feedName + ':' + dateKey.toString();
let state = await OraclePriceDaily.get(id);
if (!state) {
state = new OraclePriceDaily(
id,
dateKey,
BigInt(data.blockHeight),
new Date(block.block.header.time as any)
);
state = new OraclePriceDaily(id, dateKey, BigInt(data.blockHeight), new Date(block.block.header.time as any));
}
return state;
}
Expand Down
28 changes: 17 additions & 11 deletions src/mappings/events/psm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PsmGovernance, PsmMetrics, PsmMetricsDaily } from "../../types";
import { dateToDayKey } from "../utils";
import { PsmGovernance, PsmMetrics, PsmMetricsDaily } from '../../types';
import { dateToDayKey } from '../utils';

export const psmEventKit = (block: any, data: any, module: string, path: string) => {
async function savePsmMetrics(payload: any): Promise<Promise<any>[]> {
Expand All @@ -8,13 +8,13 @@ export const psmEventKit = (block: any, data: any, module: string, path: string)
path,
BigInt(data.blockHeight),
block.block.header.time as any,
path.split(".")[3],
path.split(".")[3],
path.split('.')[3],
path.split('.')[3],
BigInt(payload.anchorPoolBalance.__value),
BigInt(payload.feePoolBalance.__value),
BigInt(payload.mintedPoolBalance.__value),
BigInt(payload.totalAnchorProvided.__value),
BigInt(payload.totalMintedProvided.__value)
BigInt(payload.totalMintedProvided.__value),
).save();

return [psmMetric, psmMetricDaily];
Expand All @@ -25,7 +25,7 @@ export const psmEventKit = (block: any, data: any, module: string, path: string)

let state = await getPsmMetricDaily(dateKey);

state.denom = path.split(".")[3];
state.denom = path.split('.')[3];

state.anchorPoolBalanceLast = BigInt(payload.anchorPoolBalance.__value);
state.feePoolBalanceLast = BigInt(payload.feePoolBalance.__value);
Expand All @@ -39,10 +39,16 @@ export const psmEventKit = (block: any, data: any, module: string, path: string)
}

async function getPsmMetricDaily(dateKey: number): Promise<PsmMetricsDaily> {
const id = path + ":" + dateKey.toString();
const id = path + ':' + dateKey.toString();
let state = await PsmMetricsDaily.get(id);
if (!state) {
state = new PsmMetricsDaily(id, path, dateKey, BigInt(data.blockHeight), new Date(block.block.header.time as any));
state = new PsmMetricsDaily(
id,
path,
dateKey,
BigInt(data.blockHeight),
new Date(block.block.header.time as any),
);
}
return state;
}
Expand All @@ -52,13 +58,13 @@ export const psmEventKit = (block: any, data: any, module: string, path: string)
path,
BigInt(data.blockHeight),
block.block.header.time as any,
path.split(".")[3],
path.split(".")[3],
path.split('.')[3],
path.split('.')[3],
BigInt(payload.current.MintLimit.value.__value),
BigInt(payload.current.GiveMintedFee?.value?.denominator?.__value ?? 0),
BigInt(payload.current.GiveMintedFee?.value?.numerator?.__value ?? 0),
BigInt(payload.current.WantMintedFee?.value?.denominator?.__value ?? 0),
BigInt(payload.current.WantMintedFee?.value?.numerator?.__value ?? 0)
BigInt(payload.current.WantMintedFee?.value?.numerator?.__value ?? 0),
).save();
return [psmGovernance];
}
Expand Down
23 changes: 14 additions & 9 deletions src/mappings/events/reserves.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { promises } from "dns";
import { ReserveAllocationMetrics, ReserveAllocationMetricsDaily, ReserveMetrics } from "../../types";
import { dateToDayKey, extractBrand } from "../utils";
import { promises } from 'dns';
import { ReserveAllocationMetrics, ReserveAllocationMetricsDaily, ReserveMetrics } from '../../types';
import { dateToDayKey, extractBrand } from '../utils';

export const reservesEventKit = (block: any, data: any, module: string, path: string) => {
async function saveReserveMetrics(payload: any): Promise<Promise<any>[]> {
Expand All @@ -11,7 +11,7 @@ export const reservesEventKit = (block: any, data: any, module: string, path: st
block.block.header.time as any,
BigInt(payload.shortfallBalance.__value),
BigInt(payload.totalFeeBurned.__value),
BigInt(payload.totalFeeMinted.__value)
BigInt(payload.totalFeeMinted.__value),
);
promises.push(reserveMetric.save());

Expand All @@ -30,7 +30,7 @@ export const reservesEventKit = (block: any, data: any, module: string, path: st
brand,
key,
BigInt(allocation.__value),
reserveMetric.id
reserveMetric.id,
);

promises.push(reserveAllocationMetric.save());
Expand All @@ -40,7 +40,12 @@ export const reservesEventKit = (block: any, data: any, module: string, path: st
return promises;
}

async function saveReserveAllocationMetricDaily(brand: string, payload: any, allocation: any, key: string): Promise<any> {
async function saveReserveAllocationMetricDaily(
brand: string,
payload: any,
allocation: any,
key: string,
): Promise<any> {
const dateKey = dateToDayKey(block.block.header.time);

let state = await getReserveAllocationMetricDaily(brand, dateKey);
Expand All @@ -54,17 +59,17 @@ export const reservesEventKit = (block: any, data: any, module: string, path: st

async function getReserveAllocationMetricDaily(
brand: string,
dateKey: number
dateKey: number,
): Promise<ReserveAllocationMetricsDaily> {
const id = brand + ":" + dateKey.toString();
const id = brand + ':' + dateKey.toString();
let state = await ReserveAllocationMetricsDaily.get(id);
if (!state) {
state = new ReserveAllocationMetricsDaily(
id,
brand,
dateKey,
BigInt(data.blockHeight),
new Date(block.block.header.time as any)
new Date(block.block.header.time as any),
);
}
return state;
Expand Down
Loading

0 comments on commit d9e5b0c

Please sign in to comment.