Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

proxy.gno

14.26 Kb · 443 lines
  1package pool
  2
  3// CreatePool creates a new liquidity pool for a token pair.
  4//
  5// Parameters:
  6//   - cur: Current realm context; callers use cross(cur) when crossing into this
  7//     realm.
  8//   - token0Path: Token contract path supplied for token0; the pool orders the
  9//     pair canonically rather than preserving the supplied order.
 10//   - token1Path: Token contract path supplied for token1; must form a distinct
 11//     registered pair with token0Path.
 12//   - fee: Fee tier for the pool; determines its tick spacing and swap fee.
 13//   - sqrtPriceX96: Initial square-root price in Q64.96 fixed-point form; it is
 14//     inverted when the supplied token order is reversed and must be in bounds.
 15//
 16// Halt check: reverts while the Pool halt scope is active.
 17func CreatePool(
 18	cur realm,
 19	token0Path string,
 20	token1Path string,
 21	fee uint32,
 22	sqrtPriceX96 string,
 23) {
 24	getImplementation().CreatePool(
 25		0,
 26		cur,
 27		token0Path,
 28		token1Path,
 29		fee,
 30		sqrtPriceX96,
 31	)
 32}
 33
 34// SetPoolCreationFee sets the pool creation fee.
 35//
 36// Parameters:
 37//   - cur: Current realm context; callers use cross(cur) when crossing into this
 38//     realm.
 39//   - fee: New pool creation fee, in the configured native-token base units.
 40//
 41// Halt check: reverts while the Pool halt scope is active.
 42func SetPoolCreationFee(cur realm, fee int64) {
 43	getImplementation().SetPoolCreationFee(0, cur, fee)
 44}
 45
 46// IncreaseObservationCardinalityNext increases the observation cardinality for a pool.
 47//
 48// Parameters:
 49//   - cur: Current realm context; callers use cross(cur) when crossing into this
 50//     realm.
 51//   - token0Path: Path of the first token in the pool pair.
 52//   - token1Path: Path of the second token in the pool pair.
 53//   - fee: Fee tier identifying the pool.
 54//   - cardinalityNext: Requested maximum number of oracle observations retained
 55//     for the pool.
 56//
 57// Halt check: reverts while the Pool halt scope is active.
 58func IncreaseObservationCardinalityNext(
 59	cur realm,
 60	token0Path string,
 61	token1Path string,
 62	fee uint32,
 63	cardinalityNext uint16,
 64) {
 65	getImplementation().IncreaseObservationCardinalityNext(
 66		0,
 67		cur,
 68		token0Path,
 69		token1Path,
 70		fee,
 71		cardinalityNext,
 72	)
 73}
 74
 75// Mint adds liquidity to a position.
 76//
 77// Parameters:
 78//   - cur: Current realm context; callers use cross(cur) when crossing into this
 79//     realm.
 80//   - token0Path: Path of the first token in the pool pair.
 81//   - token1Path: Path of the second token in the pool pair.
 82//   - fee: Fee tier identifying the pool.
 83//   - tickLower: Lower inclusive tick boundary of the position range.
 84//   - tickUpper: Upper exclusive tick boundary of the position range.
 85//   - liquidityAmount: Decimal liquidity amount to add to the position.
 86//   - positionCaller: Position-contract address whose position receives the
 87//     liquidity.
 88//
 89// Returns:
 90//   - amount0: Token0 amount required for the liquidity addition, as a decimal
 91//     string.
 92//   - amount1: Token1 amount required for the liquidity addition, as a decimal
 93//     string.
 94//
 95// Halt check: reverts while the Pool halt scope is active.
 96func Mint(
 97	cur realm,
 98	token0Path string,
 99	token1Path string,
100	fee uint32,
101	tickLower int32,
102	tickUpper int32,
103	liquidityAmount string,
104	positionCaller address,
105) (string, string) {
106	return getImplementation().Mint(
107		0,
108		cur,
109		token0Path,
110		token1Path,
111		fee,
112		tickLower,
113		tickUpper,
114		liquidityAmount,
115		positionCaller,
116	)
117}
118
119// Burn removes liquidity from a position.
120//
121// Parameters:
122//   - cur: Current realm context; callers use cross(cur) when crossing into this
123//     realm.
124//   - token0Path: Path of the first token in the pool pair.
125//   - token1Path: Path of the second token in the pool pair.
126//   - fee: Fee tier identifying the pool.
127//   - tickLower: Lower inclusive tick boundary of the position range.
128//   - tickUpper: Upper exclusive tick boundary of the position range.
129//   - liquidityAmount: Decimal liquidity amount to remove from the position.
130//   - positionCaller: Position-contract address whose position is decreased.
131//
132// Returns:
133//   - amount0: Token0 principal credited to the position, as a decimal string;
134//     the pool operation leaves it owed until a subsequent collection.
135//   - amount1: Token1 principal credited to the position, as a decimal string;
136//     the pool operation leaves it owed until a subsequent collection.
137//
138// Halt check: reverts while the Withdraw halt scope is active.
139func Burn(
140	cur realm,
141	token0Path string,
142	token1Path string,
143	fee uint32,
144	tickLower int32,
145	tickUpper int32,
146	liquidityAmount string,
147	positionCaller address,
148) (string, string) {
149	return getImplementation().Burn(
150		0,
151		cur,
152		token0Path,
153		token1Path,
154		fee,
155		tickLower,
156		tickUpper,
157		liquidityAmount,
158		positionCaller,
159	)
160}
161
162// CollectSwapFee pays accrued swap fees for a position out to recipient,
163// net of the withdrawal fee.
164//
165// Parameters:
166//   - cur: Current realm context; callers use cross(cur) when crossing into this
167//     realm.
168//   - token0Path: Path of the first token in the pool pair.
169//   - token1Path: Path of the second token in the pool pair.
170//   - fee: Fee tier identifying the pool.
171//   - recipient: Non-zero address receiving the collected token amounts after
172//     withdrawal-fee deduction.
173//   - tickLower: Lower inclusive tick boundary of the position range.
174//   - tickUpper: Upper exclusive tick boundary of the position range.
175//   - amount0Requested: Decimal token0 amount requested; the configured maximum
176//     value requests all token0 fees owed.
177//   - amount1Requested: Decimal token1 amount requested; the configured maximum
178//     value requests all token1 fees owed.
179//
180// Returns:
181//   - amount0: Collected token0 amount before withdrawal-fee deduction, as a
182//     decimal string.
183//   - amount1: Collected token1 amount before withdrawal-fee deduction, as a
184//     decimal string.
185//   - fee0: Withdrawal fee withheld from token0, as a decimal string.
186//   - fee1: Withdrawal fee withheld from token1, as a decimal string.
187//
188// Halt check: reverts while the Withdraw halt scope is active.
189func CollectSwapFee(
190	cur realm,
191	token0Path string,
192	token1Path string,
193	fee uint32,
194	recipient address,
195	tickLower int32,
196	tickUpper int32,
197	amount0Requested string,
198	amount1Requested string,
199) (amount0, amount1, fee0, fee1 string) {
200	return getImplementation().CollectSwapFee(
201		0,
202		cur,
203		token0Path,
204		token1Path,
205		fee,
206		recipient,
207		tickLower,
208		tickUpper,
209		amount0Requested,
210		amount1Requested,
211	)
212}
213
214// Collect pays tokens owed to a position out to recipient in full. No
215// withdrawal fee is charged on this path; see CollectSwapFee for the
216// fee-bearing path.
217//
218// Parameters:
219//   - cur: Current realm context; callers use cross(cur) when crossing into this
220//     realm.
221//   - token0Path: Path of the first token in the pool pair.
222//   - token1Path: Path of the second token in the pool pair.
223//   - fee: Fee tier identifying the pool.
224//   - recipient: Non-zero address receiving the owed token amounts.
225//   - tickLower: Lower inclusive tick boundary of the position range.
226//   - tickUpper: Upper exclusive tick boundary of the position range.
227//   - amount0Requested: Decimal token0 amount requested from the position's
228//     accrued principal.
229//   - amount1Requested: Decimal token1 amount requested from the position's
230//     accrued principal.
231//
232// Returns:
233//   - amount0: Token0 principal transferred to recipient, as a decimal string.
234//   - amount1: Token1 principal transferred to recipient, as a decimal string.
235//
236// Halt check: reverts while the Withdraw halt scope is active.
237func Collect(
238	cur realm,
239	token0Path string,
240	token1Path string,
241	fee uint32,
242	recipient address,
243	tickLower int32,
244	tickUpper int32,
245	amount0Requested string,
246	amount1Requested string,
247) (string, string) {
248	return getImplementation().Collect(
249		0,
250		cur,
251		token0Path,
252		token1Path,
253		fee,
254		recipient,
255		tickLower,
256		tickUpper,
257		amount0Requested,
258		amount1Requested,
259	)
260}
261
262// SetWithdrawalFee sets the withdrawal fee rate.
263//
264// Parameters:
265//   - cur: Current realm context; callers use cross(cur) when crossing into this
266//     realm.
267//   - fee: Withdrawal fee in basis points; zero disables the fee.
268//
269// Halt check: reverts while the Pool halt scope is active.
270func SetWithdrawalFee(cur realm, fee uint64) {
271	getImplementation().SetWithdrawalFee(0, cur, fee)
272}
273
274// Swap executes a token swap in the pool.
275//
276// Parameters:
277//   - cur: Current realm context; callers use cross(cur) when crossing into this
278//     realm.
279//   - token0Path: Path of the first token in the pool pair.
280//   - token1Path: Path of the second token in the pool pair.
281//   - fee: Fee tier identifying the pool.
282//   - recipient: Address receiving output tokens.
283//   - zeroForOne: True to sell token0 for token1; false to sell token1 for
284//     token0.
285//   - amountSpecified: Decimal signed amount; positive requests exact input and
286//     negative requests exact output.
287//   - sqrtPriceLimitX96: Price boundary in Q64.96 fixed-point form at which the
288//     swap must stop.
289//   - swapCallback: Callback invoked with the current realm, signed token
290//     deltas, and a callback marker; it must settle the input token and return a
291//     non-nil error to abort settlement.
292//
293// Returns:
294//   - amount0: Signed token0 delta for the swap, as a decimal string.
295//   - amount1: Signed token1 delta for the swap, as a decimal string.
296//
297// Halt check: reverts while the Pool halt scope is active.
298func Swap(
299	cur realm,
300	token0Path string,
301	token1Path string,
302	fee uint32,
303	recipient address,
304	zeroForOne bool,
305	amountSpecified string,
306	sqrtPriceLimitX96 string,
307	swapCallback func(cur realm, amount0Delta, amount1Delta int64, callbackMarker *CallbackMarker) error,
308) (string, string) {
309	return getImplementation().Swap(
310		0,
311		cur,
312		token0Path,
313		token1Path,
314		fee,
315		recipient,
316		zeroForOne,
317		amountSpecified,
318		sqrtPriceLimitX96,
319		swapCallback,
320	)
321}
322
323// DrySwap simulates a swap without executing it, returning the expected output.
324//
325// This is a read-only operation that does not modify pool state.
326// Used by router for multi-hop swap simulations and by clients for price quotes.
327//
328// Parameters:
329//   - token0Path: Path of the first token in the pool pair.
330//   - token1Path: Path of the second token in the pool pair.
331//   - fee: Fee tier identifying the pool.
332//   - zeroForOne: True to sell token0 for token1; false to sell token1 for
333//     token0.
334//   - amountSpecified: Decimal signed amount; positive requests exact input and
335//     negative requests exact output.
336//   - sqrtPriceLimitX96: Price boundary in Q64.96 fixed-point form at which the
337//     simulation must stop.
338//
339// Returns:
340//   - amount0: Simulated signed token0 delta, as a decimal string; "0" on an
341//     unsuccessful simulation.
342//   - amount1: Simulated signed token1 delta, as a decimal string; "0" on an
343//     unsuccessful simulation.
344//   - error: Nil when the simulation succeeds; non-nil when validation,
345//     computation, or pool-balance checks fail.
346func DrySwap(
347	token0Path string,
348	token1Path string,
349	fee uint32,
350	zeroForOne bool,
351	amountSpecified string,
352	sqrtPriceLimitX96 string,
353) (string, string, error) {
354	return getImplementation().DrySwap(token0Path, token1Path, fee, zeroForOne, amountSpecified, sqrtPriceLimitX96)
355}
356
357// SetSwapEndHook sets the hook to be called at the end of a swap.
358//
359// Parameters:
360//   - cur: Current realm context; callers use cross(cur) when crossing into this
361//     realm.
362//   - hook: Callback invoked with the current realm and pool path after swap
363//     settlement; its error is propagated to abort the swap.
364func SetSwapEndHook(cur realm, hook func(cur realm, poolPath string) error) {
365	getImplementation().SetSwapEndHook(0, cur, hook)
366}
367
368// SetSwapStartHook sets the hook to be called at the start of a swap.
369//
370// Parameters:
371//   - cur: Current realm context; callers use cross(cur) when crossing into this
372//     realm.
373//   - hook: Callback invoked with the current realm, pool path, and swap
374//     timestamp before swap computation.
375func SetSwapStartHook(cur realm, hook func(cur realm, poolPath string, timestamp int64)) {
376	getImplementation().SetSwapStartHook(0, cur, hook)
377}
378
379// SetTickCrossHook sets the hook to be called when a tick is crossed during a swap.
380//
381// Parameters:
382//   - cur: Current realm context; callers use cross(cur) when crossing into this
383//     realm.
384//   - hook: Callback invoked with the current realm, pool path, crossed tick
385//     index, swap direction, and block timestamp.
386func SetTickCrossHook(cur realm, hook func(cur realm, poolPath string, tickId int32, zeroForOne bool, timestamp int64)) {
387	getImplementation().SetTickCrossHook(0, cur, hook)
388}
389
390// CollectProtocol collects protocol fees from a pool.
391//
392// Parameters:
393//   - cur: Current realm context; callers use cross(cur) when crossing into this
394//     realm.
395//   - token0Path: Path of the first token in the pool pair.
396//   - token1Path: Path of the second token in the pool pair.
397//   - fee: Fee tier identifying the pool.
398//   - recipient: Address receiving the collected protocol fees.
399//   - amount0Requested: Decimal token0 protocol-fee amount requested; collection
400//     is capped at the available amount.
401//   - amount1Requested: Decimal token1 protocol-fee amount requested; collection
402//     is capped at the available amount.
403//
404// Returns:
405//   - amount0: Token0 protocol fee transferred to recipient, as a decimal string.
406//   - amount1: Token1 protocol fee transferred to recipient, as a decimal string.
407//
408// Halt check: reverts while the Withdraw halt scope is active.
409func CollectProtocol(
410	cur realm,
411	token0Path string,
412	token1Path string,
413	fee uint32,
414	recipient address,
415	amount0Requested string,
416	amount1Requested string,
417) (string, string) {
418	return getImplementation().CollectProtocol(
419		0,
420		cur,
421		token0Path,
422		token1Path,
423		fee,
424		recipient,
425		amount0Requested,
426		amount1Requested,
427	)
428}
429
430// SetFeeProtocol sets the protocol fee rates for a pool.
431//
432// Parameters:
433//   - cur: Current realm context; callers use cross(cur) when crossing into this
434//     realm.
435//   - feeProtocol0: Token0 protocol-fee denominator; zero disables it, while
436//     non-zero supported values route the corresponding fraction to protocol.
437//   - feeProtocol1: Token1 protocol-fee denominator; zero disables it, while
438//     non-zero supported values route the corresponding fraction to protocol.
439//
440// Halt check: reverts while the Pool halt scope is active.
441func SetFeeProtocol(cur realm, feeProtocol0, feeProtocol1 uint8) {
442	getImplementation().SetFeeProtocol(0, cur, feeProtocol0, feeProtocol1)
443}