@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,248 @@
1
+ import { BuildError, LimitExceededError } from "../core/errors.js";
2
+ import { FEE_BPS } from "../core/fee.js";
3
+ import { mempadBuyGas } from "../core/gas.js";
4
+ import { randomQueryId } from "../core/tx.js";
5
+ import * as mempad from "../codec/mempad.js";
6
+ import { mempadCurveAddress } from "../state/address.js";
7
+ /*
8
+ * Mempad: launching a token on a bonding curve and trading against it. Built
9
+ * offline; only the factory's `launchFee` (in its c4, changes on upgrade) has to
10
+ * be read from chain. `Moon.createCurve` reads it for you.
11
+ *
12
+ * - create: the factory keeps its launch fee and forwards the rest to the curve.
13
+ * - buy: the curve subtracts its gas overhead from the attached value, so `value`
14
+ * here is the purchase and the computed gas ({@link mempadBuyGas}) rides on top.
15
+ * - sell: a sale is a burn with a marker. Without it a trading curve refuses (555)
16
+ * and a graduated one burns the tokens and pays nothing.
17
+ */
18
+ /**
19
+ * Pool fee tiers the factory accepts; anything else is `INVALID_PAYLOAD` (700).
20
+ * Same as CPMM's {@link FEE_BPS}: it is the fee of the CPMM pool the curve graduates into.
21
+ */
22
+ export const MEMPAD_FEE_BPS = FEE_BPS;
23
+ /**
24
+ * Trade and creator fees per tier, from the factory's `feesForTier`.
25
+ * The creator's cut is not a fixed share of the trade fee.
26
+ */
27
+ export const MEMPAD_FEE_TIERS = {
28
+ 10: { tradeFeeBps: 20, creatorFeeBps: 10 },
29
+ 20: { tradeFeeBps: 40, creatorFeeBps: 30 },
30
+ 30: { tradeFeeBps: 60, creatorFeeBps: 50 },
31
+ 50: { tradeFeeBps: 100, creatorFeeBps: 80 },
32
+ 100: { tradeFeeBps: 200, creatorFeeBps: 150 },
33
+ 200: { tradeFeeBps: 400, creatorFeeBps: 300 },
34
+ };
35
+ /**
36
+ * Default sell attachment in nanograms: 0.06 GRAM, not the wallet's 0.05 gate
37
+ * (exit 48). The burn notification
38
+ * forwards what is left in mode 64, and at exactly 0.05 the curve falls short of its
39
+ * own gate. The unspent part is returned with the payout.
40
+ */
41
+ export const MEMPAD_SELL_ATTACH = 60000000n;
42
+ /** The wallet's own floor. Attaching less is exit 48 before anything happens. */
43
+ export const MEMPAD_SELL_MIN_ATTACH = mempad.MEMPAD_VALUE_JETTON_TRANSFER;
44
+ /**
45
+ * Value a deploy must attach: the factory's flat cost, the launch fee and the initial buy.
46
+ * Gas for the initial buy is not added: the curve covers it from the flat cost.
47
+ */
48
+ export function createLaunchValue(launchFee, initialBuy) {
49
+ return mempad.MEMPAD_VALUE_CREATE_LAUNCH + launchFee + initialBuy;
50
+ }
51
+ /**
52
+ * Message value for a purchase of `net` nanograms: `net` plus the computed gas
53
+ * ({@link mempadBuyGas}), as {@link buildCurveBuy} attaches by default.
54
+ * `prices` is only for a chain whose config 21 differs from mainnet's.
55
+ */
56
+ export function buyValueForSpend(net, prices) {
57
+ const gas = mempadBuyGas(prices).overhead;
58
+ if (net < mempad.MEMPAD_VALUE_MIN_BUY) {
59
+ throw new BuildError(`mempad buy: the curve's minimum is ${mempad.MEMPAD_VALUE_MIN_BUY} nanograms ` +
60
+ `(VALUE_MIN_BUY), got ${net}`);
61
+ }
62
+ return net + gas;
63
+ }
64
+ // Bytes the factory rejects in name and symbol: below 0x20, and 0x7f. Kept as
65
+ // escapes: a literal control byte in source is invisible and easily lost.
66
+ const CONTROL_BYTE = /[\u0000-\u001f\u007f]/;
67
+ function byteLength(text) {
68
+ return Buffer.from(text, 'utf8').length;
69
+ }
70
+ function checkField(value, field, maxBytes, maxCells) {
71
+ const bytes = byteLength(value);
72
+ if (bytes === 0) {
73
+ throw new BuildError(`mempad create: ${field} is empty — snakeField asserts bits > 0 ` +
74
+ '(INVALID_METADATA 701)');
75
+ }
76
+ if (bytes > maxBytes) {
77
+ throw new LimitExceededError(`mempad create: ${field} in bytes`, maxBytes, bytes, 'The factory counts BYTES, not characters — Cyrillic costs two per letter and an emoji ' +
78
+ 'four (INVALID_METADATA 701).');
79
+ }
80
+ const cells = mempad.snakeCells(value);
81
+ if (maxCells !== null && cells > maxCells) {
82
+ throw new LimitExceededError(`mempad create: ${field} in cells`, maxCells, cells, 'snakeField asserts the chain is strictly linear, so it cannot be split differently.');
83
+ }
84
+ }
85
+ /**
86
+ * Builds a token launch: one message to the factory.
87
+ *
88
+ * `launchFee` has no default: it lives in the factory's c4 and can change on upgrade.
89
+ * Pass `curveCode` (also from c4) to predict the curve address. A repeated
90
+ * `(factory, creator, salt)` does not throw but the factory keeps the fee, so check
91
+ * the predicted address for an existing curve before signing.
92
+ */
93
+ export function buildCreateCurve(args) {
94
+ if (!MEMPAD_FEE_BPS.includes(args.feeBps)) {
95
+ throw new BuildError(`mempad create: fee must be one of ${MEMPAD_FEE_BPS.join(', ')} basis points, ` +
96
+ `got ${args.feeBps} (INVALID_PAYLOAD 700)`);
97
+ }
98
+ const initialBuy = args.initialBuy ?? 0n;
99
+ if (initialBuy < 0n)
100
+ throw new BuildError('mempad create: initialBuy is negative');
101
+ if (initialBuy !== 0n && initialBuy < mempad.MEMPAD_VALUE_MIN_BUY) {
102
+ throw new BuildError(`mempad create: initialBuy must be exactly 0 or at least ${mempad.MEMPAD_VALUE_MIN_BUY} ` +
103
+ `nanograms, got ${initialBuy} (INVALID_PAYLOAD 700). ` +
104
+ 'The factory checks this after it has taken the launch fee.');
105
+ }
106
+ if (args.launchFee < 0n)
107
+ throw new BuildError('mempad create: launchFee is negative');
108
+ const meta = args.metadata;
109
+ const limits = mempad.MEMPAD_META_LIMITS;
110
+ checkField(meta.name, 'name', limits.nameBytes, 1);
111
+ checkField(meta.symbol, 'symbol', limits.symbolBytes, 1);
112
+ checkField(meta.image, 'image', limits.imageBytes, limits.imageCells);
113
+ if (meta.description) {
114
+ checkField(meta.description, 'description', limits.descriptionBytes, limits.descriptionCells);
115
+ }
116
+ for (const [field, value] of Object.entries(meta.links ?? {})) {
117
+ if (value)
118
+ checkField(value, `links.${field}`, limits.linkBytes, 1);
119
+ }
120
+ // Only name and symbol are scanned, matching the factory.
121
+ for (const [field, value] of [['name', meta.name], ['symbol', meta.symbol]]) {
122
+ if (CONTROL_BYTE.test(value)) {
123
+ throw new BuildError(`mempad create: ${field} contains a control byte — every byte must be >= 0x20 and != 0x7f ` +
124
+ '(INVALID_METADATA 701)');
125
+ }
126
+ }
127
+ if (meta.links && !meta.description) {
128
+ throw new BuildError('mempad create: links need a description — the on-chain metadata layout declares it ' +
129
+ '`cell`, not `cell?`, so links without one cannot be encoded');
130
+ }
131
+ const salt = args.salt ?? randomQueryId();
132
+ const queryId = args.queryId ?? salt & 0xffffffffn;
133
+ const tier = MEMPAD_FEE_TIERS[args.feeBps];
134
+ return {
135
+ txs: [
136
+ {
137
+ to: args.factory,
138
+ value: createLaunchValue(args.launchFee, initialBuy),
139
+ body: mempad.encodeCreateLaunch({
140
+ queryId,
141
+ salt,
142
+ feeBps: args.feeBps,
143
+ initialBuy,
144
+ content: mempad.encodeLaunchContent(meta),
145
+ }),
146
+ },
147
+ ],
148
+ queryId,
149
+ details: {
150
+ salt,
151
+ feeBps: args.feeBps,
152
+ tradeFeeBps: tier.tradeFeeBps,
153
+ creatorFeeBps: tier.creatorFeeBps,
154
+ initialBuy,
155
+ launchFee: args.launchFee,
156
+ curve: args.curveCode
157
+ ? mempadCurveAddress({
158
+ factory: args.factory,
159
+ creator: args.creator,
160
+ salt,
161
+ curveCode: args.curveCode,
162
+ })
163
+ : null,
164
+ },
165
+ warnings: [],
166
+ };
167
+ }
168
+ /**
169
+ * Builds a purchase on the curve.
170
+ *
171
+ * `value` is the purchase, not the TON message value: the curve computes
172
+ * `gross = msgValue - requiredGas`, so by default the computed overhead
173
+ * ({@link mempadBuyGas}) is added on top and exactly `value` reaches the curve.
174
+ * Pass `gasIncluded: true` to make `value` the whole message instead (for example,
175
+ * to spend a wallet's last GRAM).
176
+ */
177
+ export function buildCurveBuy(args) {
178
+ const gas = mempadBuyGas(args.prices);
179
+ const minOut = args.minOut ?? 0n;
180
+ if (minOut < 0n)
181
+ throw new BuildError('mempad buy: minOut is negative');
182
+ if (args.value < 0n)
183
+ throw new BuildError('mempad buy: value is negative');
184
+ const value = args.gasIncluded === true ? args.value : args.value + gas.overhead;
185
+ const spend = value - gas.overhead;
186
+ if (spend < mempad.MEMPAD_VALUE_MIN_BUY) {
187
+ throw new BuildError(args.gasIncluded === true
188
+ ? `mempad buy: value ${args.value} is below the curve's gate of ${gas.minimum} ` +
189
+ `nanograms — the curve takes ${gas.overhead} for gas first, leaving ${spend} to buy ` +
190
+ `with, and the curve answers LOW_AMOUNT (510). ${gas.gate}`
191
+ : `mempad buy: the curve's smallest purchase is ${mempad.MEMPAD_VALUE_MIN_BUY} nanograms ` +
192
+ `(VALUE_MIN_BUY), got ${args.value} — the curve answers LOW_AMOUNT (510). ` +
193
+ 'Gas is not the problem here: it is already ' +
194
+ 'being added on top of this number.');
195
+ }
196
+ const queryId = args.queryId ?? randomQueryId();
197
+ return {
198
+ txs: [{ to: args.curve, value, body: mempad.encodeBuy({ queryId, minOut }) }],
199
+ queryId,
200
+ details: { value, requiredGas: gas.overhead, spend, minOut },
201
+ warnings: [],
202
+ };
203
+ }
204
+ /**
205
+ * Builds a sale back to the curve.
206
+ *
207
+ * The message goes to the seller's own jetton wallet, not to the curve. That
208
+ * address is sharded (not the plain state-init hash), so derive it with
209
+ * `mempadJettonWalletAddress`. `owner` becomes `sendExcessesTo`, where the change goes.
210
+ */
211
+ export function buildCurveSell(args) {
212
+ if (args.amount <= 0n) {
213
+ throw new BuildError('mempad sell: amount must be greater than zero');
214
+ }
215
+ const minOut = args.minOut ?? 0n;
216
+ if (minOut < 0n)
217
+ throw new BuildError('mempad sell: minOut is negative');
218
+ const attach = args.attach ?? MEMPAD_SELL_ATTACH;
219
+ if (attach < MEMPAD_SELL_MIN_ATTACH) {
220
+ throw new BuildError(`mempad sell: attaching ${attach} is below the wallet's gate of ${MEMPAD_SELL_MIN_ATTACH} ` +
221
+ 'nanograms — it answers NotEnoughGas (48)');
222
+ }
223
+ const queryId = args.queryId ?? randomQueryId();
224
+ const warnings = [];
225
+ if (attach < MEMPAD_SELL_ATTACH) {
226
+ warnings.push(`attaching ${attach} clears the wallet's gate but may leave the curve short: ` +
227
+ 'the burn notification carries what is left of this value, and the surplus ' +
228
+ 'is returned with the payout anyway');
229
+ }
230
+ return {
231
+ txs: [
232
+ {
233
+ to: args.jettonWallet,
234
+ value: attach,
235
+ body: mempad.encodeAskToBurn({
236
+ queryId,
237
+ jettonAmount: args.amount,
238
+ sendExcessesTo: args.owner,
239
+ customPayload: mempad.encodeSellPayload({ minOut }),
240
+ }),
241
+ },
242
+ ],
243
+ queryId,
244
+ details: { amount: args.amount, minOut, attach },
245
+ warnings,
246
+ };
247
+ }
248
+ //# sourceMappingURL=mempad.js.map
@@ -0,0 +1 @@
1
+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E,CAAC;QACpC,MAAM,IAAI,UAAU,CAClB,0BAA0B,MAAM,kCAAkC,sBAAsB,GAAG;YACzF,0CAA0C,CAC7C,CAAA;IACH,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,aAAa,EAAE,CAAA;IAC/C,MAAM,QAAQ,GAAa,EAAE,CAAA;IAC7B,IAAI,MAAM,GAAG,kBAAkB,EAAE,CAAC;QAChC,QAAQ,CAAC,IAAI,CACX,aAAa,MAAM,2DAA2D;YAC5E,4EAA4E;YAC5E,oCAAoC,CACvC,CAAA;IACH,CAAC;IAED,OAAO;QACL,GAAG,EAAE;YACH;gBACE,EAAE,EAAE,IAAI,CAAC,YAAY;gBACrB,KAAK,EAAE,MAAM;gBACb,IAAI,EAAE,MAAM,CAAC,eAAe,CAAC;oBAC3B,OAAO;oBACP,YAAY,EAAE,IAAI,CAAC,MAAM;oBACzB,cAAc,EAAE,IAAI,CAAC,KAAK;oBAC1B,aAAa,EAAE,MAAM,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;iBACpD,CAAC;aACH;SACF;QACD,OAAO;QACP,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;QAChD,QAAQ;KACT,CAAA;AACH,CAAC"}
@@ -0,0 +1,75 @@
1
+ import type { Address } from '@ton/core';
2
+ import { type Asset } from '../core/asset.ts';
3
+ import { type FeeBps } from '../core/fee.ts';
4
+ import { type BuiltOperation } from '../core/tx.ts';
5
+ import { type BinStep } from '../math/clmm.ts';
6
+ /** Minimum the CPMM factory accepts to deploy a pool, in nanotons. */
7
+ export declare const CPMM_CREATE_POOL_GAS = 1000000000n;
8
+ /** Value attached to a CPMM pool deployment: the gate plus margin for the deploy cascade. */
9
+ export declare const CPMM_CREATE_POOL_ATTACH = 1200000000n;
10
+ /** Minimum the CLMM factory accepts, in nanotons. It deploys three ranges. */
11
+ export declare const CLMM_CREATE_POOL_GAS = 4000000000n;
12
+ /** Value attached to a CLMM pool deployment, with margin. */
13
+ export declare const CLMM_CREATE_POOL_ATTACH = 4200000000n;
14
+ export type PoolCreation = {
15
+ /** The pair as the factory will store it. */
16
+ x: Asset;
17
+ y: Asset;
18
+ /** True when the factory's order is the reverse of what you passed. */
19
+ inverted: boolean;
20
+ };
21
+ export type CpmmPoolCreation = PoolCreation & {
22
+ /** The fee chosen by the creator; stored in the pool forever. */
23
+ lpFeeBps: number;
24
+ /** The factory's own cut, derived from `lpFeeBps` — shown, never sent. */
25
+ protocolFeeBps: number;
26
+ };
27
+ export type ClmmPoolCreation = PoolCreation & {
28
+ binStep: BinStep;
29
+ /** The starting bin, computed for the pair in the factory's order. */
30
+ initBin: number;
31
+ /** The price that bin actually represents, in the factory's orientation. */
32
+ initPrice: number;
33
+ /** Which range will hold the starting price. */
34
+ rangeNum: number;
35
+ };
36
+ /** Pool fees the CPMM factory accepts, in basis points. Alias of {@link FEE_BPS}. */
37
+ export declare const CPMM_FEE_BPS: readonly [10, 20, 30, 50, 100, 200];
38
+ export type CpmmFeeBps = FeeBps;
39
+ /**
40
+ * Builds a CPMM pool deployment. The factory orders the pair itself; CPMM carries
41
+ * no price, so the order does not matter to the caller.
42
+ */
43
+ export declare function buildCpmmCreatePool(args: {
44
+ factory: Address;
45
+ assetA: Asset;
46
+ assetB: Asset;
47
+ /**
48
+ * Basis points: 10 = 0.10%, 20 = 0.20%, 30 = 0.30%, 50 = 0.50%,
49
+ * 100 = 1.00%, 200 = 2.00%. Write the number, or `FeeTier.Bps30`.
50
+ * Stored in the pool forever.
51
+ */
52
+ feeBps: CpmmFeeBps;
53
+ queryId?: bigint;
54
+ }): BuiltOperation<CpmmPoolCreation>;
55
+ /**
56
+ * Builds a CLMM pool deployment.
57
+ *
58
+ * `price` is how many `assetB` one `assetA` buys, written as a person would.
59
+ * If the factory's order turns out to be the other way round, the price is
60
+ * inverted along with the pair, so the pool opens where you meant it to.
61
+ */
62
+ export declare function buildClmmCreatePool(args: {
63
+ factory: Address;
64
+ assetA: Asset;
65
+ assetB: Asset;
66
+ /**
67
+ * Basis points per bin: 25 = 0.25%, 50 = 0.50%, 100 = 1.00%, 200 = 2.00%.
68
+ * Write the number, or `BinStep.Bps25`.
69
+ */
70
+ binStep: BinStep;
71
+ /** Starting price: units of `assetB` per one `assetA`. */
72
+ price: number;
73
+ queryId?: bigint;
74
+ }): BuiltOperation<ClmmPoolCreation>;
75
+ //# sourceMappingURL=pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/ops/pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAe,KAAK,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAE1D,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAA;AAGlE,OAAO,EAQL,KAAK,OAAO,EACb,MAAM,iBAAiB,CAAA;AAOxB,sEAAsE;AACtE,eAAO,MAAM,oBAAoB,cAAiB,CAAA;AAClD,6FAA6F;AAC7F,eAAO,MAAM,uBAAuB,cAAiB,CAAA;AAErD,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB,cAAiB,CAAA;AAClD,6DAA6D;AAC7D,eAAO,MAAM,uBAAuB,cAAiB,CAAA;AAErD,MAAM,MAAM,YAAY,GAAG;IACzB,6CAA6C;IAC7C,CAAC,EAAE,KAAK,CAAA;IACR,CAAC,EAAE,KAAK,CAAA;IACR,uEAAuE;IACvE,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG;IAC5C,iEAAiE;IACjE,QAAQ,EAAE,MAAM,CAAA;IAChB,0EAA0E;IAC1E,cAAc,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG;IAC5C,OAAO,EAAE,OAAO,CAAA;IAChB,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAA;IACf,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAA;IACjB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,qFAAqF;AACrF,eAAO,MAAM,YAAY,qCAAU,CAAA;AACnC,MAAM,MAAM,UAAU,GAAG,MAAM,CAAA;AAa/B;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IACxC,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,KAAK,CAAA;IACb,MAAM,EAAE,KAAK,CAAA;IACb;;;;OAIG;IACH,MAAM,EAAE,UAAU,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,GAAG,cAAc,CAAC,gBAAgB,CAAC,CAiCnC;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IACxC,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,KAAK,CAAA;IACb,MAAM,EAAE,KAAK,CAAA;IACb;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAA;IAChB,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,GAAG,cAAc,CAAC,gBAAgB,CAAC,CAqEnC"}
@@ -0,0 +1,129 @@
1
+ import { orderAssets } from "../core/asset.js";
2
+ import { BuildError, LimitExceededError } from "../core/errors.js";
3
+ import { FEE_BPS } from "../core/fee.js";
4
+ import { randomQueryId } from "../core/tx.js";
5
+ import * as cpmmCodec from "../codec/cpmm.js";
6
+ import * as clmmCodec from "../codec/clmm.js";
7
+ import { BIN_STEPS, RANGE_MAX, RANGE_MIN, isBinStep, nearestBinToHumanPrice, priceAtBin, rangeOfBin, } from "../math/clmm.js";
8
+ /*
9
+ * The factories reorder the pair's masters but leave every other field alone, so a
10
+ * starting price must be inverted along with the pair or the pool opens at the inverse.
11
+ */
12
+ /** Minimum the CPMM factory accepts to deploy a pool, in nanotons. */
13
+ export const CPMM_CREATE_POOL_GAS = 1000000000n;
14
+ /** Value attached to a CPMM pool deployment: the gate plus margin for the deploy cascade. */
15
+ export const CPMM_CREATE_POOL_ATTACH = 1200000000n;
16
+ /** Minimum the CLMM factory accepts, in nanotons. It deploys three ranges. */
17
+ export const CLMM_CREATE_POOL_GAS = 4000000000n;
18
+ /** Value attached to a CLMM pool deployment, with margin. */
19
+ export const CLMM_CREATE_POOL_ATTACH = 4200000000n;
20
+ /** Pool fees the CPMM factory accepts, in basis points. Alias of {@link FEE_BPS}. */
21
+ export const CPMM_FEE_BPS = FEE_BPS;
22
+ // Protocol fee per tier as the factory derives it (`protocolFeeFor`).
23
+ // Never sent; surfaced in `details` so the full swap fee can be shown.
24
+ const PROTOCOL_FEE_FOR = {
25
+ 10: 5,
26
+ 20: 10,
27
+ 30: 10,
28
+ 50: 20,
29
+ 100: 20,
30
+ 200: 50,
31
+ };
32
+ /**
33
+ * Builds a CPMM pool deployment. The factory orders the pair itself; CPMM carries
34
+ * no price, so the order does not matter to the caller.
35
+ */
36
+ export function buildCpmmCreatePool(args) {
37
+ // Checked at runtime too: JavaScript callers can pass any number.
38
+ if (!CPMM_FEE_BPS.includes(args.feeBps)) {
39
+ throw new BuildError(`pool fee must be one of ${CPMM_FEE_BPS.join(', ')} basis points, got ${args.feeBps}`);
40
+ }
41
+ const { x, y, inverted } = orderAssets(args.assetA, args.assetB);
42
+ const queryId = args.queryId ?? randomQueryId();
43
+ return {
44
+ txs: [
45
+ {
46
+ to: args.factory,
47
+ value: CPMM_CREATE_POOL_ATTACH,
48
+ body: cpmmCodec.encodeCreatePool({
49
+ queryId,
50
+ xMaster: x.master,
51
+ yMaster: y.master,
52
+ feeBps: args.feeBps,
53
+ }),
54
+ },
55
+ ],
56
+ queryId,
57
+ details: {
58
+ x,
59
+ y,
60
+ inverted,
61
+ lpFeeBps: args.feeBps,
62
+ protocolFeeBps: PROTOCOL_FEE_FOR[args.feeBps],
63
+ },
64
+ warnings: [],
65
+ };
66
+ }
67
+ /**
68
+ * Builds a CLMM pool deployment.
69
+ *
70
+ * `price` is how many `assetB` one `assetA` buys, written as a person would.
71
+ * If the factory's order turns out to be the other way round, the price is
72
+ * inverted along with the pair, so the pool opens where you meant it to.
73
+ */
74
+ export function buildClmmCreatePool(args) {
75
+ // Checked at runtime too: JavaScript callers and parsed state can pass any number.
76
+ if (!isBinStep(args.binStep)) {
77
+ throw new BuildError(`bin step must be one of ${BIN_STEPS.join(', ')} basis points, got ${args.binStep}`);
78
+ }
79
+ if (!(args.price > 0) || !Number.isFinite(args.price)) {
80
+ throw new BuildError('the starting price must be a finite number greater than zero');
81
+ }
82
+ const { x, y, inverted } = orderAssets(args.assetA, args.assetB);
83
+ const price = inverted ? 1 / args.price : args.price;
84
+ // Deliberately the nearest bin, not the one containing the price: the factory accepts
85
+ // any initBin inside the ranges, and nearest keeps the
86
+ // drift under binStep/2, while flooring would trip the drift warning below for about half of all pools.
87
+ const initBin = nearestBinToHumanPrice({
88
+ price,
89
+ binStep: args.binStep,
90
+ decimalsX: x.decimals,
91
+ decimalsY: y.decimals,
92
+ });
93
+ const rangeNum = rangeOfBin(initBin);
94
+ if (rangeNum < RANGE_MIN || rangeNum > RANGE_MAX) {
95
+ throw new LimitExceededError(`a starting price of ${args.price} lands on bin ${initBin}, outside the ranges the ` +
96
+ 'factory deploys', RANGE_MAX, rangeNum, `Bins ${RANGE_MIN * 2048 - 1024}…${RANGE_MAX * 2048 + 1023} are available at this bin step.`);
97
+ }
98
+ const queryId = args.queryId ?? randomQueryId();
99
+ const initPrice = priceAtBin(initBin, args.binStep, x.decimals, y.decimals);
100
+ const warnings = [];
101
+ if (inverted) {
102
+ warnings.push(`the factory stores this pair as ${x.symbol ?? x.toString()}/${y.symbol ?? y.toString()}, ` +
103
+ `so the starting price was inverted to ${initPrice}`);
104
+ }
105
+ // Bins quantise the price; warn when the drift exceeds half a step.
106
+ const drift = Math.abs(initPrice - (inverted ? 1 / args.price : args.price));
107
+ if (drift / initPrice > args.binStep / 10_000 / 2) {
108
+ warnings.push(`the nearest bin prices this pool at ${initPrice}, not exactly what you asked`);
109
+ }
110
+ return {
111
+ txs: [
112
+ {
113
+ to: args.factory,
114
+ value: CLMM_CREATE_POOL_ATTACH,
115
+ body: clmmCodec.encodeCreatePool({
116
+ queryId,
117
+ xMaster: x.master,
118
+ yMaster: y.master,
119
+ binStep: args.binStep,
120
+ initBin,
121
+ }),
122
+ },
123
+ ],
124
+ queryId,
125
+ details: { x, y, inverted, binStep: args.binStep, initBin, initPrice, rangeNum },
126
+ warnings,
127
+ };
128
+ }
129
+ //# sourceMappingURL=pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.js","sourceRoot":"","sources":["../../src/ops/pool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAc,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,EAAE,OAAO,EAAe,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAuB,MAAM,eAAe,CAAA;AAClE,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EACL,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,sBAAsB,EACtB,UAAU,EACV,UAAU,GAEX,MAAM,iBAAiB,CAAA;AAExB;;;GAGG;AAEH,sEAAsE;AACtE,MAAM,CAAC,MAAM,oBAAoB,GAAG,WAAc,CAAA;AAClD,6FAA6F;AAC7F,MAAM,CAAC,MAAM,uBAAuB,GAAG,WAAc,CAAA;AAErD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,oBAAoB,GAAG,WAAc,CAAA;AAClD,6DAA6D;AAC7D,MAAM,CAAC,MAA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,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE;QAChF,QAAQ;KACT,CAAA;AACH,CAAC"}
@@ -0,0 +1,47 @@
1
+ import type { Address } from '@ton/core';
2
+ import { type BuiltOperation } from '../core/tx.ts';
3
+ import type { ClmmPositionState, CpmmPoolState, CpmmPositionState } from '../state/storage.ts';
4
+ /** Fees a CPMM position can collect right now. */
5
+ export declare function cpmmPendingFees(args: {
6
+ position: CpmmPositionState;
7
+ pool: CpmmPoolState;
8
+ }): {
9
+ x: bigint;
10
+ y: bigint;
11
+ };
12
+ /**
13
+ * Builds a fee collection. Works on a locked position too: locking stops
14
+ * withdrawals, not fee income.
15
+ */
16
+ export declare function buildCollectFees(args: {
17
+ protocol: 'cpmm' | 'clmm';
18
+ position: Address;
19
+ /** CPMM only: a frozen position is mid-settlement and will reject. */
20
+ frozen?: boolean;
21
+ /** CLMM only: a position with a withdrawal or fee collection in flight will reject. */
22
+ pending?: boolean;
23
+ queryId?: bigint;
24
+ }): BuiltOperation<{
25
+ protocol: 'cpmm' | 'clmm';
26
+ }>;
27
+ /** The exact phrase `lockForever` requires, so the call cannot be made by accident. */
28
+ export declare const LOCK_CONFIRMATION = "lock this liquidity forever";
29
+ export type LockArgs = {
30
+ protocol: 'cpmm' | 'clmm';
31
+ position: Address;
32
+ /**
33
+ * Must be exactly {@link LOCK_CONFIRMATION}. Neither protocol has an unlock
34
+ * message: a locked position keeps earning fees and never returns its principal.
35
+ */
36
+ confirm: string;
37
+ /** Already locked, read from the position's own state. */
38
+ alreadyLocked?: boolean;
39
+ queryId?: bigint;
40
+ };
41
+ /** Builds an irreversible position lock. The liquidity stays in the pool permanently; fees remain collectable. */
42
+ export declare function buildLockForever(args: LockArgs): BuiltOperation<{
43
+ irreversible: true;
44
+ }>;
45
+ /** Whether a position is locked, from either protocol's state. */
46
+ export declare function isLocked(state: CpmmPositionState | ClmmPositionState): boolean;
47
+ //# sourceMappingURL=position.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../src/ops/position.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAQxC,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAA;AAIlE,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAE9F,kDAAkD;AAClD,wBAAgB,eAAe,CAAC,IAAI,EAAE;IACpC,QAAQ,EAAE,iBAAiB,CAAA;IAC3B,IAAI,EAAE,aAAa,CAAA;CACpB,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAM3B;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;IACzB,QAAQ,EAAE,OAAO,CAAA;IACjB,sEAAsE;IACtE,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,uFAAuF;IACvF,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,GAAG,cAAc,CAAC;IAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC,CAqBhD;AAED,uFAAuF;AACvF,eAAO,MAAM,iBAAiB,gCAAgC,CAAA;AAE9D,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;IACzB,QAAQ,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAA;IACf,0DAA0D;IAC1D,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,kHAAkH;AAClH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,GAAG,cAAc,CAAC;IAAE,YAAY,EAAE,IAAI,CAAA;CAAE,CAAC,CAgCvF;AAED,kEAAkE;AAClE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,iBAAiB,GAAG,iBAAiB,GAAG,OAAO,CAE9E"}
@@ -0,0 +1,73 @@
1
+ import { BuildError } from "../core/errors.js";
2
+ import { clmmCollectFeesGas, clmmLockGas, cpmmCollectFeesGas, cpmmLockGas, } from "../core/gas.js";
3
+ import { randomQueryId } from "../core/tx.js";
4
+ import * as cpmmCodec from "../codec/cpmm.js";
5
+ import * as clmmCodec from "../codec/clmm.js";
6
+ import { pendingFees } from "../math/cpmm.js";
7
+ /** Fees a CPMM position can collect right now. */
8
+ export function cpmmPendingFees(args) {
9
+ return pendingFees({
10
+ lp: args.position.lp,
11
+ feesLp: args.pool.feesLp,
12
+ checkpoint: args.position.feeCheckpoint,
13
+ });
14
+ }
15
+ /**
16
+ * Builds a fee collection. Works on a locked position too: locking stops
17
+ * withdrawals, not fee income.
18
+ */
19
+ export function buildCollectFees(args) {
20
+ if (args.frozen === true) {
21
+ throw new BuildError('this position is settling a previous operation — try again shortly');
22
+ }
23
+ if (args.pending === true) {
24
+ throw new BuildError('this position is settling a withdrawal or fee collection — try again once it settles');
25
+ }
26
+ const queryId = args.queryId ?? randomQueryId();
27
+ const gas = args.protocol === 'cpmm' ? cpmmCollectFeesGas() : clmmCollectFeesGas();
28
+ const body = args.protocol === 'cpmm'
29
+ ? cpmmCodec.encodeWithdrawFees({ queryId })
30
+ : clmmCodec.encodeWithdrawFees({ queryId });
31
+ return {
32
+ txs: [{ to: args.position, value: gas.attach, body }],
33
+ queryId,
34
+ details: { protocol: args.protocol },
35
+ warnings: [],
36
+ };
37
+ }
38
+ /** The exact phrase `lockForever` requires, so the call cannot be made by accident. */
39
+ export const LOCK_CONFIRMATION = 'lock this liquidity forever';
40
+ /** Builds an irreversible position lock. The liquidity stays in the pool permanently; fees remain collectable. */
41
+ export function buildLockForever(args) {
42
+ if (args.confirm !== LOCK_CONFIRMATION) {
43
+ throw new BuildError('locking a position cannot be undone by anyone, ever. ' +
44
+ `To go ahead, pass confirm: ${JSON.stringify(LOCK_CONFIRMATION)}.`);
45
+ }
46
+ if (args.alreadyLocked === true) {
47
+ throw new BuildError('this position is already locked');
48
+ }
49
+ const queryId = args.queryId ?? randomQueryId();
50
+ const gas = args.protocol === 'cpmm' ? cpmmLockGas() : clmmLockGas();
51
+ const body = args.protocol === 'cpmm'
52
+ ? cpmmCodec.encodeLockLiquidity({ queryId })
53
+ : clmmCodec.encodeLockLiquidity({ queryId });
54
+ return {
55
+ txs: [{ to: args.position, value: gas.attach, body }],
56
+ queryId,
57
+ details: { irreversible: true },
58
+ warnings: [
59
+ 'this cannot be undone: the liquidity stays in the pool permanently',
60
+ 'fees can still be collected afterwards',
61
+ // CPMM has one position per wallet per pool and later deposits merge into it
62
+ // with the lock kept; CLMM deploys a new position.
63
+ ...(args.protocol === 'cpmm'
64
+ ? ['every later deposit from this wallet into this pool merges into this position and is locked too']
65
+ : []),
66
+ ],
67
+ };
68
+ }
69
+ /** Whether a position is locked, from either protocol's state. */
70
+ export function isLocked(state) {
71
+ return state.locked;
72
+ }
73
+ //# sourceMappingURL=position.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"position.js","sourceRoot":"","sources":["../../src/ops/position.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,WAAW,GACZ,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,aAAa,EAAuB,MAAM,eAAe,CAAA;AAClE,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAG7C,kDAAkD;A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