@@ -13,29 +13,6 @@ import (
13
13
poolmanagertypes "github.com/osmosis-labs/osmosis/v15/x/poolmanager/types"
14
14
)
15
15
16
- // ShouldExecutePump decides if the pump should happen in this block based on stream's pump params.
17
- func (k Keeper ) ShouldExecutePump (ctx sdk.Context , stream types.Stream ) (bool , error ) {
18
- if stream .PumpParams == nil {
19
- return false , nil
20
- }
21
-
22
- if stream .PumpParams .EpochBudgetLeft .IsZero () {
23
- return false , nil
24
- }
25
-
26
- epochBlocks , err := k .EpochBlocks (ctx , stream .DistrEpochIdentifier )
27
- if err != nil {
28
- return false , fmt .Errorf ("failed to get epoch blocks: %w" , err )
29
- }
30
-
31
- pumpAmt , err := ShouldPump (ctx , stream .PumpParams .EpochBudget , stream .PumpParams .EpochBudgetLeft , stream .PumpParams .NumPumps , epochBlocks )
32
- if err != nil {
33
- return false , fmt .Errorf ("failed to calculate pump amount: %w" , err )
34
- }
35
-
36
- return ! pumpAmt .IsZero (), nil
37
- }
38
-
39
16
// ShouldPump decides if the pump should happen in this block. It uses block
40
17
// hash and block time as entropy.
41
18
//
@@ -116,63 +93,73 @@ func (k Keeper) ExecutePump(
116
93
ctx sdk.Context ,
117
94
pumpAmt math.Int ,
118
95
rollappID string ,
119
- ) error {
96
+ ) ( tokenOut sdk. Coin , err error ) {
120
97
rollapp , found := k .rollappKeeper .GetRollapp (ctx , rollappID )
121
98
if ! found {
122
- return fmt .Errorf ("rollapp not found: %s" , rollappID )
99
+ return sdk. Coin {}, fmt .Errorf ("rollapp not found: %s" , rollappID )
123
100
}
124
101
125
102
plan , found := k .iroKeeper .GetPlanByRollapp (ctx , rollapp .RollappId )
126
103
if ! found {
127
- return fmt .Errorf ("IRO plan not found for rollapp: %s" , rollappID )
104
+ return sdk. Coin {}, fmt .Errorf ("IRO plan not found for rollapp: %s" , rollappID )
128
105
}
129
106
130
- address := k .ak .GetModuleAddress (types .ModuleName )
131
- // TODO: get base denom
132
- baseDenom := "adym" // Base denom for budget
107
+ // Always use base denom for budget
108
+ baseDenom , err := k .txFeesKeeper .GetBaseDenom (ctx )
109
+ if err != nil {
110
+ return sdk.Coin {}, fmt .Errorf ("get base denom: %w" , err )
111
+ }
133
112
134
- return osmoutils .ApplyFuncIfNoError (ctx , func (ctx sdk.Context ) error {
135
- var targetDenom string
136
- if plan .IsSettled () {
137
- targetDenom = plan .SettledDenom
138
- } else {
139
- targetDenom = plan .LiquidityDenom
140
- }
113
+ var targetDenom string
114
+ if plan .IsSettled () {
115
+ targetDenom = plan .SettledDenom
116
+ } else {
117
+ targetDenom = plan .LiquidityDenom
118
+ }
141
119
142
- // Get FeeToken for target denom to find routing
143
- feeToken , err := k .getFeeTokenForDenom (ctx , targetDenom )
144
- if err != nil {
145
- return fmt .Errorf ("get fee token for denom %s: %w" , targetDenom , err )
146
- }
120
+ // Get FeeToken for target denom to find routing to the base denom.
121
+ // Every token must have a route to the base denom.
122
+ feeToken , err := k .txFeesKeeper .GetFeeToken (ctx , targetDenom )
123
+ if err != nil {
124
+ return sdk.Coin {}, fmt .Errorf ("get fee token for denom %s: %w" , targetDenom , err )
125
+ }
147
126
148
- tokenIn := sdk .NewCoin (baseDenom , pumpAmt )
127
+ buyer := k .ak .GetModuleAddress (types .ModuleName )
128
+ var tokenOutAmt math.Int
149
129
150
- targetAmount , err := k .poolManagerKeeper .RouteExactAmountIn (
130
+ err = osmoutils .ApplyFuncIfNoError (ctx , func (ctx sdk.Context ) error {
131
+ // Buy:
132
+ // - RA tokens if IRO is over
133
+ // - Liquidity tokens if IRO is in progress
134
+ tokenOutAmt , err := k .poolManagerKeeper .RouteExactAmountIn (
151
135
ctx ,
152
- address ,
153
- feeToken .Route , // Use route from FeeToken
154
- tokenIn ,
155
- math .ZeroInt (), // tokenOutMinAmount = 0 (ignore slippage for now )
136
+ buyer ,
137
+ feeToken .Route ,
138
+ sdk . NewCoin ( baseDenom , pumpAmt ), // token in
139
+ math .ZeroInt (), // no slippage )
156
140
)
157
141
if err != nil {
158
142
return fmt .Errorf ("route exact amount in: target denom: %s, error: %w" , targetDenom , err )
159
143
}
160
144
161
145
if ! plan .IsSettled () {
162
- err = k .iroKeeper .BuyExactSpend (
146
+ // If IRO is in progress, use liquidity tokens to buy IRO tokens
147
+ tokenOutAmt , err = k .iroKeeper .BuyExactSpend (
163
148
ctx ,
164
149
fmt .Sprintf ("%d" , plan .Id ),
165
- address ,
166
- targetAmount , // amountToSpend
167
- math .ZeroInt (), // minTokensAmt = 0
150
+ buyer ,
151
+ tokenOutAmt , // amountToSpend
152
+ math .ZeroInt (), // no slippage
168
153
)
169
154
if err != nil {
170
- return fmt .Errorf ("buy from IRO: %w" , err )
155
+ return fmt .Errorf ("buy from IRO %d : %w" , plan . Id , err )
171
156
}
172
157
}
173
158
174
159
return nil
175
160
})
161
+
162
+ return sdk .NewCoin (targetDenom , tokenOutAmt ), err
176
163
}
177
164
178
165
// getFeeTokenForDenom gets the FeeToken configuration for a given denom
@@ -210,33 +197,29 @@ func (k Keeper) DistributePumpStreams(ctx sdk.Context, pumpStreams []types.Strea
210
197
}
211
198
212
199
// Use ShouldPump directly to determine pump amount
213
- pumpAmt , err := ShouldPump (ctx , stream .PumpParams .EpochBudget , stream .PumpParams .EpochBudgetLeft , stream .PumpParams .NumPumps , epochBlocks )
200
+ pumpAmt , err := ShouldPump (
201
+ ctx ,
202
+ stream .PumpParams .EpochBudget ,
203
+ stream .PumpParams .EpochBudgetLeft ,
204
+ stream .PumpParams .NumPumps ,
205
+ epochBlocks ,
206
+ )
214
207
if err != nil {
215
208
return fmt .Errorf ("failed to calculate pump amount: %w" , err )
216
209
}
217
210
218
211
if pumpAmt .IsZero () {
212
+ // Shouldn't pump on this iteration
219
213
continue
220
214
}
221
215
222
216
// Get top rollapps from the stream's distribution
223
217
rollapps := k .TopRollapps (ctx , stream .DistributeTo .Records , stream .PumpParams .NumTopRollapps )
224
218
225
- // Calculate total weight for proportional distribution
226
- totalWeight := math .ZeroInt ()
227
- for _ , rollapp := range rollapps {
228
- totalWeight = totalWeight .Add (rollapp .Weight )
229
- }
230
-
231
- if totalWeight .IsZero () {
232
- k .Logger (ctx ).Info ("no valid rollapps found for pump stream" , "streamID" , stream .Id )
233
- continue
234
- }
235
-
236
219
// Distribute pump amount proportionally to each rollapp
237
220
for _ , rollapp := range rollapps {
238
221
// Calculate proportional pump amount based on rollapp weight
239
- pumpAmtRA := pumpAmt .Mul (rollapp .Weight ).Quo (totalWeight )
222
+ pumpAmtRA := pumpAmt .Mul (rollapp .Weight ).Quo (stream . DistributeTo . TotalWeight )
240
223
241
224
if pumpAmtRA .IsZero () {
242
225
continue
0 commit comments