Skip to content

Commit

Permalink
Prettify code
Browse files Browse the repository at this point in the history
  • Loading branch information
toliaqat committed May 7, 2024
1 parent 71d8a4a commit fbd5e35
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 135 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" }
}
]
}
86 changes: 43 additions & 43 deletions src/mappings/constants.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
import { b64encode } from "./utils";
import { b64encode } from './utils';

export const EVENT_TYPES = {
ACTIVE_PROPOSAL: "active_proposal",
BURN: "burn",
COIN_RECEIVED: "coin_received",
COIN_SPENT: "coin_spent",
COINBASE: "coinbase",
COMMISSION: "commission",
MESSAGE: "message",
MINT: "mint",
PROPOSAL_DEPOSIT: "proposal_deposit",
PROPOSAL_VOTE: "proposal_vote",
PROPOSER_REWARD: "proposer_reward",
REWARDS: "rewards",
STATE_CHANGE: "state_change",
STORAGE: "storage",
SUBMIT_PROPOSAL: "submit_proposal",
TRANSFER: "transfer",
SEND_PACKET: "send_packet",
RECEIVE_PACKET: "recv_packet",
IBC_TRANSFER: "ibc_transfer",
FUNGIBLE_TOKEN_PACKET: "fungible_token_packet",
ACTIVE_PROPOSAL: 'active_proposal',
BURN: 'burn',
COIN_RECEIVED: 'coin_received',
COIN_SPENT: 'coin_spent',
COINBASE: 'coinbase',
COMMISSION: 'commission',
MESSAGE: 'message',
MINT: 'mint',
PROPOSAL_DEPOSIT: 'proposal_deposit',
PROPOSAL_VOTE: 'proposal_vote',
PROPOSER_REWARD: 'proposer_reward',
REWARDS: 'rewards',
STATE_CHANGE: 'state_change',
STORAGE: 'storage',
SUBMIT_PROPOSAL: 'submit_proposal',
TRANSFER: 'transfer',
SEND_PACKET: 'send_packet',
RECEIVE_PACKET: 'recv_packet',
IBC_TRANSFER: 'ibc_transfer',
FUNGIBLE_TOKEN_PACKET: 'fungible_token_packet',
};

export const VAULT_STATES = {
LIQUIDATING: "liquidating",
LIQUIDATED: "liquidated",
LIQUIDATING: 'liquidating',
LIQUIDATED: 'liquidated',
};

export const VALUE_KEY = b64encode("value");
export const STORE_KEY = b64encode("store");
export const VSTORAGE_VALUE = b64encode("vstorage");
export const KEY_KEY = b64encode("key");
export const STORE_NAME_KEY = b64encode("store_name");
export const SUBKEY_KEY = b64encode("store_subkey");
export const UNPROVED_VALUE_KEY = b64encode("unproved_value");
export const PACKET_DATA_KEY = "packet_data";
export const PACKET_SRC_CHANNEL_KEY = "packet_src_channel";
export const PACKET_DST_CHANNEL_KEY = "packet_dst_channel";
export const PACKET_SRC_PORT_KEY = "packet_src_port";
export const PACKET_DST_PORT_KEY = "packet_dst_port";
export const ACTION_KEY = b64encode("action");
export const IBC_MESSAGE_TRANSFER_VALUE = b64encode("/ibc.applications.transfer.v1.MsgTransfer");
export const IBC_MESSAGE_RECEIVE_PACKET_VALUE = b64encode("/ibc.core.channel.v1.MsgRecvPacket");
export const RECEPIENT_KEY = b64encode("recipient");
export const SENDER_KEY = b64encode("sender");
export const RECEIVER_KEY = b64encode("receiver");
export const AMOUNT_KEY = b64encode("amount");
export const TRANSFER_PORT_VALUE = "transfer";
export const VALUE_KEY = b64encode('value');
export const STORE_KEY = b64encode('store');
export const VSTORAGE_VALUE = b64encode('vstorage');
export const KEY_KEY = b64encode('key');
export const STORE_NAME_KEY = b64encode('store_name');
export const SUBKEY_KEY = b64encode('store_subkey');
export const UNPROVED_VALUE_KEY = b64encode('unproved_value');
export const PACKET_DATA_KEY = 'packet_data';
export const PACKET_SRC_CHANNEL_KEY = 'packet_src_channel';
export const PACKET_DST_CHANNEL_KEY = 'packet_dst_channel';
export const PACKET_SRC_PORT_KEY = 'packet_src_port';
export const PACKET_DST_PORT_KEY = 'packet_dst_port';
export const ACTION_KEY = b64encode('action');
export const IBC_MESSAGE_TRANSFER_VALUE = b64encode('/ibc.applications.transfer.v1.MsgTransfer');
export const IBC_MESSAGE_RECEIVE_PACKET_VALUE = b64encode('/ibc.core.channel.v1.MsgRecvPacket');
export const RECEPIENT_KEY = b64encode('recipient');
export const SENDER_KEY = b64encode('sender');
export const RECEIVER_KEY = b64encode('receiver');
export const AMOUNT_KEY = b64encode('amount');
export const TRANSFER_PORT_VALUE = 'transfer';
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 fbd5e35

Please sign in to comment.