@@ -130,12 +130,12 @@ func CreatePool(
130
130
token0Path string,
131
131
token1Path string,
132
132
fee uint32,
133
- _sqrtPriceX96 string,
133
+ sqrtPriceX96 string,
134
134
) {
135
135
common.IsHalted()
136
136
en.MintAndDistributeGns()
137
137
138
- poolInfo := newPoolParams(token0Path, token1Path, fee, _sqrtPriceX96 )
138
+ poolInfo := newPoolParams(token0Path, token1Path, fee, sqrtPriceX96 )
139
139
140
140
if poolInfo.isSameTokenPath() {
141
141
panic(addDetailToError(
@@ -153,7 +153,7 @@ func CreatePool(
153
153
poolPath := GetPoolPath(token0Path, token1Path, fee)
154
154
155
155
// reinitialize poolInfo with wrapped tokens
156
- poolInfo = newPoolParams(token0Path, token1Path, fee, _sqrtPriceX96 )
156
+ poolInfo = newPoolParams(token0Path, token1Path, fee, sqrtPriceX96 )
157
157
158
158
// then check if token0Path == token1Path
159
159
if poolInfo.isSameTokenPath() {
@@ -174,7 +174,7 @@ func CreatePool(
174
174
}
175
175
176
176
// TODO: make this as a parameter
177
- prevAddr, prevRealm := getPrev ()
177
+ prevAddr, prevRealm := getPrevAsString ()
178
178
179
179
// check whether the pool already exist
180
180
pool, exist := pools.Get(poolPath)
@@ -208,7 +208,7 @@ func CreatePool(
208
208
"token0Path", token0Path,
209
209
"token1Path", token1Path,
210
210
"fee", ufmt.Sprintf("%d", fee),
211
- "sqrtPriceX96", _sqrtPriceX96 ,
211
+ "sqrtPriceX96", sqrtPriceX96 ,
212
212
"internal_poolPath", poolPath,
213
213
)
214
214
}
@@ -220,46 +220,91 @@ func DoesPoolPathExist(poolPath string) bool {
220
220
return exist
221
221
}
222
222
223
- // GetPool retrieves the pool for the given token paths and fee.
224
- // It constructs the poolPath from the given parameters and returns the corresponding pool.
225
- // Returns pool struct
223
+ // GetPool retrieves a pool instance based on the provided token paths and fee tier.
224
+ //
225
+ // This function determines the pool path by combining the paths of token0 and token1 along with the fee tier,
226
+ // and then retrieves the corresponding pool instance using that path.
227
+ //
228
+ // Parameters:
229
+ // - token0Path (string): The unique identifier or path for token0.
230
+ // - token1Path (string): The unique identifier or path for token1.
231
+ // - fee (uint32): The fee tier for the pool, expressed in basis points (e.g., 3000 for 0.3%).
232
+ //
233
+ // Returns:
234
+ // - *Pool: A pointer to the Pool instance corresponding to the provided tokens and fee tier.
235
+ //
236
+ // Notes:
237
+ // - The order of token paths (token0Path and token1Path) matters and should match the pool's configuration.
238
+ // - Ensure that the tokens and fee tier provided are valid and registered in the system.
239
+ //
240
+ // Example:
241
+ // pool := GetPool("path/to/token0", "path/to/token1", 3000)
226
242
func GetPool(token0Path, token1Path string, fee uint32) *Pool {
227
243
poolPath := GetPoolPath(token0Path, token1Path, fee)
228
- pool, exist := pools[poolPath]
229
- if !exist {
230
- panic(addDetailToError(
231
- errDataNotFound,
232
- ufmt.Sprintf("pool_manager.gno__GetPool() || expected poolPath(%s) to exist", poolPath),
233
- ))
234
- }
235
-
236
- return pool
244
+ return GetPoolFromPoolPath(poolPath)
237
245
}
238
246
239
- // GetPoolFromPoolPath retrieves the pool for the given poolPath.
247
+ // GetPoolFromPoolPath retrieves a pool instance based on the provided pool path.
248
+ //
249
+ // This function checks if a pool exists for the given poolPath in the `pools` mapping.
250
+ // If the pool exists, it returns the pool instance. Otherwise, it panics with a descriptive error.
251
+ //
252
+ // Parameters:
253
+ // - poolPath (string): The unique identifier or path for the pool.
254
+ //
255
+ // Returns:
256
+ // - *Pool: A pointer to the Pool instance corresponding to the given poolPath.
257
+ //
258
+ // Panics:
259
+ // - If the `poolPath` does not exist in the `pools` mapping, it panics with an error message
260
+ // indicating that the expected poolPath was not found.
261
+ //
262
+ // Notes:
263
+ // - Ensure that the `poolPath` provided is valid and corresponds to an existing pool in the `pools` mapping.
264
+ //
265
+ // Example:
266
+ // pool := GetPoolFromPoolPath("path/to/pool")
240
267
func GetPoolFromPoolPath(poolPath string) *Pool {
241
268
pool, exist := pools[poolPath]
242
269
if !exist {
243
270
panic(addDetailToError(
244
271
errDataNotFound,
245
- ufmt.Sprintf("pool_manager.gno__GetPoolFromPoolPath() || expected poolPath(%s) to exist", poolPath),
272
+ ufmt.Sprintf("expected poolPath(%s) to exist", poolPath),
246
273
))
247
274
}
248
-
249
275
return pool
250
276
}
251
277
252
- // GetPoolPath generates a poolPath from the given token paths and fee.
253
- // The poolPath is constructed by joining the token paths and fee with colons.
278
+ // GetPoolPath generates a unique pool path string based on the token paths and fee tier.
279
+ //
280
+ // This function ensures that the token paths are registered and sorted in alphabetical order
281
+ // before combining them with the fee tier to create a unique identifier for the pool.
282
+ //
283
+ // Parameters:
284
+ // - token0Path (string): The unique identifier or path for token0.
285
+ // - token1Path (string): The unique identifier or path for token1.
286
+ // - fee (uint32): The fee tier for the pool, expressed in basis points (e.g., 3000 for 0.3%).
287
+ //
288
+ // Returns:
289
+ // - string: A unique pool path string in the format "token0Path:token1Path:fee".
290
+ //
291
+ // Notes:
292
+ // - The function validates that both `token0Path` and `token1Path` are registered in the system
293
+ // using `common.MustRegistered`.
294
+ // - The token paths are sorted alphabetically to ensure consistent pool path generation, regardless
295
+ // of the input order.
296
+ // - This sorting guarantees that the pool path remains deterministic for the same pair of tokens and fee.
297
+ //
298
+ // Example:
299
+ // poolPath := GetPoolPath("path/to/token0", "path/to/token1", 3000)
300
+ // // Output: "path/to/token0:path/to/token1:3000"
254
301
func GetPoolPath(token0Path, token1Path string, fee uint32) string {
255
302
common.MustRegistered(token0Path)
256
303
common.MustRegistered(token1Path)
257
304
258
- // TODO: this check is not unnecessary, if we are sure that
259
305
// all the token paths in the pool are sorted in alphabetical order.
260
306
if strings.Compare(token1Path, token0Path) < 0 {
261
307
token0Path, token1Path = token1Path, token0Path
262
308
}
263
-
264
309
return ufmt.Sprintf("%s:%s:%d", token0Path, token1Path, fee)
265
310
}
0 commit comments