Skip to content
Open
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
32 changes: 16 additions & 16 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (db *DB) GetVaultStateByID(id string) (*models.VaultState, error) {
defer cancel()

var vaultState models.VaultState
query := `SELECT current_round, current_round_address, unlocked_balance, locked_balance, stashed_balance, address, latest_block, deployment_date, fossil_client_address, eth_address, option_round_class_hash, alpha, strike_level, auction_duration, round_duration, round_transition_period FROM public."VaultStates" WHERE address=$1`
query := `SELECT current_round, current_round_address, unlocked_balance, locked_balance, stashed_balance, address, latest_block, deployment_date, l1_data_processor_address, eth_address, option_round_class_hash, alpha, strike_level, auction_duration, round_duration, round_transition_period FROM public."VaultStates" WHERE address=$1`

err := db.Pool.QueryRow(ctx, query, id).Scan(
&vaultState.CurrentRound,
Expand All @@ -60,7 +60,7 @@ func (db *DB) GetVaultStateByID(id string) (*models.VaultState, error) {
&vaultState.Address,
&vaultState.LatestBlock,
&vaultState.DeploymentDate,
&vaultState.FossilClientAddress,
&vaultState.L1DataProcessorAddress,
&vaultState.EthAddress,
&vaultState.OptionRoundClassHash,
&vaultState.Alpha,
Expand All @@ -86,16 +86,16 @@ func (db *DB) GetOptionRoundsByVaultAddress(vaultAddress string) ([]*models.Opti
var optionRounds []*models.OptionRound
query :=
`
SELECT
address, vault_address, round_id, cap_level, start_date, end_date, settlement_date,
starting_liquidity, queued_liquidity,remaining_liquidity, unsold_liquidity, available_options, reserve_price,
settlement_price, strike_price, sold_options, clearing_price, state,
SELECT
address, vault_address, round_id, cap_level, start_date, end_date, settlement_date,
starting_liquidity, queued_liquidity,remaining_liquidity, unsold_liquidity, available_options, reserve_price,
settlement_price, strike_price, sold_options, clearing_price, state,
premiums, payout_per_option, deployment_date
FROM
public."Option_Rounds"
WHERE
vault_address = $1
ORDER BY
FROM
public."Option_Rounds"
WHERE
vault_address = $1
ORDER BY
round_id ASC;`

rows, err := db.Pool.Query(context.Background(), query, vaultAddress)
Expand Down Expand Up @@ -154,8 +154,8 @@ func (db *DB) GetBlocks(startTimestamp, endTimestamp, roundDuration uint64) ([]m
default:
samplingRate = 1
}
query := `SELECT block_number, timestamp, basefee, is_confirmed, twelve_min_twap,three_hour_twap,thirty_day_twap
FROM public."blocks"
query := `SELECT block_number, timestamp, basefee, is_confirmed, twelve_min_twap,three_hour_twap,thirty_day_twap
FROM public."blocks"
WHERE timestamp BETWEEN $1 AND $2
AND block_number % $3 = 0
ORDER BY block_number ASC
Expand Down Expand Up @@ -260,7 +260,7 @@ func (db *DB) GetVaultAddresses() ([]string, error) {
var vaultAddresses []string

query := `
SELECT address
SELECT address
FROM "VaultStates" ;`

rows, err := db.Pool.Query(context.Background(), query)
Expand Down Expand Up @@ -306,7 +306,7 @@ func (db *DB) GetLiquidityProviderStateByAddress(address, vaultAddress string) (
// GetOptionBuyerByID retrieves an OptionBuyer record by its Address
func (db *DB) GetOptionBuyerByAddress(address string) ([]*models.OptionBuyer, error) {
var optionBuyers []*models.OptionBuyer
query := `SELECT address, round_address, mintable_options, refundable_amount, has_minted, has_refunded
query := `SELECT address, round_address, mintable_options, refundable_amount, has_minted, has_refunded
FROM public."Option_Buyers" WHERE address=$1`

rows, err := db.Pool.Query(context.Background(), query, address)
Expand Down Expand Up @@ -334,7 +334,7 @@ func (db *DB) GetOptionBuyerByAddress(address string) ([]*models.OptionBuyer, er
}

// Fetch associated bids for this optionBuyer
bidQuery := `SELECT buyer_address, round_address, bid_id, tree_nonce, amount, price
bidQuery := `SELECT buyer_address, round_address, bid_id, tree_nonce, amount, price
FROM public."Bids" WHERE buyer_address=$1 AND round_address=$2`
bidRows, err := db.Pool.Query(context.Background(), bidQuery, optionBuyer.Address, optionBuyer.RoundAddress)

Expand Down
32 changes: 16 additions & 16 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ type OptionRound struct {
}

type VaultState struct {
CurrentRound BigInt `json:"currentRoundId"`
CurrentRoundAddress string `json:"currentRoundAddress"`
UnlockedBalance BigInt `json:"unlockedBalance"`
LockedBalance BigInt `json:"lockedBalance"`
StashedBalance BigInt `json:"stashedBalance"`
Address string `json:"address"`
LatestBlock BigInt `json:"latestBlock"`
DeploymentDate uint64 `json:"deploymentDate"`
FossilClientAddress string `json:"fossilClientAddress"`
EthAddress string `json:"ethAddress"`
OptionRoundClassHash string `json:"optionRoundClassHash"`
Alpha BigInt `json:"alpha"`
StrikeLevel BigInt `json:"strikeLevel"`
AuctionRunTime uint64 `json:"auctionRunTime"`
OptionRunTime uint64 `json:"optionRunTime"`
RoundTransitionPeriod uint64 `json:"roundTransitionPeriod"`
CurrentRound BigInt `json:"currentRoundId"`
CurrentRoundAddress string `json:"currentRoundAddress"`
UnlockedBalance BigInt `json:"unlockedBalance"`
LockedBalance BigInt `json:"lockedBalance"`
StashedBalance BigInt `json:"stashedBalance"`
Address string `json:"address"`
LatestBlock BigInt `json:"latestBlock"`
DeploymentDate uint64 `json:"deploymentDate"`
L1DataProcessorAddress string `json:"l1DataProcessorAddress"`
EthAddress string `json:"ethAddress"`
OptionRoundClassHash string `json:"optionRoundClassHash"`
Alpha BigInt `json:"alpha"`
StrikeLevel BigInt `json:"strikeLevel"`
AuctionRunTime uint64 `json:"auctionRunTime"`
OptionRunTime uint64 `json:"optionRunTime"`
RoundTransitionPeriod uint64 `json:"roundTransitionPeriod"`
}

type LiquidityProviderState struct {
Expand Down
34 changes: 17 additions & 17 deletions models/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ func (lps *LiquidityProviderState) UnmarshalJSON(data []byte) error {
func (vs *VaultState) UnmarshalJSON(data []byte) error {
// Auxiliary struct to map JSON keys
aux := struct {
CurrentRound BigInt `json:"current_round"`
CurrentRoundAddress string `json:"current_round_address"`
UnlockedBalance BigInt `json:"unlocked_balance"`
LockedBalance BigInt `json:"locked_balance"`
StashedBalance BigInt `json:"stashed_balance"`
Address string `json:"address"`
LatestBlock BigInt `json:"latest_block"`
DeploymentDate uint64 `json:"deployment_date"`
FossilClientAddress string `json:"fossil_client_address"`
EthAddress string `json:"eth_address"`
OptionRoundClassHash string `json:"option_round_class_hash"`
Alpha BigInt `json:"alpha"`
StrikeLevel BigInt `json:"strike_level"`
AuctionRunTime uint64 `json:"auction_duration"`
OptionRunTime uint64 `json:"round_duration"`
RoundTransitionPeriod uint64 `json:"round_transition_period"`
CurrentRound BigInt `json:"current_round"`
CurrentRoundAddress string `json:"current_round_address"`
UnlockedBalance BigInt `json:"unlocked_balance"`
LockedBalance BigInt `json:"locked_balance"`
StashedBalance BigInt `json:"stashed_balance"`
Address string `json:"address"`
LatestBlock BigInt `json:"latest_block"`
DeploymentDate uint64 `json:"deployment_date"`
L1DataProcessorAddress string `json:"l1_data_processor_address"`
EthAddress string `json:"eth_address"`
OptionRoundClassHash string `json:"option_round_class_hash"`
Alpha BigInt `json:"alpha"`
StrikeLevel BigInt `json:"strike_level"`
AuctionRunTime uint64 `json:"auction_duration"`
OptionRunTime uint64 `json:"round_duration"`
RoundTransitionPeriod uint64 `json:"round_transition_period"`
}{}

// Unmarshal into the auxiliary struct
Expand All @@ -67,7 +67,7 @@ func (vs *VaultState) UnmarshalJSON(data []byte) error {
vs.Address = aux.Address
vs.LatestBlock = aux.LatestBlock
vs.DeploymentDate = aux.DeploymentDate
vs.FossilClientAddress = aux.FossilClientAddress
vs.L1DataProcessorAddress = aux.L1DataProcessorAddress
vs.EthAddress = aux.EthAddress
vs.OptionRoundClassHash = aux.OptionRoundClassHash
vs.Alpha = aux.Alpha
Expand Down