@@ -130,12 +130,12 @@ func CreatePool(
130130 token0Path string,
131131 token1Path string,
132132 fee uint32,
133- _sqrtPriceX96 string,
133+ sqrtPriceX96 string,
134134) {
135135 common.IsHalted()
136136 en.MintAndDistributeGns()
137137
138- poolInfo := newPoolParams(token0Path, token1Path, fee, _sqrtPriceX96 )
138+ poolInfo := newPoolParams(token0Path, token1Path, fee, sqrtPriceX96 )
139139
140140 if poolInfo.isSameTokenPath() {
141141 panic(addDetailToError(
@@ -153,7 +153,7 @@ func CreatePool(
153153 poolPath := GetPoolPath(token0Path, token1Path, fee)
154154
155155 // reinitialize poolInfo with wrapped tokens
156- poolInfo = newPoolParams(token0Path, token1Path, fee, _sqrtPriceX96 )
156+ poolInfo = newPoolParams(token0Path, token1Path, fee, sqrtPriceX96 )
157157
158158 // then check if token0Path == token1Path
159159 if poolInfo.isSameTokenPath() {
@@ -174,7 +174,7 @@ func CreatePool(
174174 }
175175
176176 // TODO: make this as a parameter
177- prevAddr, prevRealm := getPrev ()
177+ prevAddr, prevRealm := getPrevAsString ()
178178
179179 // check whether the pool already exist
180180 pool, exist := pools.Get(poolPath)
@@ -208,7 +208,7 @@ func CreatePool(
208208 "token0Path", token0Path,
209209 "token1Path", token1Path,
210210 "fee", ufmt.Sprintf("%d", fee),
211- "sqrtPriceX96", _sqrtPriceX96 ,
211+ "sqrtPriceX96", sqrtPriceX96 ,
212212 "internal_poolPath", poolPath,
213213 )
214214}
@@ -220,46 +220,91 @@ func DoesPoolPathExist(poolPath string) bool {
220220 return exist
221221}
222222
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)
226242func GetPool(token0Path, token1Path string, fee uint32) *Pool {
227243 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)
237245}
238246
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")
240267func GetPoolFromPoolPath(poolPath string) *Pool {
241268 pool, exist := pools[poolPath]
242269 if !exist {
243270 panic(addDetailToError(
244271 errDataNotFound,
245- ufmt.Sprintf("pool_manager.gno__GetPoolFromPoolPath() || expected poolPath(%s) to exist", poolPath),
272+ ufmt.Sprintf("expected poolPath(%s) to exist", poolPath),
246273 ))
247274 }
248-
249275 return pool
250276}
251277
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"
254301func GetPoolPath(token0Path, token1Path string, fee uint32) string {
255302 common.MustRegistered(token0Path)
256303 common.MustRegistered(token1Path)
257304
258- // TODO: this check is not unnecessary, if we are sure that
259305 // all the token paths in the pool are sorted in alphabetical order.
260306 if strings.Compare(token1Path, token0Path) < 0 {
261307 token0Path, token1Path = token1Path, token0Path
262308 }
263-
264309 return ufmt.Sprintf("%s:%s:%d", token0Path, token1Path, fee)
265310}
0 commit comments