Skip to content

Commit 2e6243b

Browse files
author
jeffyanta
authored
Make swap subsidizer in Geyser configurable (#43)
1 parent e2be168 commit 2e6243b

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

pkg/code/async/geyser/backup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (p *service) backupExternalDepositWorker(serviceCtx context.Context, interv
142142

143143
log := log.WithField("account", vault.PublicKey().ToBase58())
144144

145-
err := fixMissingExternalDeposits(tracedCtx, p.data, p.pusher, vault)
145+
err := fixMissingExternalDeposits(tracedCtx, p.conf, p.data, p.pusher, vault)
146146
if err != nil {
147147
m.NoticeError(err)
148148
log.WithError(err).Warn("failure fixing missing external deposits")

pkg/code/async/geyser/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ const (
3434
MessagingFeeCollectorPublicKeyConfigEnvName = envConfigPrefix + "MESSAGING_FEE_COLLECTOR_PUBLIC_KEY"
3535
defaultMessagingFeeCollectorPublicKey = "invalid" // ensure something valid is set
3636

37+
SwapSubsidizerPublicKeyConfigEnvName = envConfigPrefix + "SWAP_SUBSIDIZER_PUBLIC_KEY"
38+
defaultSwapSubsidizerPublicKey = "invalid" // ensure something valid is set
39+
3740
BackupMessagingWorkerIntervalConfigEnvName = envConfigPrefix + "BACKUP_MESSAGING_WORKER_INTERVAL"
3841
defaultBackupMessagingWorkerInterval = 15 * time.Minute // Decrease significantly once feature is live
3942
)
@@ -52,6 +55,8 @@ type conf struct {
5255

5356
messagingFeeCollectorPublicKey config.String
5457
backupMessagingWorkerInterval config.Duration
58+
59+
swapSubsidizerPublicKey config.String
5560
}
5661

5762
// ConfigProvider defines how config values are pulled
@@ -74,6 +79,8 @@ func WithEnvConfigs() ConfigProvider {
7479

7580
messagingFeeCollectorPublicKey: env.NewStringConfig(MessagingFeeCollectorPublicKeyConfigEnvName, defaultMessagingFeeCollectorPublicKey),
7681
backupMessagingWorkerInterval: env.NewDurationConfig(BackupMessagingWorkerIntervalConfigEnvName, defaultBackupMessagingWorkerInterval),
82+
83+
swapSubsidizerPublicKey: env.NewStringConfig(SwapSubsidizerPublicKeyConfigEnvName, defaultSwapSubsidizerPublicKey),
7784
}
7885
}
7986
}

pkg/code/async/geyser/external_deposit.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ var (
3939
syncedDepositCache = cache.NewCache(1_000_000)
4040
)
4141

42-
func fixMissingExternalDeposits(ctx context.Context, data code_data.Provider, pusher push_lib.Provider, vault *common.Account) error {
42+
func fixMissingExternalDeposits(ctx context.Context, conf *conf, data code_data.Provider, pusher push_lib.Provider, vault *common.Account) error {
4343
signatures, err := findPotentialExternalDeposits(ctx, data, vault)
4444
if err != nil {
4545
return errors.Wrap(err, "error finding potential external deposits")
4646
}
4747

4848
var anyError error
4949
for _, signature := range signatures {
50-
err := processPotentialExternalDeposit(ctx, data, pusher, signature, vault)
50+
err := processPotentialExternalDeposit(ctx, conf, data, pusher, signature, vault)
5151
if err != nil {
5252
anyError = errors.Wrap(err, "error processing signature for external deposit")
5353
}
@@ -115,7 +115,7 @@ func findPotentialExternalDeposits(ctx context.Context, data code_data.Provider,
115115
}
116116
}
117117

118-
func processPotentialExternalDeposit(ctx context.Context, data code_data.Provider, pusher push_lib.Provider, signature string, tokenAccount *common.Account) error {
118+
func processPotentialExternalDeposit(ctx context.Context, conf *conf, data code_data.Provider, pusher push_lib.Provider, signature string, tokenAccount *common.Account) error {
119119
// Avoid reprocessing deposits we've recently seen and processed. Particularly,
120120
// the backup process will likely be triggered in frequent bursts, so this is
121121
// just an optimization around that.
@@ -199,7 +199,7 @@ func processPotentialExternalDeposit(ctx context.Context, data code_data.Provide
199199
return nil
200200
}
201201

202-
isCodeSwap, usdcQuarksSwapped, err := getCodeSwapMetadata(tokenBalances)
202+
isCodeSwap, usdcQuarksSwapped, err := getCodeSwapMetadata(ctx, conf, tokenBalances)
203203
if err != nil {
204204
return errors.Wrap(err, "error getting code swap metadata")
205205
}
@@ -381,13 +381,12 @@ func getDeltaQuarksFromTokenBalances(tokenAccount *common.Account, tokenBalances
381381
return postQuarkBalance - preQuarkBalance, nil
382382
}
383383

384-
func getCodeSwapMetadata(tokenBalances *solana.TransactionTokenBalances) (bool, uint64, error) {
384+
func getCodeSwapMetadata(ctx context.Context, conf *conf, tokenBalances *solana.TransactionTokenBalances) (bool, uint64, error) {
385385
// Detect whether this is a Code swap by inspecting whether the swap subsidizer
386386
// is included in the transaction.
387387
var isCodeSwap bool
388388
for _, account := range tokenBalances.Accounts {
389-
// todo: configurable
390-
if account == "swapBMF2EzkHSn9NDwaSFWMtGC7ZsgzApQv9NSkeUeU" {
389+
if account == conf.swapSubsidizerPublicKey.Get(ctx) {
391390
isCodeSwap = true
392391
break
393392
}

pkg/code/async/geyser/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (h *TokenProgramAccountHandler) Handle(ctx context.Context, update *geyserp
144144

145145
// We've determined this token account is one that we care about. Process
146146
// the update as an external deposit.
147-
return processPotentialExternalDeposit(ctx, h.data, h.pusher, *update.TxSignature, tokenAccount)
147+
return processPotentialExternalDeposit(ctx, h.conf, h.data, h.pusher, *update.TxSignature, tokenAccount)
148148
}
149149

150150
type TimelockV1ProgramAccountHandler struct {

0 commit comments

Comments
 (0)