Skip to content

Commit

Permalink
Merge pull request #2442 from fluidity-money/develop-fix-solana-and-e…
Browse files Browse the repository at this point in the history
…xtra-logging

Replace the locations of the accounts for testing a Mint
  • Loading branch information
af-afk authored Dec 11, 2023
2 parents fa3c0dc + b280587 commit 5f41fff
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 9 deletions.
9 changes: 8 additions & 1 deletion cmd/connector-common-winners-timescale/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
package main

import (
"github.com/fluidity-money/fluidity-app/lib/databases/postgres/solana"
database "github.com/fluidity-money/fluidity-app/lib/databases/timescale/winners"
queue "github.com/fluidity-money/fluidity-app/lib/queues/winners"
)

func main() {
queue.WinnersAll(database.InsertWinner)
go queue.WinnersEthereum(database.InsertWinner)

queue.WinnersSolana(func(winner queue.Winner) {
winningSignature := solana.GetIntermediateWinner(winner.TransactionHash)
winner.SendTransactionHash = winningSignature
database.InsertWinner(winner)
})
}
15 changes: 13 additions & 2 deletions cmd/microservice-solana-transactions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,27 @@ func main() {
for i, transaction := range block.Transactions {
apps := solanaLib.ClassifyApplication(transaction, applications)

signature := transaction.Transaction.Signatures[0]

if len(apps) == 0 {
log.Debugf(
"Transaction position %d block %v didn't have an application classified!",
"Transaction signature %v position %d block %v didn't have an application classified!",
signature,
i,
slot.Slot,
)

continue
}

log.Debugf(
`Transaction signature %v position %d block %v had "%v" applications classified!`,
signature,
i,
slot.Slot,
apps,
)

transactionFeeUsd := new(big.Rat).SetUint64(transaction.Meta.Fee)

transactionFeeUsd.Quo(transactionFeeUsd, LamportDecimalPlacesRat)
Expand All @@ -143,7 +154,7 @@ func main() {
transactionFeeUsd.Mul(transactionFeeUsd, solanaPrice)

parsed := worker.SolanaApplicationTransaction{
Signature: transaction.Transaction.Signatures[0],
Signature: signature,
Result: transaction,
AdjustedFee: transactionFeeUsd,
Applications: apps,
Expand Down
7 changes: 7 additions & 0 deletions cmd/microservice-solana-user-actions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ func main() {

fluidityOwners := make([]string, len(accountKeys))

log.Debugf(
"Token balances for transaction signature %v: %v",
signature,
accountKeys,
)

for _, bal := range tokenBalances {
if bal.Mint == fluidityTokenMint {
fluidityOwners[bal.AccountIndex] = bal.Owner
Expand Down Expand Up @@ -135,6 +141,7 @@ func main() {
accountKeys,
fluidityOwners,
tokenDetails,
applications,
)

case SplProgramId:
Expand Down
23 changes: 17 additions & 6 deletions cmd/microservice-solana-user-actions/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func tokenIsMintEvent(senderAddress, recipientAddress, fluidityTokenMintAddress,
return false
}

func processFluidityTransaction(transactionHash string, instruction solana.TransactionInstruction, accounts, fluidityOwners []string, tokenDetails token_details.TokenDetails) (winner1 *winners.Winner, winner2 *winners.Winner, swapWrap *user_actions.UserAction, swapUnwrap *user_actions.UserAction, err error) {
func processFluidityTransaction(transactionHash string, instruction solana.TransactionInstruction, accounts, fluidityOwners []string, tokenDetails token_details.TokenDetails, applications []applications.Application) (winner1 *winners.Winner, winner2 *winners.Winner, swapWrap *user_actions.UserAction, swapUnwrap *user_actions.UserAction, err error) {

fluidityTransaction, err := fluidity.DecodeFluidityInstruction(instruction.Data)

Expand All @@ -75,19 +75,22 @@ func processFluidityTransaction(transactionHash string, instruction solana.Trans

if fluidityTransaction.Payout != nil {
var (
winnerAIndex = instruction.Accounts[5]
winnerBIndex = instruction.Accounts[6]
winnerAIndex = instruction.Accounts[7]
winnerBIndex = instruction.Accounts[8]
)

// payout for different token
if fluidityOwners[winnerAIndex] == "" {
if ind := fluidityOwners[winnerAIndex]; ind == "" {
log.App(func(k *log.Log) {
k.Format(
"Got a winning payout, but token mint was wrong, transaction hash %v, winnerAIndex %v, winnerBIndex %v, fluidity owners %v",
`Got a winning payout, but token mint was wrong, transaction hash %v, winnerAIndex %v, winnerBIndex %v, fluidity owners %v, fluidity owners length %v, content when accessing winnerAIndex "%v", instruction accounts "%v"`,
transactionHash,
winnerAIndex,
winnerBIndex,
fluidityOwners,
len(fluidityOwners),
ind,
instruction.Accounts,
)
})
return nil, nil, nil, nil, nil
Expand All @@ -107,8 +110,14 @@ func processFluidityTransaction(transactionHash string, instruction solana.Trans
var (
winner1_ = winner_
winner2_ = winner_

application string
)

if len(applications) > 0 {
application = applications[0].String()
}

winningAmount1 := new(big.Int).Mul(winningAmount, Winner1Split)

winningAmount1.Quo(winningAmount1, winner10Split)
Expand All @@ -119,6 +128,7 @@ func processFluidityTransaction(transactionHash string, instruction solana.Trans

winner1_.WinnerAddress = accounts[winnerAIndex]
winner1_.SolanaWinnerOwnerAddress = fluidityOwners[winnerAIndex]
winner1_.Application = application

winner1_.WinningAmount = misc.NewBigIntFromInt(*winningAmount1)
winner1_.RewardType = "send"
Expand All @@ -127,7 +137,8 @@ func processFluidityTransaction(transactionHash string, instruction solana.Trans
winner2_.SolanaWinnerOwnerAddress = fluidityOwners[winnerBIndex]

winner2_.WinningAmount = misc.NewBigIntFromInt(*winningAmount2)
winner2.RewardType = "receive"
winner2_.RewardType = "receive"
winner2_.Application = application

winner1 = &winner1_
winner2 = &winner2_
Expand Down
9 changes: 9 additions & 0 deletions common/solana/transfers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package solana

import (
"github.com/fluidity-money/fluidity-app/common/solana/applications"
"github.com/fluidity-money/fluidity-app/lib/log"
"github.com/fluidity-money/fluidity-app/lib/types/solana"
)

Expand All @@ -14,6 +15,14 @@ func ClassifyApplication(transaction solana.TransactionResult, apps map[string]a

foundApps := make(map[applications.Application]struct{}, 0)

log.Debug(func(k *log.Log) {
k.Format(
`About to search apps "%v" for account keys "%v"`,
apps,
accounts,
)
})

for _, account := range accounts {
app, exists := apps[account]
if !exists {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

-- migrate:up

CREATE TABLE solana_intermediate_winners (
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
winning_signature VARCHAR NOT NULL, -- corresponds to winners send_transaction_hash
payout_signature VARCHAR NOT NULL -- corresponds to winners transaction_hash
);

-- migrate:down

DROP TABLE solana_intermediate_winners;
57 changes: 57 additions & 0 deletions lib/databases/postgres/solana/intermediate-winners.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2022 Fluidity Money. All rights reserved. Use of this
// source code is governed by a GPL-style license that can be found in the
// LICENSE.md file.

package solana

import (
"fmt"

"github.com/fluidity-money/fluidity-app/lib/log"
"github.com/fluidity-money/fluidity-app/lib/postgres"
)

// GetIntermediateWinner using a payout transaction signature
func GetIntermediateWinner(payoutSignature string) (winningSignature string) {
databaseClient := postgres.Client()

statementText := fmt.Sprintf(
`SELECT winning_signature
FROM %s
WHERE payout_signature = $1;`,

TableIntermediateWinners,
)

row := databaseClient.QueryRow(statementText, payoutSignature)

if err := row.Err(); err != nil {
log.Fatal(func(k *log.Log) {
k.Context = Context

k.Format(
"Failed to query for an intermediate winner with payout sig %v",
payoutSignature,
)

k.Payload = err
})
}

err := row.Scan(&winningSignature)

if err != nil {
log.Fatal(func(k *log.Log) {
k.Context = Context

k.Format(
"Failed to scan the intermediate winners table for payout signature %v",
payoutSignature,
)

k.Payload = err
})
}

return winningSignature
}
5 changes: 5 additions & 0 deletions lib/databases/postgres/solana/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ const (

// TableMintLimits is used to store each token's per user mint limit
TableMintLimits = `solana_mint_limits`

// TableIntermediateWinners to use to track winners that were
// paid out and need to be linked in the winners database to the
// winning transaction
TableIntermediateWinners = `solana_intermediate_winners`
)

0 comments on commit 5f41fff

Please sign in to comment.