Skip to content

Commit f1fabd7

Browse files
authored
Fix issue with funding glf vault setting cashback to 0 (#136)
* Fix issue with funding glf vault setting cashback to 0 * Fix logic
1 parent 11c944e commit f1fabd7

3 files changed

Lines changed: 43 additions & 17 deletions

File tree

mock/FEVMActions.go

Lines changed: 15 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/plus_actions.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,44 @@ func (a *fevmActions) SPPlusSetPersonalCashBackPercent(ctx context.Context, auth
101101
return util.TxPostProcess(tx, err)
102102
}
103103

104-
func (a *fevmActions) SPPlusFundGLFVault(ctx context.Context, auth *bind.TransactOpts, tokenID *big.Int, amount *big.Int) (*types.Transaction, error) {
104+
func (a *fevmActions) SPPlusFundGLFVault(ctx context.Context, auth *bind.TransactOpts, tokenID *big.Int, amount *big.Int, cashBackPercent *big.Int) (*types.Transaction, error) {
105105
client, err := a.extern.ConnectEthClient()
106106
if err != nil {
107107
return nil, err
108108
}
109109
defer client.Close()
110110

111+
// if the cashback percent is not provided, we use the existing cash back percent on the tokenID
112+
// if this is the first time funding the GLF vault (implied by a personal cash back percent of 0), we use the max cash back percent
113+
if cashBackPercent == nil {
114+
caller, err := abigen.NewSPPlusCaller(a.queries.SPPlus(), client)
115+
if err != nil {
116+
return nil, err
117+
}
118+
119+
opts := &bind.CallOpts{Context: ctx}
120+
121+
personalCashBackPercent, err := caller.TokenIdToPersonalCashBackPercent(opts, tokenID)
122+
if err != nil {
123+
return nil, err
124+
}
125+
126+
if personalCashBackPercent.Cmp(big.NewInt(0)) == 0 {
127+
cashBackPercent, err = caller.MaxCashBackPercent(opts)
128+
if err != nil {
129+
return nil, err
130+
}
131+
} else {
132+
cashBackPercent = personalCashBackPercent
133+
}
134+
}
135+
111136
plus, err := abigen.NewSPPlusTransactor(a.queries.SPPlus(), client)
112137
if err != nil {
113138
return nil, err
114139
}
115140

116-
tx, err := plus.FundGlfVault(auth, tokenID, amount)
141+
tx, err := plus.FundGlfVault0(auth, tokenID, amount, cashBackPercent)
117142

118143
return util.TxPostProcess(tx, err)
119144
}

types/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ type FEVMActions interface {
141141
SPPlusMintActivateAndFund(ctx context.Context, auth *bind.TransactOpts, cashBackPercent *big.Int, beneficiary common.Address, tier uint8, amount *big.Int) (*types.Transaction, error)
142142
SPPlusActivate(ctx context.Context, auth *bind.TransactOpts, beneficiary common.Address, tokenID *big.Int, tier uint8) (*types.Transaction, error)
143143
SPPlusSetPersonalCashBackPercent(ctx context.Context, auth *bind.TransactOpts, tokenID *big.Int, cashBackPercent *big.Int) (*types.Transaction, error)
144-
SPPlusFundGLFVault(ctx context.Context, auth *bind.TransactOpts, tokenID *big.Int, amount *big.Int) (*types.Transaction, error)
144+
SPPlusFundGLFVault(ctx context.Context, auth *bind.TransactOpts, tokenID *big.Int, amount *big.Int, cashBackPercent *big.Int) (*types.Transaction, error)
145145
SPPlusClaimCashBack(ctx context.Context, auth *bind.TransactOpts, tokenID *big.Int, receiver common.Address) (*types.Transaction, error)
146146
SPPlusUpgrade(ctx context.Context, auth *bind.TransactOpts, tokenID *big.Int, tier uint8) (*types.Transaction, error)
147147
SPPlusDowngrade(ctx context.Context, auth *bind.TransactOpts, tokenID *big.Int, tier uint8, agentAddr common.Address, requesterKey *ecdsa.PrivateKey) (*types.Transaction, error)

0 commit comments

Comments
 (0)