Skip to content

Commit

Permalink
feat: fetching account balance for initial accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed May 29, 2024
1 parent 31796b1 commit f3896d4
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 275 deletions.
13 changes: 0 additions & 13 deletions genesis-local.json

This file was deleted.

130 changes: 0 additions & 130 deletions genesis-main.json

This file was deleted.

54 changes: 40 additions & 14 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,40 @@ type Vault @entity {
id: ID!
blockHeight: BigInt!
blockTime: Date!
balance: BigInt
balance: BigInt # use lockedValue instead
lockedValue: BigInt
coin: String @index # use denom instead
denom: String @index
debt: BigInt
state: String
wallet: Wallet!
liquidatingAt: Date
liquidatedAt: Date
liquidated: Boolean
}

type VaultManagerGovernanceJson @jsonField {
liquidationMarginDenominator: BigInt
liquidationMarginNumerator: BigInt
}

type OraclePriceJson @jsonField {
typeInAmount: BigInt
typeOutAmount: BigInt
}

type VaultLiquidation @entity {
id: ID!
blockHeight: BigInt!
blockTime: Date!
balance: BigInt # use lockedValue instead
lockedValue: BigInt
coin: String @index # use denom instead
denom: String @index
debt: BigInt
state: String
wallet: Wallet!
currentState: Vault!
liquidatingState: VaultLiquidation!
vaultManagerGovernance: VaultManagerGovernanceJson
oraclePrice: OraclePriceJson
}

type VaultManagerMetrics @entity {
Expand Down Expand Up @@ -242,6 +266,10 @@ type ReserveMetrics @entity {
allocations: [ReserveAllocationMetrics] @derivedFrom(field: "reserveMetrics")
}

type Account @entity {
id: ID!
}

type IBCChannel @entity {
id: ID!
channelName: String!
Expand All @@ -265,15 +293,13 @@ type IBCTransfer @entity {
transferType: TransferType!
}

type Balance @entity {
type VaultStatesDaily @entity {
id: ID!
address: String @index
balance: BigInt
denom: String @index
account: Account!
}

type Account @entity {
id: ID!
balances: [Balance] @derivedFrom(field: "account")
blockHeightLast: BigInt!
blockTimeLast: Date!
active: BigInt!
closed: BigInt!
liquidating: BigInt!
liquidated: BigInt!
liquidatedClosed: BigInt!
}
96 changes: 51 additions & 45 deletions src/mappings/constants.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,56 @@
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",
ACTIVE: 'active',
CLOSED: 'closed',
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 BALANCE_FIELDS = {
amount: 'amount',
// Bank Events
Expand All @@ -36,33 +59,16 @@ export const BALANCE_FIELDS = {
coin_spent: 'spender',
transfer_recipient: 'recipient',
transfer_sender: 'sender',
burn: "burner",
burn: 'burner',
// Distribution Events
rewards: 'validator',
commission: 'validator',
proposer_reward: 'validator',
withdraw_rewards: 'validator',
withdraw_commission: 'validator',

};

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 FETCH_ACCOUNTS_URL =
'http://localhost:1317/cosmos/auth/v1beta1/accounts';
export const GET_FETCH_BALANCE_URL = (address: string) =>
`http://localhost:1317/cosmos/bank/v1beta1/balances/${address}`;
44 changes: 44 additions & 0 deletions src/mappings/custom-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export type Balance = {
denom: string;
amount: string;
};

interface PubKey {
'@type': string;
key: string;
}

export type BaseAccount = {
'@type': string;
address: string;
pub_key: PubKey | null;
account_number: string;
sequence: string;
};

export type ModuleAccount = {
'@type': string;
base_account: {
address: string;
pub_key: PubKey | null;
account_number: string;
sequence: string;
};
name: string;
permissions: string[];
};

type Pagination = {
next_key: string | null;
total: string;
};

export type BalancesResponse = {
balances: Balance[];
pagination: Pagination;
};

export type AccountsResponse = {
accounts: (BaseAccount | ModuleAccount)[];
pagination: Pagination;
};
Loading

0 comments on commit f3896d4

Please sign in to comment.