@moon-cx/sdk 0.0.0-stage → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +2 -2
  3. package/dist/adapters/sender.d.ts +88 -0
  4. package/dist/adapters/sender.d.ts.map +1 -0
  5. package/dist/adapters/sender.js +62 -0
  6. package/dist/adapters/sender.js.map +1 -0
  7. package/dist/adapters/tonclient.d.ts +13 -0
  8. package/dist/adapters/tonclient.d.ts.map +1 -0
  9. package/dist/adapters/tonclient.js +17 -0
  10. package/dist/adapters/tonclient.js.map +1 -0
  11. package/dist/api/index.d.ts +210 -0
  12. package/dist/api/index.d.ts.map +1 -0
  13. package/dist/api/index.js +364 -0
  14. package/dist/api/index.js.map +1 -0
  15. package/dist/codec/bins.d.ts +26 -0
  16. package/dist/codec/bins.d.ts.map +1 -0
  17. package/dist/codec/bins.js +67 -0
  18. package/dist/codec/bins.js.map +1 -0
  19. package/dist/codec/clmm.d.ts +87 -0
  20. package/dist/codec/clmm.d.ts.map +1 -0
  21. package/dist/codec/clmm.js +119 -0
  22. package/dist/codec/clmm.js.map +1 -0
  23. package/dist/codec/cpmm.d.ts +112 -0
  24. package/dist/codec/cpmm.d.ts.map +1 -0
  25. package/dist/codec/cpmm.js +146 -0
  26. package/dist/codec/cpmm.js.map +1 -0
  27. package/dist/codec/jetton.d.ts +30 -0
  28. package/dist/codec/jetton.d.ts.map +1 -0
  29. package/dist/codec/jetton.js +37 -0
  30. package/dist/codec/jetton.js.map +1 -0
  31. package/dist/codec/mempad.d.ts +109 -0
  32. package/dist/codec/mempad.d.ts.map +1 -0
  33. package/dist/codec/mempad.js +162 -0
  34. package/dist/codec/mempad.js.map +1 -0
  35. package/dist/core/amount.d.ts +33 -0
  36. package/dist/core/amount.d.ts.map +1 -0
  37. package/dist/core/amount.js +81 -0
  38. package/dist/core/amount.js.map +1 -0
  39. package/dist/core/asset.d.ts +82 -0
  40. package/dist/core/asset.d.ts.map +1 -0
  41. package/dist/core/asset.js +143 -0
  42. package/dist/core/asset.js.map +1 -0
  43. package/dist/core/errors.d.ts +70 -0
  44. package/dist/core/errors.d.ts.map +1 -0
  45. package/dist/core/errors.js +114 -0
  46. package/dist/core/errors.js.map +1 -0
  47. package/dist/core/fee.d.ts +36 -0
  48. package/dist/core/fee.d.ts.map +1 -0
  49. package/dist/core/fee.js +40 -0
  50. package/dist/core/fee.js.map +1 -0
  51. package/dist/core/gas.d.ts +112 -0
  52. package/dist/core/gas.d.ts.map +1 -0
  53. package/dist/core/gas.js +265 -0
  54. package/dist/core/gas.js.map +1 -0
  55. package/dist/core/percent.d.ts +27 -0
  56. package/dist/core/percent.d.ts.map +1 -0
  57. package/dist/core/percent.js +71 -0
  58. package/dist/core/percent.js.map +1 -0
  59. package/dist/core/tx.d.ts +36 -0
  60. package/dist/core/tx.d.ts.map +1 -0
  61. package/dist/core/tx.js +17 -0
  62. package/dist/core/tx.js.map +1 -0
  63. package/dist/index.d.ts +63 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +41 -0
  66. package/dist/index.js.map +1 -0
  67. package/dist/jetton/index.d.ts +53 -0
  68. package/dist/jetton/index.d.ts.map +1 -0
  69. package/dist/jetton/index.js +90 -0
  70. package/dist/jetton/index.js.map +1 -0
  71. package/dist/math/clmm-swap.d.ts +80 -0
  72. package/dist/math/clmm-swap.d.ts.map +1 -0
  73. package/dist/math/clmm-swap.js +277 -0
  74. package/dist/math/clmm-swap.js.map +1 -0
  75. package/dist/math/clmm.d.ts +234 -0
  76. package/dist/math/clmm.d.ts.map +1 -0
  77. package/dist/math/clmm.js +270 -0
  78. package/dist/math/clmm.js.map +1 -0
  79. package/dist/math/cpmm.d.ts +170 -0
  80. package/dist/math/cpmm.d.ts.map +1 -0
  81. package/dist/math/cpmm.js +175 -0
  82. package/dist/math/cpmm.js.map +1 -0
  83. package/dist/math/integer.d.ts +10 -0
  84. package/dist/math/integer.d.ts.map +1 -0
  85. package/dist/math/integer.js +44 -0
  86. package/dist/math/integer.js.map +1 -0
  87. package/dist/math/q128.d.ts +45 -0
  88. package/dist/math/q128.d.ts.map +1 -0
  89. package/dist/math/q128.js +108 -0
  90. package/dist/math/q128.js.map +1 -0
  91. package/dist/moon.d.ts +245 -0
  92. package/dist/moon.d.ts.map +1 -0
  93. package/dist/moon.js +332 -0
  94. package/dist/moon.js.map +1 -0
  95. package/dist/ops/jetton-input.d.ts +3 -0
  96. package/dist/ops/jetton-input.d.ts.map +1 -0
  97. package/dist/ops/jetton-input.js +8 -0
  98. package/dist/ops/jetton-input.js.map +1 -0
  99. package/dist/ops/liquidity.d.ts +157 -0
  100. package/dist/ops/liquidity.d.ts.map +1 -0
  101. package/dist/ops/liquidity.js +413 -0
  102. package/dist/ops/liquidity.js.map +1 -0
  103. package/dist/ops/mempad.d.ts +143 -0
  104. package/dist/ops/mempad.d.ts.map +1 -0
  105. package/dist/ops/mempad.js +248 -0
  106. package/dist/ops/mempad.js.map +1 -0
  107. package/dist/ops/pool.d.ts +75 -0
  108. package/dist/ops/pool.d.ts.map +1 -0
  109. package/dist/ops/pool.js +129 -0
  110. package/dist/ops/pool.js.map +1 -0
  111. package/dist/ops/position.d.ts +47 -0
  112. package/dist/ops/position.d.ts.map +1 -0
  113. package/dist/ops/position.js +73 -0
  114. package/dist/ops/position.js.map +1 -0
  115. package/dist/ops/swap.d.ts +104 -0
  116. package/dist/ops/swap.d.ts.map +1 -0
  117. package/dist/ops/swap.js +248 -0
  118. package/dist/ops/swap.js.map +1 -0
  119. package/dist/pool/amounts.d.ts +36 -0
  120. package/dist/pool/amounts.d.ts.map +1 -0
  121. package/dist/pool/amounts.js +68 -0
  122. package/dist/pool/amounts.js.map +1 -0
  123. package/dist/pool/assets.d.ts +45 -0
  124. package/dist/pool/assets.d.ts.map +1 -0
  125. package/dist/pool/assets.js +57 -0
  126. package/dist/pool/assets.js.map +1 -0
  127. package/dist/pool/clmm.d.ts +309 -0
  128. package/dist/pool/clmm.d.ts.map +1 -0
  129. package/dist/pool/clmm.js +561 -0
  130. package/dist/pool/clmm.js.map +1 -0
  131. package/dist/pool/cpmm.d.ts +228 -0
  132. package/dist/pool/cpmm.d.ts.map +1 -0
  133. package/dist/pool/cpmm.js +332 -0
  134. package/dist/pool/cpmm.js.map +1 -0
  135. package/dist/protocol/generated.d.ts +2752 -0
  136. package/dist/protocol/generated.d.ts.map +1 -0
  137. package/dist/protocol/generated.js +3564 -0
  138. package/dist/protocol/generated.js.map +1 -0
  139. package/dist/protocol/index.d.ts +19 -0
  140. package/dist/protocol/index.d.ts.map +1 -0
  141. package/dist/protocol/index.js +49 -0
  142. package/dist/protocol/index.js.map +1 -0
  143. package/dist/state/address.d.ts +121 -0
  144. package/dist/state/address.d.ts.map +1 -0
  145. package/dist/state/address.js +143 -0
  146. package/dist/state/address.js.map +1 -0
  147. package/dist/state/source.d.ts +26 -0
  148. package/dist/state/source.d.ts.map +1 -0
  149. package/dist/state/source.js +32 -0
  150. package/dist/state/source.js.map +1 -0
  151. package/dist/state/storage.d.ts +218 -0
  152. package/dist/state/storage.d.ts.map +1 -0
  153. package/dist/state/storage.js +273 -0
  154. package/dist/state/storage.js.map +1 -0
  155. package/package.json +74 -4
@@ -0,0 +1,228 @@
1
+ import type { Address } from '@ton/core';
2
+ import { Amount } from '../core/amount.ts';
3
+ import type { Asset } from '../core/asset.ts';
4
+ import { Percent } from '../core/percent.ts';
5
+ import type { BuiltOperation } from '../core/tx.ts';
6
+ import { type StateSource } from '../state/source.ts';
7
+ import { type CpmmPoolState, type CpmmPositionState } from '../state/storage.ts';
8
+ import { type SwapQuote } from '../ops/swap.ts';
9
+ import { type CpmmDepositPlan } from '../ops/liquidity.ts';
10
+ import type { Jettons } from '../jetton/index.ts';
11
+ import { type AmountLike } from './amounts.ts';
12
+ import { type PoolDecimalsSource } from './assets.ts';
13
+ import { type Operation, type Sender } from '../adapters/sender.ts';
14
+ /**
15
+ * Who the operation is attributed to: the wallet if given, else the explicit
16
+ * `sender` address (for signing elsewhere). Throws `NoWalletError` with neither.
17
+ */
18
+ export declare function whoSends(operation: string, args: {
19
+ wallet?: Sender;
20
+ sender?: Address;
21
+ }): Address;
22
+ /**
23
+ * Assets a pool holds, in the pool's own order, with the decimals used to read
24
+ * and print amounts. Where those decimals came from is `pool.decimalsSource`.
25
+ */
26
+ export type PoolAssets = {
27
+ x: Asset;
28
+ y: Asset;
29
+ };
30
+ /**
31
+ * A CPMM pool, opened at an address. Quotes and plans use the last read state;
32
+ * call {@link CpmmPool.refresh} to update it.
33
+ */
34
+ export declare class CpmmPool {
35
+ #private;
36
+ readonly address: Address;
37
+ readonly assets: PoolAssets;
38
+ /** Where each side's decimals came from; see `DecimalsSource`. */
39
+ readonly decimalsSource: PoolDecimalsSource;
40
+ private constructor();
41
+ /**
42
+ * Reads a pool. Which token is x and which is y comes from the pool itself;
43
+ * `assets`, if given, must name the same tokens on the same sides, or this throws.
44
+ *
45
+ * Decimals are read from the jetton masters when `jettons` is given, and `assets`
46
+ * decimals are then ignored. Without it, `assets` decimals are used as given; on a
47
+ * side built from a listing entry, or with no decimals at all (shown as nine),
48
+ * amounts are accepted only as raw `bigint` (see `DecimalsSource`).
49
+ *
50
+ * @throws BuildError when `assets` names a token the pool does not hold, or
51
+ * names the pool's tokens in the other order
52
+ * @throws JettonLookupError when a master's metadata cannot be read
53
+ */
54
+ static open(source: StateSource, address: Address, options?: {
55
+ assets?: Partial<PoolAssets>;
56
+ jettons?: Jettons;
57
+ }): Promise<CpmmPool>;
58
+ /** The state this pool was last read at. */
59
+ get state(): CpmmPoolState;
60
+ get reserves(): {
61
+ x: Amount;
62
+ y: Amount;
63
+ };
64
+ get lpTotal(): bigint;
65
+ /** Total fee taken from every swap, in basis points. */
66
+ get feeBps(): number;
67
+ /** True once the pool has resolved its jetton wallets and holds liquidity. */
68
+ get isTradable(): boolean;
69
+ /** Price of X in units of Y, at the current reserves. */
70
+ get price(): number;
71
+ /** Re-reads the pool from the chain. */
72
+ refresh(): Promise<this>;
73
+ buildSwap(args: {
74
+ quote: SwapQuote;
75
+ sender: Address;
76
+ senderJettonWallet?: Address;
77
+ queryId?: bigint;
78
+ }): BuiltOperation<SwapQuote>;
79
+ /** Fills in the second side of a deposit at the pool's current ratio. */
80
+ matchDeposit(args: {
81
+ x?: AmountLike;
82
+ y?: AmountLike;
83
+ }): {
84
+ x: Amount;
85
+ y: Amount;
86
+ };
87
+ planDeposit(args: {
88
+ x: AmountLike;
89
+ y: AmountLike;
90
+ slippage: Percent;
91
+ }): CpmmDepositPlan;
92
+ buildDeposit(args: {
93
+ plan: CpmmDepositPlan;
94
+ sender: Address;
95
+ senderJettonWallets: {
96
+ x?: Address;
97
+ y?: Address;
98
+ };
99
+ /** From `(await pool.position(sender))?.isLocked` — see `CpmmDepositArgs`. */
100
+ positionLocked?: boolean;
101
+ queryId?: bigint;
102
+ }): BuiltOperation<CpmmDepositPlan>;
103
+ /**
104
+ * Prepares a deposit against freshly read reserves. Sends nothing.
105
+ * `details` carries the amounts, the expected LP and the LP floor in the message.
106
+ *
107
+ * A wallet has one position per pool and every deposit merges into it, so if
108
+ * that position is locked this deposit is locked forever too. That is not
109
+ * refused; `details.positionLocked` and a warning report it.
110
+ */
111
+ deposit(args: {
112
+ /** Give both sides, or one — the other is matched at the current ratio. */
113
+ x?: AmountLike;
114
+ y?: AmountLike;
115
+ slippage: Percent;
116
+ /** Whose operation this is, and what `send()` will sign with. */
117
+ wallet?: Sender;
118
+ /** Use when signing elsewhere: attributes the operation without a wallet. */
119
+ sender?: Address;
120
+ refresh?: boolean;
121
+ queryId?: bigint;
122
+ }): Promise<Operation<CpmmDepositPlan>>;
123
+ /**
124
+ * Prepares a swap against freshly read reserves. Sends nothing. The quote is in
125
+ * `details`; `minAmountOut` is written into the message. Pass `refresh: false`
126
+ * to quote against the state already held.
127
+ */
128
+ swap(args: {
129
+ assetIn: Asset;
130
+ /** `'50'`, `50`, `50n` for raw units, or an {@link Amount}. */
131
+ amountIn: AmountLike;
132
+ slippage: Percent;
133
+ /** Whose operation this is, and what `send()` will sign with. */
134
+ wallet?: Sender;
135
+ /** Build without sending, for this address. Ignored when `wallet` is given. */
136
+ sender?: Address;
137
+ refresh?: boolean;
138
+ queryId?: bigint;
139
+ }): Promise<Operation<SwapQuote>>;
140
+ /** The sender's own jetton wallets for this pool's sides. */
141
+ walletsOf(owner: Address): Promise<{
142
+ x?: Address;
143
+ y?: Address;
144
+ }>;
145
+ /** Address of a wallet's position in this pool. One per wallet per pool. */
146
+ positionAddress(user: Address): Address;
147
+ /** Opens a wallet's position, or `null` if it has never deposited here. */
148
+ position(user: Address): Promise<CpmmPosition | null>;
149
+ /**
150
+ * Opens a position by its address, or `null` if it is not deployed or
151
+ * deployed empty (see `cpmmPositionIsInitOnly`; anyone can deploy an empty one).
152
+ */
153
+ positionAt(address: Address): Promise<CpmmPosition | null>;
154
+ }
155
+ /** A wallet's liquidity position in a CPMM pool. */
156
+ export declare class CpmmPosition {
157
+ #private;
158
+ readonly address: Address;
159
+ readonly pool: CpmmPool;
160
+ constructor(pool: CpmmPool, address: Address, state: CpmmPositionState, source: StateSource);
161
+ /** Re-reads the position and its pool. */
162
+ refresh(): Promise<this>;
163
+ get state(): CpmmPositionState;
164
+ get lp(): bigint;
165
+ /**
166
+ * Once locked, liquidity can never be withdrawn; fees still can. Future deposits
167
+ * merge into this position and are locked too.
168
+ */
169
+ get isLocked(): boolean;
170
+ /** What the position is worth right now, principal only. */
171
+ get value(): {
172
+ x: Amount;
173
+ y: Amount;
174
+ };
175
+ /** Fees waiting to be collected. */
176
+ get pendingFees(): {
177
+ x: Amount;
178
+ y: Amount;
179
+ };
180
+ buildWithdraw(args?: {
181
+ lp?: bigint;
182
+ percent?: Percent;
183
+ queryId?: bigint;
184
+ }): BuiltOperation<{
185
+ lp: bigint;
186
+ expected: {
187
+ x: bigint;
188
+ y: bigint;
189
+ };
190
+ }>;
191
+ /** Withdraws liquidity, against freshly read position and pool state. */
192
+ withdraw(args?: {
193
+ lp?: bigint;
194
+ percent?: Percent;
195
+ /** Whose operation this is, and what `send()` will sign with. */
196
+ wallet?: Sender;
197
+ refresh?: boolean;
198
+ queryId?: bigint;
199
+ }): Promise<Operation<{
200
+ lp: bigint;
201
+ expected: {
202
+ x: bigint;
203
+ y: bigint;
204
+ };
205
+ }>>;
206
+ /** Collects accrued fees, against freshly read state. Works on a locked position too. */
207
+ collectFees(args?: {
208
+ /** Whose operation this is, and what `send()` will sign with. */
209
+ wallet?: Sender;
210
+ refresh?: boolean;
211
+ queryId?: bigint;
212
+ }): Promise<Operation<{
213
+ protocol: 'cpmm' | 'clmm';
214
+ }>>;
215
+ buildCollectFees(args?: {
216
+ queryId?: bigint;
217
+ }): BuiltOperation<{
218
+ protocol: 'cpmm' | 'clmm';
219
+ }>;
220
+ /** Locks the position permanently; there is no unlock. `confirm` must equal `LOCK_CONFIRMATION`. */
221
+ buildLockForever(args: {
222
+ confirm: string;
223
+ queryId?: bigint;
224
+ }): BuiltOperation<{
225
+ irreversible: true;
226
+ }>;
227
+ }
228
+ //# sourceMappingURL=cpmm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cpmm.d.ts","sourceRoot":"","sources":["../../src/pool/cpmm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACnE,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACvB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAA4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M,CAAC,EAAE,MAAM,CAAA;QACf,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB,GAAG,OAAO,CAAC,SAAS,CAAC;QAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC,CAAC;IAKrD,gBAAgB,CAAC,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,cAAc,CAAC;QAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAS5F,oGAAoG;IACpG,gBAAgB,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,cAAc,CAAC;QAC5E,YAAY,EAAE,IAAI,CAAA;KACnB,CAAC;CASH"}
@@ -0,0 +1,332 @@
1
+ import { Amount } from "../core/amount.js";
2
+ import { BuildError, StateError } from "../core/errors.js";
3
+ import { Percent } from "../core/percent.js";
4
+ import { readContract } from "../state/source.js";
5
+ import { cpmmPositionIsInitOnly, parseCpmmPool, parseCpmmPosition, } from "../state/storage.js";
6
+ import { cpmmLpPositionAddress } from "../state/address.js";
7
+ import { buildSwap, quoteCpmmSwap } from "../ops/swap.js";
8
+ import { buildCpmmDeposit, buildCpmmWithdraw, matchCpmmDeposit, planCpmmDeposit, } from "../ops/liquidity.js";
9
+ import { buildCollectFees, buildLockForever, cpmmPendingFees } from "../ops/position.js";
10
+ import { canonicalAsset, poolAmount } from "./amounts.js";
11
+ import { resolvePoolAssets } from "./assets.js";
12
+ import { prepared, NoWalletError } from "../adapters/sender.js";
13
+ /**
14
+ * Who the operation is attributed to: the wallet if given, else the explicit
15
+ * `sender` address (for signing elsewhere). Throws `NoWalletError` with neither.
16
+ */
17
+ export function whoSends(operation, args) {
18
+ if (args.wallet !== undefined)
19
+ return args.wallet.address;
20
+ if (args.sender !== undefined)
21
+ return args.sender;
22
+ throw new NoWalletError(operation);
23
+ }
24
+ /**
25
+ * A CPMM pool, opened at an address. Quotes and plans use the last read state;
26
+ * call {@link CpmmPool.refresh} to update it.
27
+ */
28
+ export class CpmmPool {
29
+ address;
30
+ assets;
31
+ /** Where each side's decimals came from; see `DecimalsSource`. */
32
+ decimalsSource;
33
+ #state;
34
+ #source;
35
+ #jettons;
36
+ constructor(source, address, state, resolved, jettons) {
37
+ this.#source = source;
38
+ this.address = address;
39
+ this.#state = state;
40
+ this.assets = resolved.assets;
41
+ this.decimalsSource = resolved.decimalsSource;
42
+ this.#jettons = jettons;
43
+ }
44
+ /**
45
+ * Reads a pool. Which token is x and which is y comes from the pool itself;
46
+ * `assets`, if given, must name the same tokens on the same sides, or this throws.
47
+ *
48
+ * Decimals are read from the jetton masters when `jettons` is given, and `assets`
49
+ * decimals are then ignored. Without it, `assets` decimals are used as given; on a
50
+ * side built from a listing entry, or with no decimals at all (shown as nine),
51
+ * amounts are accepted only as raw `bigint` (see `DecimalsSource`).
52
+ *
53
+ * @throws BuildError when `assets` names a token the pool does not hold, or
54
+ * names the pool's tokens in the other order
55
+ * @throws JettonLookupError when a master's metadata cannot be read
56
+ */
57
+ static async open(source, address, options) {
58
+ const state = await readContract(source, address, 'CPMM pool', parseCpmmPool);
59
+ const jettons = options?.jettons ?? null;
60
+ const resolved = await resolvePoolAssets({
61
+ pool: address,
62
+ masters: state.masters,
63
+ given: options?.assets,
64
+ jettons,
65
+ });
66
+ return new CpmmPool(source, address, state, resolved, jettons);
67
+ }
68
+ /** The state this pool was last read at. */
69
+ get state() {
70
+ return this.#state;
71
+ }
72
+ get reserves() {
73
+ return {
74
+ x: new Amount(this.#state.reserves.x, this.assets.x),
75
+ y: new Amount(this.#state.reserves.y, this.assets.y),
76
+ };
77
+ }
78
+ get lpTotal() {
79
+ return this.#state.lpTotal;
80
+ }
81
+ /** Total fee taken from every swap, in basis points. */
82
+ get feeBps() {
83
+ return this.#state.lpFeeBps + this.#state.protocolFeeBps;
84
+ }
85
+ /** True once the pool has resolved its jetton wallets and holds liquidity. */
86
+ get isTradable() {
87
+ return this.#state.walletsResolved && this.#state.lpTotal > 0n;
88
+ }
89
+ /** Price of X in units of Y, at the current reserves. */
90
+ get price() {
91
+ if (this.#state.reserves.x === 0n)
92
+ return 0;
93
+ const scale = 10 ** (this.assets.x.decimals - this.assets.y.decimals);
94
+ return (Number(this.#state.reserves.y) / Number(this.#state.reserves.x)) * scale;
95
+ }
96
+ /** Re-reads the pool from the chain. */
97
+ async refresh() {
98
+ this.#state = await readContract(this.#source, this.address, 'CPMM pool', parseCpmmPool);
99
+ return this;
100
+ }
101
+ async #quote(args) {
102
+ if (args.refresh !== false)
103
+ await this.refresh();
104
+ const assetIn = canonicalAsset(this.assets, args.assetIn, this.decimalsSource);
105
+ const side = assetIn.equals(this.assets.x) ? 'x' : 'y';
106
+ const assetOut = side === 'x' ? this.assets.y : this.assets.x;
107
+ return quoteCpmmSwap({
108
+ pool: this.address,
109
+ state: this.#state,
110
+ assetIn,
111
+ assetOut,
112
+ amountIn: poolAmount(args.amountIn, assetIn, this.decimalsSource[side]),
113
+ slippage: args.slippage,
114
+ });
115
+ }
116
+ buildSwap(args) {
117
+ return buildSwap(args);
118
+ }
119
+ /** A deposit side's amount; `x` and `y` are the pool's own sides. */
120
+ #amount(side, value) {
121
+ return poolAmount(value, this.assets[side], this.decimalsSource[side]);
122
+ }
123
+ /** Fills in the second side of a deposit at the pool's current ratio. */
124
+ matchDeposit(args) {
125
+ return matchCpmmDeposit({
126
+ state: this.#state,
127
+ assetX: this.assets.x,
128
+ assetY: this.assets.y,
129
+ ...(args.x !== undefined ? { x: this.#amount('x', args.x) } : {}),
130
+ ...(args.y !== undefined ? { y: this.#amount('y', args.y) } : {}),
131
+ });
132
+ }
133
+ planDeposit(args) {
134
+ return planCpmmDeposit({
135
+ state: this.#state,
136
+ x: this.#amount('x', args.x),
137
+ y: this.#amount('y', args.y),
138
+ slippage: args.slippage,
139
+ });
140
+ }
141
+ buildDeposit(args) {
142
+ return buildCpmmDeposit({ pool: this.address, state: this.#state, ...args });
143
+ }
144
+ /**
145
+ * Prepares a deposit against freshly read reserves. Sends nothing.
146
+ * `details` carries the amounts, the expected LP and the LP floor in the message.
147
+ *
148
+ * A wallet has one position per pool and every deposit merges into it, so if
149
+ * that position is locked this deposit is locked forever too. That is not
150
+ * refused; `details.positionLocked` and a warning report it.
151
+ */
152
+ async deposit(args) {
153
+ if (args.refresh !== false)
154
+ await this.refresh();
155
+ // The second side is matched at the freshly read ratio.
156
+ const amounts = args.x !== undefined && args.y !== undefined
157
+ ? { x: this.#amount('x', args.x), y: this.#amount('y', args.y) }
158
+ : this.matchDeposit({
159
+ ...(args.x !== undefined ? { x: args.x } : {}),
160
+ ...(args.y !== undefined ? { y: args.y } : {}),
161
+ });
162
+ const sender = whoSends('deposit', args);
163
+ // Pass raw units: a pool-matched amount must not be re-checked against unverified decimals.
164
+ const plan = this.planDeposit({ x: amounts.x.raw, y: amounts.y.raw, slippage: args.slippage });
165
+ // Read fresh, never cached: a lock can land between two calls.
166
+ const existing = await this.position(sender);
167
+ return prepared(this.buildDeposit({
168
+ plan,
169
+ sender,
170
+ senderJettonWallets: await this.walletsOf(sender),
171
+ positionLocked: existing?.isLocked ?? false,
172
+ ...(args.queryId !== undefined ? { queryId: args.queryId } : {}),
173
+ }), args.wallet);
174
+ }
175
+ /**
176
+ * Prepares a swap against freshly read reserves. Sends nothing. The quote is in
177
+ * `details`; `minAmountOut` is written into the message. Pass `refresh: false`
178
+ * to quote against the state already held.
179
+ */
180
+ async swap(args) {
181
+ const quote = await this.#quote(args);
182
+ const sender = whoSends('swap', args);
183
+ const wallets = quote.assetIn.isNative() ? {} : await this.walletsOf(sender);
184
+ // Wallet by the quote's side (`xIn` comes from storage masters, like `wallets`), not by `assets` order.
185
+ const senderJettonWallet = quote.xIn ? wallets.x : wallets.y;
186
+ return prepared(buildSwap({
187
+ quote,
188
+ sender,
189
+ ...(senderJettonWallet !== undefined ? { senderJettonWallet } : {}),
190
+ ...(args.queryId !== undefined ? { queryId: args.queryId } : {}),
191
+ }), args.wallet);
192
+ }
193
+ /** The sender's own jetton wallets for this pool's sides. */
194
+ async walletsOf(owner) {
195
+ if (this.#jettons === null) {
196
+ throw new BuildError('this pool was opened without jetton lookups — pass senderJettonWallets to ' +
197
+ 'buildDeposit, or create Moon with a client that can open jetton masters');
198
+ }
199
+ return this.#jettons.walletsFor(this.#state.masters, owner);
200
+ }
201
+ /** Address of a wallet's position in this pool. One per wallet per pool. */
202
+ positionAddress(user) {
203
+ return cpmmLpPositionAddress({
204
+ pool: this.address,
205
+ user,
206
+ lpPositionCode: this.#state.lpPositionCode,
207
+ });
208
+ }
209
+ /** Opens a wallet's position, or `null` if it has never deposited here. */
210
+ async position(user) {
211
+ const address = this.positionAddress(user);
212
+ return this.positionAt(address);
213
+ }
214
+ /**
215
+ * Opens a position by its address, or `null` if it is not deployed or
216
+ * deployed empty (see `cpmmPositionIsInitOnly`; anyone can deploy an empty one).
217
+ */
218
+ async positionAt(address) {
219
+ const account = await this.#source.getAccountState(address);
220
+ if (account === null)
221
+ return null;
222
+ let state;
223
+ try {
224
+ if (cpmmPositionIsInitOnly(account.data))
225
+ return null;
226
+ state = parseCpmmPosition(account.data);
227
+ }
228
+ catch {
229
+ throw new StateError(address, 'the position storage cannot be read');
230
+ }
231
+ if (!state.pool.equals(this.address) || !this.positionAddress(state.user).equals(address)) {
232
+ throw new StateError(address, 'the position does not belong to this pool');
233
+ }
234
+ return new CpmmPosition(this, address, state, this.#source);
235
+ }
236
+ }
237
+ /** A wallet's liquidity position in a CPMM pool. */
238
+ export class CpmmPosition {
239
+ address;
240
+ pool;
241
+ #state;
242
+ #source;
243
+ constructor(pool, address, state, source) {
244
+ this.pool = pool;
245
+ this.address = address;
246
+ this.#state = state;
247
+ this.#source = source;
248
+ }
249
+ /** Re-reads the position and its pool. */
250
+ async refresh() {
251
+ const [account] = await Promise.all([
252
+ this.#source.getAccountState(this.address),
253
+ this.pool.refresh(),
254
+ ]);
255
+ if (account === null)
256
+ throw new StateError(this.address, 'the position is no longer deployed');
257
+ this.#state = parseCpmmPosition(account.data);
258
+ return this;
259
+ }
260
+ get state() {
261
+ return this.#state;
262
+ }
263
+ get lp() {
264
+ return this.#state.lp;
265
+ }
266
+ /**
267
+ * Once locked, liquidity can never be withdrawn; fees still can. Future deposits
268
+ * merge into this position and are locked too.
269
+ */
270
+ get isLocked() {
271
+ return this.#state.locked;
272
+ }
273
+ /** What the position is worth right now, principal only. */
274
+ get value() {
275
+ const pool = this.pool.state;
276
+ if (pool.lpTotal === 0n) {
277
+ return { x: Amount.zero(this.pool.assets.x), y: Amount.zero(this.pool.assets.y) };
278
+ }
279
+ return {
280
+ x: new Amount((pool.reserves.x * this.#state.lp) / pool.lpTotal, this.pool.assets.x),
281
+ y: new Amount((pool.reserves.y * this.#state.lp) / pool.lpTotal, this.pool.assets.y),
282
+ };
283
+ }
284
+ /** Fees waiting to be collected. */
285
+ get pendingFees() {
286
+ const fees = cpmmPendingFees({ position: this.#state, pool: this.pool.state });
287
+ return {
288
+ x: new Amount(fees.x, this.pool.assets.x),
289
+ y: new Amount(fees.y, this.pool.assets.y),
290
+ };
291
+ }
292
+ buildWithdraw(args) {
293
+ return buildCpmmWithdraw({
294
+ position: this.address,
295
+ state: this.#state,
296
+ poolState: this.pool.state,
297
+ ...args,
298
+ });
299
+ }
300
+ /** Withdraws liquidity, against freshly read position and pool state. */
301
+ async withdraw(args) {
302
+ if (args?.refresh !== false)
303
+ await this.refresh();
304
+ return prepared(this.buildWithdraw(args), args?.wallet);
305
+ }
306
+ /** Collects accrued fees, against freshly read state. Works on a locked position too. */
307
+ async collectFees(args) {
308
+ if (args?.refresh !== false)
309
+ await this.refresh();
310
+ return prepared(this.buildCollectFees(args), args?.wallet);
311
+ }
312
+ buildCollectFees(args) {
313
+ return buildCollectFees({
314
+ protocol: 'cpmm',
315
+ position: this.address,
316
+ frozen: this.#state.frozen,
317
+ ...args,
318
+ });
319
+ }
320
+ /** Locks the position permanently; there is no unlock. `confirm` must equal `LOCK_CONFIRMATION`. */
321
+ buildLockForever(args) {
322
+ if (this.#state.locked)
323
+ throw new BuildError('this position is already locked');
324
+ return buildLockForever({
325
+ protocol: 'cpmm',
326
+ position: this.address,
327
+ alreadyLocked: this.#state.locked,
328
+ ...args,
329
+ });
330
+ }
331
+ }
332
+ //# sourceMappingURL=cpmm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cpmm.js","sourceRoot":"","sources":["../../src/pool/cpmm.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAE5C,OAAO,EAAE,YAAY,EAAoB,MAAM,oBAAoB,CAAA;AACnE,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,iBAAiB,GAGlB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,aAAa,EAAkB,MAAM,gBAAgB,CAAA;AACzE,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,GAEhB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAExF,OAAO,EAAE,cAAc,EAAE,UAAU,EAAmB,MAAM,cAAc,CAAA;AAC1E,OAAO,EAAE,iBAAiB,EAA2B,MAAM,aAAa,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAA+B,MAAM,uBAAuB,CAAA;AAE5F;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,SAAiB,EAAE,IAA2C;IACrF,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;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