Skip to content

Commit

Permalink
Merge pull request #2460 from fluidity-money/develop-adjust-airdrop-t…
Browse files Browse the repository at this point in the history
…o-v2

Initial changes to support airdrop v2
  • Loading branch information
af-afk authored Jan 10, 2024
2 parents c2b769a + 86fb946 commit de9843e
Show file tree
Hide file tree
Showing 92 changed files with 2,081 additions and 815 deletions.
1 change: 1 addition & 0 deletions automation/fluidity/website/mainnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SERVICES:
NEXT_PUBLIC_FLU_SPLIT_BROWSER_KEY: s7ovhvrpv77htn8aqlf2irirnll9ofvr07be
NEXT_PUBLIC_FLU_GTAG_ID: G-EF68MNJRJ7
NEXT_PUBLIC_FLU_GTM_ID: GTM-W7QJGR2
NEXT_PUBLIC_FLU_HASURA_URL: https://fluidity.hasura.app/v1/graphql

DOCKER_ARGS:
SECRET_FLU_SENTRY_DSN: /fluidity/frontend/sentryURL
Expand Down
4 changes: 1 addition & 3 deletions cmd/connector-common-lootboxes-timescale/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ import (
)

func main() {
queue.LootboxesAll(func(lootbox lootboxes.Lootbox) {
lootboxes.InsertLootbox(lootbox)
})
queue.LootboxesAll(lootboxes.InsertLootbox)
}
2 changes: 1 addition & 1 deletion cmd/connector-common-winners-timescale/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Winners to Timescale connector

Write winners received via AMQP to Timescale.
Write winners received via AMQP to Timescale. Also tracks epochs.

## Environment variables

Expand Down
70 changes: 69 additions & 1 deletion cmd/connector-common-winners-timescale/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,85 @@
package main

import (
"math"
"math/big"

"github.com/fluidity-money/fluidity-app/lib/databases/postgres/solana"
"github.com/fluidity-money/fluidity-app/lib/databases/timescale/lootboxes"
database "github.com/fluidity-money/fluidity-app/lib/databases/timescale/winners"
"github.com/fluidity-money/fluidity-app/lib/log"
queue "github.com/fluidity-money/fluidity-app/lib/queues/winners"
"github.com/fluidity-money/fluidity-app/lib/types/network"
)

// lootboxUpdateTrackedRewardAmounts by destructuring the winner, and
// upserting it into the database. queries the current epoch to get what
// should be used.
func lootboxUpdateTrackedRewardAmounts(winner queue.Winner) {
var (
network_ = winner.Network
tokenDetails = winner.TokenDetails
application = winner.Application
amountWon = &winner.WinningAmount.Int
)

_, lootboxHasBegun, lootboxCurrentEpoch, _ := lootboxes.GetLootboxConfig()

if !lootboxHasBegun {
log.Debug(func(k *log.Log) {
k.Message = "Lootbox not running! Ignoring a winner to be inserted in the lootbox tracked rewards!"
})

return
}

var (
tokenShortName = tokenDetails.TokenShortName
tokenDecimals = tokenDetails.TokenDecimals
)

winnerAddress := ""

// need to set it to the owner of the ATA if we're on solana!

switch network_ {
case network.NetworkSolana:
winnerAddress = winner.SolanaWinnerOwnerAddress

default:
winnerAddress = winner.WinnerAddress
}

// we can normalise this and store it in the database to avoid an
// extra check, as we can afford some loss in this calculation.

decimals := math.Pow10(tokenDecimals)

amountNormal := new(big.Rat).SetInt(amountWon)
amountNormal.Quo(amountNormal, new(big.Rat).SetInt64(int64(decimals)))

amountNormalFloat, _ := amountNormal.Float64()

lootboxes.UpdateOrInsertAmountsRewarded(
network_,
lootboxCurrentEpoch,
tokenShortName,
amountNormalFloat, // amount normal lossy
winnerAddress,
application,
)
}

func main() {
go queue.WinnersEthereum(database.InsertWinner)
go queue.WinnersEthereum(func(winner queue.Winner) {
lootboxUpdateTrackedRewardAmounts(winner)
database.InsertWinner(winner)
})

queue.WinnersSolana(func(winner queue.Winner) {
winningSignature := solana.GetIntermediateWinner(winner.TransactionHash)
winner.SendTransactionHash = winningSignature
lootboxUpdateTrackedRewardAmounts(winner)
database.InsertWinner(winner)
})
}
73 changes: 49 additions & 24 deletions cmd/microservice-ethereum-create-transaction-lootboxes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,31 @@ import (
"math/big"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
libEthereum "github.com/fluidity-money/fluidity-app/common/ethereum"
ethereumApps "github.com/fluidity-money/fluidity-app/common/ethereum/applications"
database "github.com/fluidity-money/fluidity-app/lib/databases/timescale/lootboxes"
user_actions "github.com/fluidity-money/fluidity-app/lib/databases/timescale/user-actions"
"github.com/fluidity-money/fluidity-app/lib/log"
"github.com/fluidity-money/fluidity-app/lib/queue"
lootboxes_queue "github.com/fluidity-money/fluidity-app/lib/queues/lootboxes"
winners_queue "github.com/fluidity-money/fluidity-app/lib/queues/winners"
"github.com/fluidity-money/fluidity-app/lib/types/applications"
"github.com/fluidity-money/fluidity-app/lib/types/ethereum"
"github.com/fluidity-money/fluidity-app/lib/types/lootboxes"
"github.com/fluidity-money/fluidity-app/lib/types/misc"
"github.com/fluidity-money/fluidity-app/lib/types/worker"
"github.com/fluidity-money/fluidity-app/lib/util"

libEthereum "github.com/fluidity-money/fluidity-app/common/ethereum"
"github.com/fluidity-money/fluidity-app/common/ethereum/applications"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
)

const (
// EnvTokensList to relate the received token names to a contract address
// of the form ADDR1:TOKEN1:DECIMALS1,ADDR2:TOKEN2:DECIMALS2,...
EnvTokensList = "FLU_ETHEREUM_TOKENS_LIST"

// EnvGethHttpUrl to use when performing RPC requests
EnvGethHttpUrl = `FLU_ETHEREUM_HTTP_URL`
)
Expand Down Expand Up @@ -85,6 +87,32 @@ func main() {
tokenShortName = tokenDetails.TokenShortName
)

programFound, hasBegun, currentEpoch, _ := database.GetLootboxConfig()

// check that the lootbox is enabled, and that it's also
// running. logs separately if either fail. if the
// campaign has begun but isn't in progress, then we
// should die! that means that something was processed
// weirdly.

switch false {
case programFound:
log.App(func(k *log.Log) {
k.Message = "No lootbox epoch found, skipping a request to track a winner!"
})

return

case hasBegun:
log.Fatal(func(k *log.Log) {
k.Message = "Lootbox epoch that was found is not running! Terminating on request to track a winner!"
})

return
}

log.Debugf("Lootbox current epoch running is %v!", currentEpoch)

// don't track fluidification
if winner.RewardType != "send" {
log.Debug(func(k *log.Log) {
Expand Down Expand Up @@ -114,7 +142,11 @@ func main() {

// fetch parameters to call GetApplicationFee
// wait for transaction to be mined before fetching receipt
transaction, isPending, err := ethClient.TransactionByHash(context.Background(), common.HexToHash(transactionHash))

transaction, isPending, err := ethClient.TransactionByHash(
context.Background(),
common.HexToHash(transactionHash),
)

if err != nil {
log.Fatal(func(k *log.Log) {
Expand Down Expand Up @@ -172,7 +204,14 @@ func main() {

inputData := transaction.Data()

feeData, _, _, err := ethereumApps.GetApplicationFee(applicationTransfer, ethClient, fluidTokenContract, tokenDecimals, receipt, inputData)
feeData, _, _, err := applications.GetApplicationFee(
applicationTransfer,
ethClient,
fluidTokenContract,
tokenDecimals,
receipt,
inputData,
)

if err != nil {
log.Fatal(func(k *log.Log) {
Expand Down Expand Up @@ -288,22 +327,8 @@ func volumeLiquidityMultiplier(volume *big.Rat, tokenDecimals int, address strin
}

func protocolMultiplier(application applications.Application) *big.Rat {
switch application.String() {
case "uniswap_v2":
fallthrough
case "uniswap_v3":
fallthrough
case "saddle":
fallthrough
case "curve":
fallthrough
case "camelot":
fallthrough
case "chronos":
fallthrough
case "kyber_classic":
fallthrough
case "sushiswap":
switch application {
case applications.ApplicationJumper, applications.ApplicationUniswapV3, applications.ApplicationTraderJoe, applications.ApplicationCamelot, applications.ApplicationSushiswap, applications.ApplicationRamses:
return big.NewRat(2, 100)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/microservice-ethereum-track-winners/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
"strconv"
"strings"

"github.com/fluidity-money/fluidity-app/common/ethereum/fluidity"
logging "github.com/fluidity-money/fluidity-app/lib/log"
"github.com/fluidity-money/fluidity-app/lib/queues/ethereum"
"github.com/fluidity-money/fluidity-app/lib/queues/winners"
"github.com/fluidity-money/fluidity-app/lib/types/network"
"github.com/fluidity-money/fluidity-app/lib/types/token-details"
"github.com/fluidity-money/fluidity-app/lib/util"

"github.com/fluidity-money/fluidity-app/common/ethereum/fluidity"
)

const (
Expand Down Expand Up @@ -81,7 +82,6 @@ func main() {
}

ethereum.Logs(func(log ethereum.Log) {

var (
logTopics = log.Topics
transactionHash = log.TxHash
Expand Down
16 changes: 9 additions & 7 deletions cmd/microservice-ethereum-track-winners/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"time"

"github.com/fluidity-money/fluidity-app/common/ethereum/fluidity"
winnersDb "github.com/fluidity-money/fluidity-app/lib/databases/timescale/winners"
"github.com/fluidity-money/fluidity-app/lib/log"
"github.com/fluidity-money/fluidity-app/lib/queue"
Expand All @@ -12,17 +11,19 @@ import (
"github.com/fluidity-money/fluidity-app/lib/types/network"
token_details "github.com/fluidity-money/fluidity-app/lib/types/token-details"
"github.com/fluidity-money/fluidity-app/lib/types/winners"

"github.com/fluidity-money/fluidity-app/common/ethereum/fluidity"
)

func processReward(contractAddress ethereum.Address, transactionHash ethereum.Hash, data fluidity.RewardData, tokenDetails token_details.TokenDetails, network network.BlockchainNetwork) {
var (
winnerString = data.Winner.String()
winnerAddress = ethereum.AddressFromString(winnerString)
startBlock = *data.StartBlock
endBlock = *data.EndBlock
winnerString = data.Winner.String()
startBlock = *data.StartBlock
endBlock = *data.EndBlock
blocked = data.Blocked
)

blocked := data.Blocked
winnerAddress := ethereum.AddressFromString(winnerString)

if blocked {
blockedWinner := convertBlockedWinner(
Expand Down Expand Up @@ -61,8 +62,9 @@ func processReward(contractAddress ethereum.Address, transactionHash ethereum.Ha
}

func processUnblockedReward(transactionHash ethereum.Hash, data fluidity.UnblockedRewardData, tokenDetails token_details.TokenDetails, network network.BlockchainNetwork) {
rewardData := data.RewardData

var (
rewardData = data.RewardData
winnerString = rewardData.Winner.String()
startBlock = *rewardData.StartBlock
endBlock = *rewardData.EndBlock
Expand Down
6 changes: 3 additions & 3 deletions cmd/microservice-lootbox-referral-activator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ const (
)

func main() {
var (
lootboxReferralAmount_ = util.GetEnvOrFatal(EnvLootboxReferralAmount)
)
lootboxReferralAmount_ := util.GetEnvOrFatal(EnvLootboxReferralAmount)

lootboxReferralAmount, err := strconv.ParseUint(lootboxReferralAmount_, 10, 64)

Expand All @@ -45,6 +43,7 @@ func main() {
transactionHash = lootbox.TransactionHash
address = lootbox.Address
lootboxCount = lootbox.LootboxCount
epoch = lootbox.Epoch
)

// don't track non-transaction lootboxes
Expand Down Expand Up @@ -102,6 +101,7 @@ func main() {
RewardTier: 1,
LootboxCount: 5,
Application: applications.ApplicationNone,
Epoch: epoch,
}

queue.SendMessage(lootboxes_queue.TopicLootboxes, referralLootbox)
Expand Down
7 changes: 5 additions & 2 deletions cmd/microservice-lootbox-referral-distributor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
package main

import (
"github.com/fluidity-money/fluidity-app/common/ethereum/applications"
"github.com/fluidity-money/fluidity-app/lib/databases/timescale/referrals"
"github.com/fluidity-money/fluidity-app/lib/log"
"github.com/fluidity-money/fluidity-app/lib/queue"
lootboxes_queue "github.com/fluidity-money/fluidity-app/lib/queues/lootboxes"
"github.com/fluidity-money/fluidity-app/lib/types/ethereum"
"github.com/fluidity-money/fluidity-app/lib/types/lootboxes"
"github.com/fluidity-money/fluidity-app/lib/types/misc"

"github.com/fluidity-money/fluidity-app/common/ethereum/applications"
)

func main() {
Expand All @@ -23,6 +24,7 @@ func main() {
address = lootbox.Address
lootboxCount = lootbox.LootboxCount
awardedTime = lootbox.AwardedTime
epoch = lootbox.Epoch
)

// don't track non-transaction lootboxes
Expand Down Expand Up @@ -62,9 +64,10 @@ func main() {
RewardTier: 1,
LootboxCount: referralLootboxCount,
Application: applications.ApplicationNone,
Epoch: epoch,
}

go queue.SendMessage(lootboxes_queue.TopicLootboxes, referralLootbox)
queue.SendMessage(lootboxes_queue.TopicLootboxes, referralLootbox)
}
})
}
Loading

0 comments on commit de9843e

Please sign in to comment.