@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.
- package/CHANGELOG.md +18 -0
- package/README.md +2 -2
- package/dist/adapters/sender.d.ts +88 -0
- package/dist/adapters/sender.d.ts.map +1 -0
- package/dist/adapters/sender.js +62 -0
- package/dist/adapters/sender.js.map +1 -0
- package/dist/adapters/tonclient.d.ts +13 -0
- package/dist/adapters/tonclient.d.ts.map +1 -0
- package/dist/adapters/tonclient.js +17 -0
- package/dist/adapters/tonclient.js.map +1 -0
- package/dist/api/index.d.ts +210 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +364 -0
- package/dist/api/index.js.map +1 -0
- package/dist/codec/bins.d.ts +26 -0
- package/dist/codec/bins.d.ts.map +1 -0
- package/dist/codec/bins.js +67 -0
- package/dist/codec/bins.js.map +1 -0
- package/dist/codec/clmm.d.ts +87 -0
- package/dist/codec/clmm.d.ts.map +1 -0
- package/dist/codec/clmm.js +119 -0
- package/dist/codec/clmm.js.map +1 -0
- package/dist/codec/cpmm.d.ts +112 -0
- package/dist/codec/cpmm.d.ts.map +1 -0
- package/dist/codec/cpmm.js +146 -0
- package/dist/codec/cpmm.js.map +1 -0
- package/dist/codec/jetton.d.ts +30 -0
- package/dist/codec/jetton.d.ts.map +1 -0
- package/dist/codec/jetton.js +37 -0
- package/dist/codec/jetton.js.map +1 -0
- package/dist/codec/mempad.d.ts +109 -0
- package/dist/codec/mempad.d.ts.map +1 -0
- package/dist/codec/mempad.js +162 -0
- package/dist/codec/mempad.js.map +1 -0
- package/dist/core/amount.d.ts +33 -0
- package/dist/core/amount.d.ts.map +1 -0
- package/dist/core/amount.js +81 -0
- package/dist/core/amount.js.map +1 -0
- package/dist/core/asset.d.ts +82 -0
- package/dist/core/asset.d.ts.map +1 -0
- package/dist/core/asset.js +143 -0
- package/dist/core/asset.js.map +1 -0
- package/dist/core/errors.d.ts +70 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +114 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/fee.d.ts +36 -0
- package/dist/core/fee.d.ts.map +1 -0
- package/dist/core/fee.js +40 -0
- package/dist/core/fee.js.map +1 -0
- package/dist/core/gas.d.ts +112 -0
- package/dist/core/gas.d.ts.map +1 -0
- package/dist/core/gas.js +265 -0
- package/dist/core/gas.js.map +1 -0
- package/dist/core/percent.d.ts +27 -0
- package/dist/core/percent.d.ts.map +1 -0
- package/dist/core/percent.js +71 -0
- package/dist/core/percent.js.map +1 -0
- package/dist/core/tx.d.ts +36 -0
- package/dist/core/tx.d.ts.map +1 -0
- package/dist/core/tx.js +17 -0
- package/dist/core/tx.js.map +1 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/jetton/index.d.ts +53 -0
- package/dist/jetton/index.d.ts.map +1 -0
- package/dist/jetton/index.js +90 -0
- package/dist/jetton/index.js.map +1 -0
- package/dist/math/clmm-swap.d.ts +80 -0
- package/dist/math/clmm-swap.d.ts.map +1 -0
- package/dist/math/clmm-swap.js +277 -0
- package/dist/math/clmm-swap.js.map +1 -0
- package/dist/math/clmm.d.ts +234 -0
- package/dist/math/clmm.d.ts.map +1 -0
- package/dist/math/clmm.js +270 -0
- package/dist/math/clmm.js.map +1 -0
- package/dist/math/cpmm.d.ts +170 -0
- package/dist/math/cpmm.d.ts.map +1 -0
- package/dist/math/cpmm.js +175 -0
- package/dist/math/cpmm.js.map +1 -0
- package/dist/math/integer.d.ts +10 -0
- package/dist/math/integer.d.ts.map +1 -0
- package/dist/math/integer.js +44 -0
- package/dist/math/integer.js.map +1 -0
- package/dist/math/q128.d.ts +45 -0
- package/dist/math/q128.d.ts.map +1 -0
- package/dist/math/q128.js +108 -0
- package/dist/math/q128.js.map +1 -0
- package/dist/moon.d.ts +245 -0
- package/dist/moon.d.ts.map +1 -0
- package/dist/moon.js +332 -0
- package/dist/moon.js.map +1 -0
- package/dist/ops/jetton-input.d.ts +3 -0
- package/dist/ops/jetton-input.d.ts.map +1 -0
- package/dist/ops/jetton-input.js +8 -0
- package/dist/ops/jetton-input.js.map +1 -0
- package/dist/ops/liquidity.d.ts +157 -0
- package/dist/ops/liquidity.d.ts.map +1 -0
- package/dist/ops/liquidity.js +413 -0
- package/dist/ops/liquidity.js.map +1 -0
- package/dist/ops/mempad.d.ts +143 -0
- package/dist/ops/mempad.d.ts.map +1 -0
- package/dist/ops/mempad.js +248 -0
- package/dist/ops/mempad.js.map +1 -0
- package/dist/ops/pool.d.ts +75 -0
- package/dist/ops/pool.d.ts.map +1 -0
- package/dist/ops/pool.js +129 -0
- package/dist/ops/pool.js.map +1 -0
- package/dist/ops/position.d.ts +47 -0
- package/dist/ops/position.d.ts.map +1 -0
- package/dist/ops/position.js +73 -0
- package/dist/ops/position.js.map +1 -0
- package/dist/ops/swap.d.ts +104 -0
- package/dist/ops/swap.d.ts.map +1 -0
- package/dist/ops/swap.js +248 -0
- package/dist/ops/swap.js.map +1 -0
- package/dist/pool/amounts.d.ts +36 -0
- package/dist/pool/amounts.d.ts.map +1 -0
- package/dist/pool/amounts.js +68 -0
- package/dist/pool/amounts.js.map +1 -0
- package/dist/pool/assets.d.ts +45 -0
- package/dist/pool/assets.d.ts.map +1 -0
- package/dist/pool/assets.js +57 -0
- package/dist/pool/assets.js.map +1 -0
- package/dist/pool/clmm.d.ts +309 -0
- package/dist/pool/clmm.d.ts.map +1 -0
- package/dist/pool/clmm.js +561 -0
- package/dist/pool/clmm.js.map +1 -0
- package/dist/pool/cpmm.d.ts +228 -0
- package/dist/pool/cpmm.d.ts.map +1 -0
- package/dist/pool/cpmm.js +332 -0
- package/dist/pool/cpmm.js.map +1 -0
- package/dist/protocol/generated.d.ts +2752 -0
- package/dist/protocol/generated.d.ts.map +1 -0
- package/dist/protocol/generated.js +3564 -0
- package/dist/protocol/generated.js.map +1 -0
- package/dist/protocol/index.d.ts +19 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +49 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/state/address.d.ts +121 -0
- package/dist/state/address.d.ts.map +1 -0
- package/dist/state/address.js +143 -0
- package/dist/state/address.js.map +1 -0
- package/dist/state/source.d.ts +26 -0
- package/dist/state/source.d.ts.map +1 -0
- package/dist/state/source.js +32 -0
- package/dist/state/source.js.map +1 -0
- package/dist/state/storage.d.ts +218 -0
- package/dist/state/storage.d.ts.map +1 -0
- package/dist/state/storage.js +273 -0
- package/dist/state/storage.js.map +1 -0
- package/package.json +74 -4
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** A slippage tolerance or fee share, held as whole basis points (never a float). */
|
|
2
|
+
export class Percent {
|
|
3
|
+
/** Basis points. 1 bps = 0.01%. 10000 bps = 100%. */
|
|
4
|
+
bps;
|
|
5
|
+
constructor(bps) {
|
|
6
|
+
if (!Number.isInteger(bps)) {
|
|
7
|
+
throw new TypeError(`basis points must be a whole number, got ${bps}`);
|
|
8
|
+
}
|
|
9
|
+
if (bps < 0 || bps > 10_000) {
|
|
10
|
+
throw new TypeError(`basis points must be within 0..10000, got ${bps}`);
|
|
11
|
+
}
|
|
12
|
+
this.bps = bps;
|
|
13
|
+
}
|
|
14
|
+
/** `Percent.bps(50)` — half a percent. */
|
|
15
|
+
static bps(value) {
|
|
16
|
+
return new Percent(value);
|
|
17
|
+
}
|
|
18
|
+
/** `Percent.percent(0.5)` — the same half a percent, written the other way. */
|
|
19
|
+
static percent(value) {
|
|
20
|
+
const bps = value * 100;
|
|
21
|
+
if (!Number.isInteger(Math.round(bps * 1e6) / 1e6)) {
|
|
22
|
+
throw new TypeError(`${value}% is finer than one basis point`);
|
|
23
|
+
}
|
|
24
|
+
return new Percent(Math.round(bps));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parses a written percentage: `'0.5%'`, `'0.5'` or `'50bps'`.
|
|
28
|
+
*
|
|
29
|
+
* Refuses bare numbers, since `50` could mean bps or percent; use
|
|
30
|
+
* {@link Percent.bps} or {@link Percent.percent} instead.
|
|
31
|
+
*/
|
|
32
|
+
static of(value) {
|
|
33
|
+
if (value instanceof Percent)
|
|
34
|
+
return value;
|
|
35
|
+
if (typeof value !== 'string') {
|
|
36
|
+
throw new TypeError('Percent.of takes a written value like "0.5%" or "50bps" — ' +
|
|
37
|
+
'for a bare number use Percent.bps(50) or Percent.percent(0.5)');
|
|
38
|
+
}
|
|
39
|
+
const text = value.trim().toLowerCase();
|
|
40
|
+
const bps = /^(\d+)\s*bps$/.exec(text);
|
|
41
|
+
if (bps)
|
|
42
|
+
return new Percent(Number(bps[1]));
|
|
43
|
+
const percent = /^(\d+(?:\.\d+)?)\s*%?$/.exec(text);
|
|
44
|
+
if (percent)
|
|
45
|
+
return Percent.percent(Number(percent[1]));
|
|
46
|
+
throw new TypeError(`cannot read ${JSON.stringify(value)} as a percentage`);
|
|
47
|
+
}
|
|
48
|
+
static zero() {
|
|
49
|
+
return new Percent(0);
|
|
50
|
+
}
|
|
51
|
+
isZero() {
|
|
52
|
+
return this.bps === 0;
|
|
53
|
+
}
|
|
54
|
+
/** Lower bound: what you must still accept. Rounds down, in your favour. */
|
|
55
|
+
applyDown(value) {
|
|
56
|
+
return (value * BigInt(10_000 - this.bps)) / 10000n;
|
|
57
|
+
}
|
|
58
|
+
/** Upper bound: the most you are willing to give. Rounds up. */
|
|
59
|
+
applyUp(value) {
|
|
60
|
+
const numerator = value * BigInt(10_000 + this.bps);
|
|
61
|
+
return numerator / 10000n + (numerator % 10000n === 0n ? 0n : 1n);
|
|
62
|
+
}
|
|
63
|
+
/** The share itself, rounded down: a fee of `bps` taken from `value`. */
|
|
64
|
+
of(value) {
|
|
65
|
+
return (value * BigInt(this.bps)) / 10000n;
|
|
66
|
+
}
|
|
67
|
+
toString() {
|
|
68
|
+
return `${this.bps / 100}%`;
|
|
69
|
+
}
|
|
70
|
+
}
|
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,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,MAAO,CAAA;IAC7C,CAAC;IAED,QAAQ;QACN,OAAO,GAAG,IAAI,CAAC,GAAG,GAAG,GAAG,GAAG,CAAA;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Address, Cell } from '@ton/core';
|
|
2
|
+
/**
|
|
3
|
+
* One message to be signed and sent. The SDK never signs or sends by itself:
|
|
4
|
+
* hand this to a sender from `adapters/sender` or to your own wallet code.
|
|
5
|
+
*/
|
|
6
|
+
export type TxRequest = {
|
|
7
|
+
/** Destination: a pool, a range, a position, or your own jetton wallet. */
|
|
8
|
+
to: Address;
|
|
9
|
+
/** TON to attach, in nanotons. Already includes gas — do not add your own. */
|
|
10
|
+
value: bigint;
|
|
11
|
+
body: Cell;
|
|
12
|
+
/** Send mode hint for your own wallet code; the bundled senders do not read it. */
|
|
13
|
+
sendMode?: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A built operation: the messages plus what to show a user before they sign.
|
|
17
|
+
*
|
|
18
|
+
* `warnings` lists where the SDK adjusted the request to fit an on-chain rule,
|
|
19
|
+
* e.g. a range trimmed to its window or a deposit split at the per-position
|
|
20
|
+
* bin limit.
|
|
21
|
+
*/
|
|
22
|
+
export type BuiltOperation<TDetails = unknown> = {
|
|
23
|
+
txs: TxRequest[];
|
|
24
|
+
/** Correlates the on-chain result with this request. */
|
|
25
|
+
queryId: bigint;
|
|
26
|
+
details: TDetails;
|
|
27
|
+
warnings: string[];
|
|
28
|
+
};
|
|
29
|
+
/** Total TON leaving the wallet if every message in the batch is sent. */
|
|
30
|
+
export declare function totalValue(txs: readonly TxRequest[]): bigint;
|
|
31
|
+
/**
|
|
32
|
+
* A random 64-bit query id. The protocol carries it into the fulfil and reject
|
|
33
|
+
* messages, so an operation's outcome can be found later.
|
|
34
|
+
*/
|
|
35
|
+
export declare function randomQueryId(): bigint;
|
|
36
|
+
//# sourceMappingURL=tx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../src/core/tx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAE9C;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,2EAA2E;IAC3E,EAAE,EAAE,OAAO,CAAA;IACX,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,IAAI,CAAA;IACV,mFAAmF;IACnF,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,CAAC,QAAQ,GAAG,OAAO,IAAI;IAC/C,GAAG,EAAE,SAAS,EAAE,CAAA;IAChB,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,QAAQ,CAAA;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB,CAAA;AAED,0EAA0E;AAC1E,wBAAgB,UAAU,CAAC,GAAG,EAAE,SAAS,SAAS,EAAE,GAAG,MAAM,CAE5D;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAMtC"}
|
package/dist/core/tx.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Total TON leaving the wallet if every message in the batch is sent. */
|
|
2
|
+
export function totalValue(txs) {
|
|
3
|
+
return txs.reduce((sum, tx) => sum + tx.value, 0n);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* A random 64-bit query id. The protocol carries it into the fulfil and reject
|
|
7
|
+
* messages, so an operation's outcome can be found later.
|
|
8
|
+
*/
|
|
9
|
+
export function randomQueryId() {
|
|
10
|
+
const bytes = new Uint8Array(8);
|
|
11
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
12
|
+
let value = 0n;
|
|
13
|
+
for (const byte of bytes)
|
|
14
|
+
value = (value << 8n) | BigInt(byte);
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=tx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tx.js","sourceRoot":"","sources":["../../src/core/tx.ts"],"names":[],"mappings":"AA+BA,0EAA0E;AAC1E,MAAM,UAAU,UAAU,CAAC,GAAyB;IAClD,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AACpD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;IAC/B,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;IACxC,IAAI,KAAK,GAAG,EAAE,CAAA;IACd,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,KAAK,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IAC9D,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@moon-cx/sdk` — swaps, liquidity and positions on the moon.cx DEX.
|
|
3
|
+
*
|
|
4
|
+
* Opcodes, gas thresholds and limits live in `protocol/generated.ts` and are
|
|
5
|
+
* verified by tests. Operations return {@link TxRequest}s to sign and send;
|
|
6
|
+
* quotes use on-chain state and the same arithmetic the pools run. The only backend input that decides where money
|
|
7
|
+
* goes is the factory address for create* calls when `factories` is not pinned.
|
|
8
|
+
*/
|
|
9
|
+
export { Moon } from './moon.ts';
|
|
10
|
+
export type { MoonOptions } from './moon.ts';
|
|
11
|
+
export { CpmmPool, CpmmPosition } from './pool/cpmm.ts';
|
|
12
|
+
export type { PoolAssets } from './pool/cpmm.ts';
|
|
13
|
+
export { canonicalAsset, toAmount } from './pool/amounts.ts';
|
|
14
|
+
export type { AmountLike } from './pool/amounts.ts';
|
|
15
|
+
export type { DecimalsSource, PoolDecimalsSource } from './pool/assets.ts';
|
|
16
|
+
export { ClmmPool, ClmmPosition, ClmmPositionIndex, ClmmRange } from './pool/clmm.ts';
|
|
17
|
+
export type { ClmmDepositBounds, ClmmWithdrawal } from './pool/clmm.ts';
|
|
18
|
+
export { MoonApi, MoonApiError, PoolIndexWarmingError, PoolList, WalletPositions, assetsOf, } from './api/index.ts';
|
|
19
|
+
export type { ApiConfig, ApiMempadConfig, MoonApiOptions, PoolInfo, PoolProtocol, PositionRecord, TokenInfo, } from './api/index.ts';
|
|
20
|
+
export { tonClientSource } from './adapters/tonclient.ts';
|
|
21
|
+
export { NoWalletError, prepared, tonConnectSender, walletSender } from './adapters/sender.ts';
|
|
22
|
+
export type { InternalMessageFactory, Operation, Sender, WalletLike } from './adapters/sender.ts';
|
|
23
|
+
export { JettonLookupError, Jettons } from './jetton/index.ts';
|
|
24
|
+
export type { OpenableClient, OpenedJettonMinter } from './jetton/index.ts';
|
|
25
|
+
export type { TonClientLike } from './adapters/tonclient.ts';
|
|
26
|
+
export { Asset, compareAddresses, orderAssets } from './core/asset.ts';
|
|
27
|
+
export { FEE_BPS, FeeTier, isFeeBps } from './core/fee.ts';
|
|
28
|
+
export type { FeeBps } from './core/fee.ts';
|
|
29
|
+
export { Amount } from './core/amount.ts';
|
|
30
|
+
export { Percent } from './core/percent.ts';
|
|
31
|
+
export { randomQueryId, totalValue } from './core/tx.ts';
|
|
32
|
+
export type { BuiltOperation, TxRequest } from './core/tx.ts';
|
|
33
|
+
export { AmountTooSmallError, BuildError, ContractRejectedError, EXIT_CODES, InsufficientGasError, LimitExceededError, MoonError, PoolNotFoundError, PoolNotReadyError, SlippageError, StateError, describeExitCode, } from './core/errors.ts';
|
|
34
|
+
export { CPMM_MIN_TON_DEPOSIT, DEFAULT_GAS_PRICES, LEGACY_GAS_PRICES, MAINNET_GAS_PRICES, GAS_HEADROOM, assertEnoughGas, gasFee, mempadBuyGas, } from './core/gas.ts';
|
|
35
|
+
export type { GasPrices, GasRequirement, MempadBuyGas } from './core/gas.ts';
|
|
36
|
+
export { PROTOCOL, constantOf, errorCode, fieldsOf, opcodeOf, } from './protocol/index.ts';
|
|
37
|
+
export type { ProtocolName } from './protocol/index.ts';
|
|
38
|
+
export { clmmLpAccountAddress, clmmLpPositionAddress, clmmPoolAddress, clmmRangeAddress, cpmmLpAccountAddress, cpmmLpPositionAddress, cpmmPoolAddress, MEMPAD_SHARD_DEPTH, mempadCurveAddress, mempadJettonWalletAddress, } from './state/address.ts';
|
|
39
|
+
export { parseMempadCurve, parseMempadFactory, parseClmmPool, parseClmmPosition, parseClmmRange, parseClmmFactory, parseCpmmFactory, parseCpmmPool, parseCpmmPosition, } from './state/storage.ts';
|
|
40
|
+
export type { Bin, ClmmPoolState, ClmmPositionState, ClmmRangeState, ClmmFactoryState, CpmmFactoryState, CpmmPoolState, CpmmPositionState, MempadCurveState, MempadFactoryState, } from './state/storage.ts';
|
|
41
|
+
export { readContract, requireState, staticStateSource } from './state/source.ts';
|
|
42
|
+
export type { AccountState, StateSource } from './state/source.ts';
|
|
43
|
+
export { BINS_PER_RANGE, BIN_STEPS, BinStep, isBinStep, MAX_BINS_PER_POSITION, MAX_BINS_PER_SWAP, RANGE_OFFSET, binAtHumanPrice, binAtRawPrice, binBounds, binCoverage, binFees, binSides, binValue, contributeLiquidity, firstBinOfRange, lastBinOfRange, nearestBinToHumanPrice, nearestBinToRawPrice, priceAtBin, rangeOfBin, sqrtPriceAtBin, sqrtPriceToPrice, } from './math/clmm.ts';
|
|
44
|
+
export { guaranteedOutAtLimit, simulateClmmSwap, sqrtPriceLimitFor } from './math/clmm-swap.ts';
|
|
45
|
+
export type { ClmmSwapSimulation } from './math/clmm-swap.ts';
|
|
46
|
+
export { depositLp, firstDepositLp, matchingDeposit, pendingFees, priceImpactBps, swapOutput, swapRejectionReason, withdrawAmounts, } from './math/cpmm.ts';
|
|
47
|
+
export { buildSwap, quoteClmmSwap, quoteCpmmSwap } from './ops/swap.ts';
|
|
48
|
+
export type { SwapQuote } from './ops/swap.ts';
|
|
49
|
+
export { buildClmmDeposit, buildClmmWithdraw, buildCpmmDeposit, buildCpmmWithdraw, matchCpmmDeposit, planCpmmDeposit, shapeBins, } from './ops/liquidity.ts';
|
|
50
|
+
export type { ClmmDepositPlan, CpmmDepositPlan, LiquidityShape } from './ops/liquidity.ts';
|
|
51
|
+
export { CLMM_CREATE_POOL_ATTACH, CLMM_CREATE_POOL_GAS, CPMM_CREATE_POOL_ATTACH, CPMM_CREATE_POOL_GAS, buildClmmCreatePool, buildCpmmCreatePool, } from './ops/pool.ts';
|
|
52
|
+
export type { ClmmPoolCreation, PoolCreation } from './ops/pool.ts';
|
|
53
|
+
export { MEMPAD_FEE_BPS, MEMPAD_FEE_TIERS, MEMPAD_SELL_ATTACH, MEMPAD_SELL_MIN_ATTACH, buildCreateCurve, buildCurveBuy, buildCurveSell, buyValueForSpend, createLaunchValue, } from './ops/mempad.ts';
|
|
54
|
+
export type { CurveBuy, CurveCreation, CurveSell, MempadFeeBps } from './ops/mempad.ts';
|
|
55
|
+
export { LOCK_CONFIRMATION, buildCollectFees, buildLockForever, cpmmPendingFees, isLocked, } from './ops/position.ts';
|
|
56
|
+
export * as cpmmCodec from './codec/cpmm.ts';
|
|
57
|
+
export * as clmmCodec from './codec/clmm.ts';
|
|
58
|
+
export * as mempadCodec from './codec/mempad.ts';
|
|
59
|
+
export type { LaunchLinks, LaunchMetadata } from './codec/mempad.ts';
|
|
60
|
+
export { buildJettonTransfer, JETTON_TRANSFER_OP } from './codec/jetton.ts';
|
|
61
|
+
export { depositBinsToDict, parseDepositBins, sumBins } from './codec/bins.ts';
|
|
62
|
+
export type { DepositBin } from './codec/bins.ts';
|
|
63
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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,MAAM,oBAAoB,CAAA;AAC3B,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAC1F,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,eAAe,CAAA;AACtB,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEnE,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,iBAAiB,CAAA;AACxB,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AACvF,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,QAAQ,GACT,MAAM,mBAAmB,CAAA;AAE1B,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAA;AAChD,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAC9E,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@moon-cx/sdk` — swaps, liquidity and positions on the moon.cx DEX.
|
|
3
|
+
*
|
|
4
|
+
* Opcodes, gas thresholds and limits live in `protocol/generated.ts` and are
|
|
5
|
+
* verified by tests. Operations return {@link TxRequest}s to sign and send;
|
|
6
|
+
* quotes use on-chain state and the same arithmetic the pools run. The only backend input that decides where money
|
|
7
|
+
* goes is the factory address for create* calls when `factories` is not pinned.
|
|
8
|
+
*/
|
|
9
|
+
export { Moon } from "./moon.js";
|
|
10
|
+
export { CpmmPool, CpmmPosition } from "./pool/cpmm.js";
|
|
11
|
+
export { canonicalAsset, toAmount } from "./pool/amounts.js";
|
|
12
|
+
export { ClmmPool, ClmmPosition, ClmmPositionIndex, ClmmRange } from "./pool/clmm.js";
|
|
13
|
+
export { MoonApi, MoonApiError, PoolIndexWarmingError, PoolList, WalletPositions, assetsOf, } from "./api/index.js";
|
|
14
|
+
export { tonClientSource } from "./adapters/tonclient.js";
|
|
15
|
+
export { NoWalletError, prepared, tonConnectSender, walletSender } from "./adapters/sender.js";
|
|
16
|
+
export { JettonLookupError, Jettons } from "./jetton/index.js";
|
|
17
|
+
export { Asset, compareAddresses, orderAssets } from "./core/asset.js";
|
|
18
|
+
export { FEE_BPS, FeeTier, isFeeBps } from "./core/fee.js";
|
|
19
|
+
export { Amount } from "./core/amount.js";
|
|
20
|
+
export { Percent } from "./core/percent.js";
|
|
21
|
+
export { randomQueryId, totalValue } from "./core/tx.js";
|
|
22
|
+
export { AmountTooSmallError, BuildError, ContractRejectedError, EXIT_CODES, InsufficientGasError, LimitExceededError, MoonError, PoolNotFoundError, PoolNotReadyError, SlippageError, StateError, describeExitCode, } from "./core/errors.js";
|
|
23
|
+
export { CPMM_MIN_TON_DEPOSIT, DEFAULT_GAS_PRICES, LEGACY_GAS_PRICES, MAINNET_GAS_PRICES, GAS_HEADROOM, assertEnoughGas, gasFee, mempadBuyGas, } from "./core/gas.js";
|
|
24
|
+
export { PROTOCOL, constantOf, errorCode, fieldsOf, opcodeOf, } from "./protocol/index.js";
|
|
25
|
+
export { clmmLpAccountAddress, clmmLpPositionAddress, clmmPoolAddress, clmmRangeAddress, cpmmLpAccountAddress, cpmmLpPositionAddress, cpmmPoolAddress, MEMPAD_SHARD_DEPTH, mempadCurveAddress, mempadJettonWalletAddress, } from "./state/address.js";
|
|
26
|
+
export { parseMempadCurve, parseMempadFactory, parseClmmPool, parseClmmPosition, parseClmmRange, parseClmmFactory, parseCpmmFactory, parseCpmmPool, parseCpmmPosition, } from "./state/storage.js";
|
|
27
|
+
export { readContract, requireState, staticStateSource } from "./state/source.js";
|
|
28
|
+
export { BINS_PER_RANGE, BIN_STEPS, BinStep, isBinStep, MAX_BINS_PER_POSITION, MAX_BINS_PER_SWAP, RANGE_OFFSET, binAtHumanPrice, binAtRawPrice, binBounds, binCoverage, binFees, binSides, binValue, contributeLiquidity, firstBinOfRange, lastBinOfRange, nearestBinToHumanPrice, nearestBinToRawPrice, priceAtBin, rangeOfBin, sqrtPriceAtBin, sqrtPriceToPrice, } from "./math/clmm.js";
|
|
29
|
+
export { guaranteedOutAtLimit, simulateClmmSwap, sqrtPriceLimitFor } from "./math/clmm-swap.js";
|
|
30
|
+
export { depositLp, firstDepositLp, matchingDeposit, pendingFees, priceImpactBps, swapOutput, swapRejectionReason, withdrawAmounts, } from "./math/cpmm.js";
|
|
31
|
+
export { buildSwap, quoteClmmSwap, quoteCpmmSwap } from "./ops/swap.js";
|
|
32
|
+
export { buildClmmDeposit, buildClmmWithdraw, buildCpmmDeposit, buildCpmmWithdraw, matchCpmmDeposit, planCpmmDeposit, shapeBins, } from "./ops/liquidity.js";
|
|
33
|
+
export { CLMM_CREATE_POOL_ATTACH, CLMM_CREATE_POOL_GAS, CPMM_CREATE_POOL_ATTACH, CPMM_CREATE_POOL_GAS, buildClmmCreatePool, buildCpmmCreatePool, } from "./ops/pool.js";
|
|
34
|
+
export { MEMPAD_FEE_BPS, MEMPAD_FEE_TIERS, MEMPAD_SELL_ATTACH, MEMPAD_SELL_MIN_ATTACH, buildCreateCurve, buildCurveBuy, buildCurveSell, buyValueForSpend, createLaunchValue, } from "./ops/mempad.js";
|
|
35
|
+
export { LOCK_CONFIRMATION, buildCollectFees, buildLockForever, cpmmPendingFees, isLocked, } from "./ops/position.js";
|
|
36
|
+
export * as cpmmCodec from "./codec/cpmm.js";
|
|
37
|
+
export * as clmmCodec from "./codec/clmm.js";
|
|
38
|
+
export * as mempadCodec from "./codec/mempad.js";
|
|
39
|
+
export { buildJettonTransfer, JETTON_TRANSFER_OP } from "./codec/jetton.js";
|
|
40
|
+
export { depositBinsToDict, parseDepositBins, sumBins } from "./codec/bins.js";
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAEvD,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAG5D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAErF,OAAO,EACL,OAAO,EACP,YAAY,EACZ,qBAAqB,EACrB,QAAQ,EACR,eAAe,EACf,QAAQ,GACT,MAAM,gBAAgB,CAAA;AAUvB,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAE9F,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAI9D,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACtE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE1D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,E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B,CAAA;AACvB,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAE/F,OAAO,EACL,SAAS,EACT,cAAc,EACd,eAAe,EACf,WAAW,EACX,cAAc,EACd,UAAU,EACV,mBAAmB,EACnB,eAAe,GAChB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAEvE,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,SAAS,GACV,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,eAAe,CAAA;AAGtB,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,QAAQ,GACT,MAAM,mBAAmB,CAAA;AAE1B,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAA;AAEhD,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Address } from '@ton/core';
|
|
2
|
+
import { JettonMinter } from '@ton-community/assets-sdk';
|
|
3
|
+
import { type ContentResolver } from '@ton-community/assets-sdk/dist/content.js';
|
|
4
|
+
import { Asset } from '../core/asset.ts';
|
|
5
|
+
import { MoonError } from '../core/errors.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Jetton wallet addresses and metadata from the chain, via
|
|
8
|
+
* `@ton-community/assets-sdk` (on-chain TEP-64 or HTTP/IPFS metadata).
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* A client that can open a jetton minter — `TonClient` from `@ton/ton` qualifies.
|
|
12
|
+
*
|
|
13
|
+
* Not generic on purpose: TonClient's `open` carries a type constraint that an
|
|
14
|
+
* unconstrained generic would not satisfy.
|
|
15
|
+
*/
|
|
16
|
+
export type OpenableClient = {
|
|
17
|
+
open(minter: JettonMinter): OpenedJettonMinter;
|
|
18
|
+
};
|
|
19
|
+
export type OpenedJettonMinter = {
|
|
20
|
+
getWalletAddress(owner: Address): Promise<Address>;
|
|
21
|
+
getContent(): Promise<{
|
|
22
|
+
symbol?: string;
|
|
23
|
+
decimals?: number;
|
|
24
|
+
name?: string;
|
|
25
|
+
image?: string | Uint8Array;
|
|
26
|
+
}>;
|
|
27
|
+
};
|
|
28
|
+
export declare class JettonLookupError extends MoonError {
|
|
29
|
+
readonly master: Address;
|
|
30
|
+
constructor(master: Address, what: string, cause: unknown);
|
|
31
|
+
}
|
|
32
|
+
/** Resolves jettons, caching results for the lifetime of the instance. */
|
|
33
|
+
export declare class Jettons {
|
|
34
|
+
#private;
|
|
35
|
+
constructor(client: OpenableClient, options?: {
|
|
36
|
+
contentResolver?: ContentResolver;
|
|
37
|
+
});
|
|
38
|
+
/** The jetton as an {@link Asset}, with decimals, symbol, name and image read from its master. */
|
|
39
|
+
asset(master: Address): Promise<Asset>;
|
|
40
|
+
/** Native TON, or the jetton at this master. */
|
|
41
|
+
assetOf(master: Address | null): Promise<Asset>;
|
|
42
|
+
/** The owner's wallet for this jetton, from the master's `get_wallet_address`. */
|
|
43
|
+
walletOf(master: Address, owner: Address): Promise<Address>;
|
|
44
|
+
/** Wallet addresses for whichever sides of a pool are jettons. */
|
|
45
|
+
walletsFor(masters: {
|
|
46
|
+
x: Address | null;
|
|
47
|
+
y: Address;
|
|
48
|
+
}, owner: Address): Promise<{
|
|
49
|
+
x?: Address;
|
|
50
|
+
y?: Address;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jetton/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAGxD,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,2CAA2C,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE7C;;;GAGG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,CAAC,MAAM,EAAE,YAAY,GAAG,kBAAkB,CAAA;CAC/C,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAElD,UAAU,IAAI,OAAO,CAAC;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;KAAE,CAAC,CAAA;CAC1G,CAAA;AAED,qBAAa,iBAAkB,SAAQ,SAAS;IAC9C,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;gBAEZ,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;CAO1D;AAED,0EAA0E;AAC1E,qBAAa,OAAO;;gBAMN,MAAM,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,eAAe,CAAA;KAAE;IASnF,kGAAkG;IAC5F,KAAK,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC;IA2B5C,gDAAgD;IAC1C,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC;IAIrD,kFAAkF;IAC5E,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAoBjE,kEAAkE;IAC5D,UAAU,CACd,OAAO,EAAE;QAAE,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;QAAC,CAAC,EAAE,OAAO,CAAA;KAAE,EAC1C,KAAK,EAAE,OAAO,GACb,OAAO,CAAC;QAAE,CAAC,CAAC,EAAE,OAAO,CAAC;QAAC,CAAC,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CAOzC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { JettonMinter } from '@ton-community/assets-sdk';
|
|
2
|
+
// The content resolver is not re-exported from the package root and there is
|
|
3
|
+
// no `exports` map, hence the internal path.
|
|
4
|
+
import { DefaultContentResolver, } from '@ton-community/assets-sdk/dist/content.js';
|
|
5
|
+
import { Asset } from "../core/asset.js";
|
|
6
|
+
import { MoonError } from "../core/errors.js";
|
|
7
|
+
export class JettonLookupError extends MoonError {
|
|
8
|
+
master;
|
|
9
|
+
constructor(master, what, cause) {
|
|
10
|
+
super(`could not read ${what} for jetton ${master.toString()}: ` +
|
|
11
|
+
(cause instanceof Error ? cause.message : String(cause)));
|
|
12
|
+
this.master = master;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Resolves jettons, caching results for the lifetime of the instance. */
|
|
16
|
+
export class Jettons {
|
|
17
|
+
#client;
|
|
18
|
+
#contentResolver;
|
|
19
|
+
#assets = new Map();
|
|
20
|
+
#wallets = new Map();
|
|
21
|
+
constructor(client, options) {
|
|
22
|
+
this.#client = client;
|
|
23
|
+
this.#contentResolver = options?.contentResolver ?? new DefaultContentResolver();
|
|
24
|
+
}
|
|
25
|
+
#minter(master) {
|
|
26
|
+
return this.#client.open(JettonMinter.createFromAddress(master, this.#contentResolver));
|
|
27
|
+
}
|
|
28
|
+
/** The jetton as an {@link Asset}, with decimals, symbol, name and image read from its master. */
|
|
29
|
+
async asset(master) {
|
|
30
|
+
const key = master.toRawString();
|
|
31
|
+
const cached = this.#assets.get(key);
|
|
32
|
+
if (cached)
|
|
33
|
+
return cached;
|
|
34
|
+
const pending = (async () => {
|
|
35
|
+
try {
|
|
36
|
+
const content = await this.#minter(master).getContent();
|
|
37
|
+
return Asset.jetton(master, {
|
|
38
|
+
decimals: content.decimals ?? 9,
|
|
39
|
+
...(content.symbol !== undefined ? { symbol: content.symbol } : {}),
|
|
40
|
+
...(typeof content.name === 'string' ? { name: content.name } : {}),
|
|
41
|
+
...(typeof content.image === 'string' ? { image: content.image } : {}),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (cause) {
|
|
45
|
+
throw new JettonLookupError(master, 'metadata', cause);
|
|
46
|
+
}
|
|
47
|
+
})();
|
|
48
|
+
this.#assets.set(key, pending);
|
|
49
|
+
// Coalesce concurrent reads, but let the next call retry a transient failure.
|
|
50
|
+
void pending.catch(() => {
|
|
51
|
+
if (this.#assets.get(key) === pending)
|
|
52
|
+
this.#assets.delete(key);
|
|
53
|
+
});
|
|
54
|
+
return pending;
|
|
55
|
+
}
|
|
56
|
+
/** Native TON, or the jetton at this master. */
|
|
57
|
+
async assetOf(master) {
|
|
58
|
+
return master === null ? Asset.native() : this.asset(master);
|
|
59
|
+
}
|
|
60
|
+
/** The owner's wallet for this jetton, from the master's `get_wallet_address`. */
|
|
61
|
+
async walletOf(master, owner) {
|
|
62
|
+
const key = `${master.toRawString()}|${owner.toRawString()}`;
|
|
63
|
+
const cached = this.#wallets.get(key);
|
|
64
|
+
if (cached)
|
|
65
|
+
return cached;
|
|
66
|
+
const pending = (async () => {
|
|
67
|
+
try {
|
|
68
|
+
return await this.#minter(master).getWalletAddress(owner);
|
|
69
|
+
}
|
|
70
|
+
catch (cause) {
|
|
71
|
+
throw new JettonLookupError(master, 'wallet address', cause);
|
|
72
|
+
}
|
|
73
|
+
})();
|
|
74
|
+
this.#wallets.set(key, pending);
|
|
75
|
+
void pending.catch(() => {
|
|
76
|
+
if (this.#wallets.get(key) === pending)
|
|
77
|
+
this.#wallets.delete(key);
|
|
78
|
+
});
|
|
79
|
+
return pending;
|
|
80
|
+
}
|
|
81
|
+
/** Wallet addresses for whichever sides of a pool are jettons. */
|
|
82
|
+
async walletsFor(masters, owner) {
|
|
83
|
+
const [x, y] = await Promise.all([
|
|
84
|
+
masters.x === null ? undefined : this.walletOf(masters.x, owner),
|
|
85
|
+
this.walletOf(masters.y, owner),
|
|
86
|
+
]);
|
|
87
|
+
return { ...(x !== undefined ? { x } : {}), y };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/jetton/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,6EAA6E;AAC7E,6CAA6C;AAC7C,OAAO,EACL,sBAAsB,GAEvB,MAAM,2CAA2C,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAuB7C,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IACrC,MAAM,CAAS;IAExB,YAAY,MAAe,EAAE,IAAY,EAAE,KAAc;QACvD,KAAK,CACH,kBAAkB,IAAI,eAAe,MAAM,CAAC,QAAQ,EAAE,IAAI;YACxD,CAAC,KA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,EAAE,CAAC,EAAE,CAAA;IACjD,CAAC;CACF"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Bin } from '../state/storage.ts';
|
|
2
|
+
export type SwapStep = {
|
|
3
|
+
bin: number;
|
|
4
|
+
newSqrtPrice: bigint;
|
|
5
|
+
out: bigint;
|
|
6
|
+
remaining: bigint;
|
|
7
|
+
lpFee: bigint;
|
|
8
|
+
protocolFee: bigint;
|
|
9
|
+
};
|
|
10
|
+
export type ClmmSwapSimulation = {
|
|
11
|
+
amountOut: bigint;
|
|
12
|
+
/** Price after the swap, as a Q128 square root. */
|
|
13
|
+
newSqrtPrice: bigint;
|
|
14
|
+
/** Bins the swap touched, in the order it crossed them. */
|
|
15
|
+
binsCrossed: number[];
|
|
16
|
+
lpFees: bigint;
|
|
17
|
+
protocolFees: bigint;
|
|
18
|
+
/** Input that could not be filled — the range ran out of liquidity. */
|
|
19
|
+
unfilled: bigint;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Runs a swap against a range's bins.
|
|
23
|
+
*
|
|
24
|
+
* `xIn` decides direction: X in walks the price down through lower bins, Y in
|
|
25
|
+
* walks it up. The range stops after forty bins, so a swap large enough to
|
|
26
|
+
* cross more is refused here too, before it is signed.
|
|
27
|
+
*/
|
|
28
|
+
export declare function simulateClmmSwap(args: {
|
|
29
|
+
xIn: boolean;
|
|
30
|
+
amountIn: bigint;
|
|
31
|
+
bins: ReadonlyMap<bigint, Bin>;
|
|
32
|
+
currentBin: number;
|
|
33
|
+
currentSqrtPrice: bigint;
|
|
34
|
+
binStep: number;
|
|
35
|
+
lpFeeBps: number;
|
|
36
|
+
protocolFeeBps: number;
|
|
37
|
+
}): ClmmSwapSimulation;
|
|
38
|
+
/**
|
|
39
|
+
* Turns a slippage tolerance into the Q128 price bound the range expects.
|
|
40
|
+
*
|
|
41
|
+
* CLMM bounds a swap by price, not by output: X in must keep the price above
|
|
42
|
+
* the bound, Y in must keep it below. Zero means unbounded, which on a live
|
|
43
|
+
* pool means accepting any price at all.
|
|
44
|
+
*/
|
|
45
|
+
export declare function sqrtPriceLimitFor(args: {
|
|
46
|
+
xIn: boolean;
|
|
47
|
+
currentSqrtPrice: bigint;
|
|
48
|
+
slippageBps: number;
|
|
49
|
+
}): bigint;
|
|
50
|
+
/**
|
|
51
|
+
* Output guaranteed by the price limit, the only on-chain guard a CLMM swap has.
|
|
52
|
+
*
|
|
53
|
+
* A CLMM swap message carries no `minOut`: the range checks the price after
|
|
54
|
+
* every bin and refunds the whole input if the limit is crossed. The minimum
|
|
55
|
+
* received is therefore what follows from the limit, and this computes it.
|
|
56
|
+
*
|
|
57
|
+
* Price moves monotonically during a swap, so every chunk of input converts
|
|
58
|
+
* at a price no worse than the limit. The LP fee comes off the input and the
|
|
59
|
+
* protocol fee off the output:
|
|
60
|
+
*
|
|
61
|
+
* xIn: out ≥ (Δin − LP) · p_lim · (1 − f_pr)
|
|
62
|
+
* yIn: out ≥ (Δin − LP) / p_lim · (1 − f_pr), p = (sqrtP/2¹²⁸)²
|
|
63
|
+
*
|
|
64
|
+
* The bound is deliberately loose. The quote places the limit one slippage
|
|
65
|
+
* tolerance beyond the post-trade price, so actual output usually exceeds
|
|
66
|
+
* the guarantee by about that tolerance; equality needs the whole swap to
|
|
67
|
+
* fill at the limit price.
|
|
68
|
+
*
|
|
69
|
+
* Rounding always goes against the caller: both fees round up and both
|
|
70
|
+
* price conversions round down.
|
|
71
|
+
*/
|
|
72
|
+
export declare function guaranteedOutAtLimit(args: {
|
|
73
|
+
xIn: boolean;
|
|
74
|
+
amountIn: bigint;
|
|
75
|
+
/** Q128 price limit exactly as sent in the message. Zero means no limit. */
|
|
76
|
+
sqrtPriceLimit: bigint;
|
|
77
|
+
lpFeeBps: number;
|
|
78
|
+
protocolFeeBps: number;
|
|
79
|
+
}): bigint;
|
|
80
|
+
//# sourceMappingURL=clmm-swap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clmm-sw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