@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,162 @@
|
|
|
1
|
+
import { Address, beginCell } from '@ton/core';
|
|
2
|
+
import { assertLayout, constantOf, opcodeOf } from "../protocol/index.js";
|
|
3
|
+
/** Field order this codec writes, per message. Checked against the protocol by the drift test. */
|
|
4
|
+
export const MEMPAD_LAYOUTS = {
|
|
5
|
+
MsgCreateLaunch: ['queryId', 'salt', 'feeBps', 'initialBuy', 'content'],
|
|
6
|
+
MsgBuy: ['queryId', 'minOut'],
|
|
7
|
+
AskToBurn: ['queryId', 'jettonAmount', 'sendExcessesTo', 'customPayload'],
|
|
8
|
+
LaunchContent: ['name', 'symbol', 'image', 'extra'],
|
|
9
|
+
LaunchExtra: ['description', 'links'],
|
|
10
|
+
LaunchLinks: ['website', 'twitter', 'telegram'],
|
|
11
|
+
CurveInitData: ['factory', 'creator', 'salt'],
|
|
12
|
+
};
|
|
13
|
+
const op = (struct) => opcodeOf('mempad', struct);
|
|
14
|
+
/**
|
|
15
|
+
* The 32-bit word that turns a burn into a sale. Without it the curve treats the
|
|
16
|
+
* burn as plain: refused with `WRONG_STATE` (555) while trading, and after
|
|
17
|
+
* graduation the tokens are destroyed with nothing paid out.
|
|
18
|
+
*/
|
|
19
|
+
export const SELL_MARKER = Number(constantOf('mempad', 'SELL_MARKER'));
|
|
20
|
+
/** Bytes per cell in a snake chain: 1023 bits minus the ref, rounded down to whole bytes. */
|
|
21
|
+
const SNAKE_BYTES_PER_CELL = 127;
|
|
22
|
+
/**
|
|
23
|
+
* A string as the factory wants it: a strictly linear chain of raw UTF-8 bytes.
|
|
24
|
+
*
|
|
25
|
+
* - No TEP-64 `0x00` prefix: the factory adds it, and a second one would
|
|
26
|
+
* become part of the stored string.
|
|
27
|
+
* - Strictly linear: the factory asserts `refs == cells - 1`, so the chain
|
|
28
|
+
* cannot branch or be padded.
|
|
29
|
+
*
|
|
30
|
+
* Limits are in bytes, not characters.
|
|
31
|
+
*/
|
|
32
|
+
export function snakeChain(text) {
|
|
33
|
+
const bytes = Buffer.from(text, 'utf8');
|
|
34
|
+
const chunks = [];
|
|
35
|
+
for (let i = 0; i < bytes.length; i += SNAKE_BYTES_PER_CELL) {
|
|
36
|
+
chunks.push(bytes.subarray(i, i + SNAKE_BYTES_PER_CELL));
|
|
37
|
+
}
|
|
38
|
+
if (chunks.length === 0)
|
|
39
|
+
chunks.push(Buffer.alloc(0));
|
|
40
|
+
let cell = beginCell().storeBuffer(chunks[chunks.length - 1]).endCell();
|
|
41
|
+
for (let i = chunks.length - 2; i >= 0; i--) {
|
|
42
|
+
cell = beginCell().storeBuffer(chunks[i]).storeRef(cell).endCell();
|
|
43
|
+
}
|
|
44
|
+
return cell;
|
|
45
|
+
}
|
|
46
|
+
/** How many cells a string will occupy once chained. The factory caps this per field. */
|
|
47
|
+
export function snakeCells(text) {
|
|
48
|
+
const length = Buffer.from(text, 'utf8').length;
|
|
49
|
+
return Math.max(1, Math.ceil(length / SNAKE_BYTES_PER_CELL));
|
|
50
|
+
}
|
|
51
|
+
/** Optional ref, written as `Maybe ^Cell`. */
|
|
52
|
+
function storeMaybeRef(builder, cell) {
|
|
53
|
+
if (cell === null)
|
|
54
|
+
builder.storeBit(0);
|
|
55
|
+
else
|
|
56
|
+
builder.storeBit(1).storeRef(cell);
|
|
57
|
+
}
|
|
58
|
+
function linksCell(links) {
|
|
59
|
+
const website = links.website ? snakeChain(links.website) : null;
|
|
60
|
+
const twitter = links.twitter ? snakeChain(links.twitter) : null;
|
|
61
|
+
const telegram = links.telegram ? snakeChain(links.telegram) : null;
|
|
62
|
+
if (website === null && twitter === null && telegram === null)
|
|
63
|
+
return null;
|
|
64
|
+
const builder = beginCell();
|
|
65
|
+
storeMaybeRef(builder, website);
|
|
66
|
+
storeMaybeRef(builder, twitter);
|
|
67
|
+
storeMaybeRef(builder, telegram);
|
|
68
|
+
return builder.endCell();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The `LaunchContent` cell: three mandatory refs plus an optional `extra`.
|
|
72
|
+
*
|
|
73
|
+
* `description` is mandatory inside `extra`, so links without a description
|
|
74
|
+
* are dropped.
|
|
75
|
+
*/
|
|
76
|
+
export function encodeLaunchContent(meta) {
|
|
77
|
+
const links = meta.links ? linksCell(meta.links) : null;
|
|
78
|
+
let extra = null;
|
|
79
|
+
if (meta.description) {
|
|
80
|
+
const builder = beginCell().storeRef(snakeChain(meta.description));
|
|
81
|
+
storeMaybeRef(builder, links);
|
|
82
|
+
extra = builder.endCell();
|
|
83
|
+
}
|
|
84
|
+
const content = beginCell()
|
|
85
|
+
.storeRef(snakeChain(meta.name))
|
|
86
|
+
.storeRef(snakeChain(meta.symbol))
|
|
87
|
+
.storeRef(snakeChain(meta.image));
|
|
88
|
+
storeMaybeRef(content, extra);
|
|
89
|
+
return content.endCell();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* `MsgCreateLaunch` — deploys a token and its bonding curve.
|
|
93
|
+
*
|
|
94
|
+
* The factory reads the bit fields positionally, so their order and widths must
|
|
95
|
+
* match exactly. The `content` ref's position does not matter.
|
|
96
|
+
*/
|
|
97
|
+
export function encodeCreateLaunch(args) {
|
|
98
|
+
return beginCell()
|
|
99
|
+
.storeUint(op('MsgCreateLaunch'), 32)
|
|
100
|
+
.storeUint(args.queryId, 64)
|
|
101
|
+
.storeUint(args.salt, 64)
|
|
102
|
+
.storeUint(args.feeBps, 8)
|
|
103
|
+
.storeCoins(args.initialBuy)
|
|
104
|
+
.storeRef(args.content)
|
|
105
|
+
.endCell();
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* `MsgBuy` — buys from the curve. The body carries no amount: the curve takes
|
|
109
|
+
* its overhead off the attached TON and spends the rest.
|
|
110
|
+
*/
|
|
111
|
+
export function encodeBuy(args) {
|
|
112
|
+
return beginCell()
|
|
113
|
+
.storeUint(op('MsgBuy'), 32)
|
|
114
|
+
.storeUint(args.queryId, 64)
|
|
115
|
+
.storeCoins(args.minOut)
|
|
116
|
+
.endCell();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The custom payload that marks a burn as a sale: marker word, then `minOut`.
|
|
120
|
+
* No query id; the curve reads exactly these two fields.
|
|
121
|
+
*/
|
|
122
|
+
export function encodeSellPayload(args) {
|
|
123
|
+
return beginCell().storeUint(SELL_MARKER, 32).storeCoins(args.minOut).endCell();
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* `AskToBurn` — sent to the seller's own jetton wallet, which forwards
|
|
127
|
+
* `customPayload` to the curve in the burn notification.
|
|
128
|
+
*/
|
|
129
|
+
export function encodeAskToBurn(args) {
|
|
130
|
+
const builder = beginCell()
|
|
131
|
+
.storeUint(op('AskToBurn'), 32)
|
|
132
|
+
.storeUint(args.queryId, 64)
|
|
133
|
+
.storeCoins(args.jettonAmount)
|
|
134
|
+
.storeAddress(args.sendExcessesTo);
|
|
135
|
+
storeMaybeRef(builder, args.customPayload);
|
|
136
|
+
return builder.endCell();
|
|
137
|
+
}
|
|
138
|
+
/** Gas units the curve charges itself for a buy. */
|
|
139
|
+
export const MEMPAD_GAS_BUY = constantOf('mempad', 'GAS_BUY');
|
|
140
|
+
/** What a jetton transfer costs, and exactly what a sell must attach. */
|
|
141
|
+
export const MEMPAD_VALUE_JETTON_TRANSFER = constantOf('mempad', 'VALUE_JETTON_TRANSFER');
|
|
142
|
+
/** The smallest purchase the curve accepts, after its overhead is removed. */
|
|
143
|
+
export const MEMPAD_VALUE_MIN_BUY = constantOf('mempad', 'VALUE_MIN_BUY');
|
|
144
|
+
/** The factory's own share of a deploy, on top of the launch fee. */
|
|
145
|
+
export const MEMPAD_VALUE_CREATE_LAUNCH = constantOf('mempad', 'VALUE_CREATE_LAUNCH');
|
|
146
|
+
/** Metadata limits, in bytes and cells, exactly as the factory asserts them. */
|
|
147
|
+
export const MEMPAD_META_LIMITS = {
|
|
148
|
+
nameBytes: Number(constantOf('mempad', 'META_MAX_NAME_BYTES')),
|
|
149
|
+
symbolBytes: Number(constantOf('mempad', 'META_MAX_SYMBOL_BYTES')),
|
|
150
|
+
imageBytes: Number(constantOf('mempad', 'META_MAX_IMAGE_BYTES')),
|
|
151
|
+
imageCells: Number(constantOf('mempad', 'META_MAX_IMAGE_CELLS')),
|
|
152
|
+
descriptionBytes: Number(constantOf('mempad', 'META_MAX_DESC_BYTES')),
|
|
153
|
+
descriptionCells: Number(constantOf('mempad', 'META_MAX_DESC_CELLS')),
|
|
154
|
+
linkBytes: Number(constantOf('mempad', 'META_MAX_LINK_BYTES')),
|
|
155
|
+
};
|
|
156
|
+
/** Asserts this codec still matches the protocol. Called by the drift test. */
|
|
157
|
+
export function assertMempadLayouts() {
|
|
158
|
+
for (const [struct, fields] of Object.entries(MEMPAD_LAYOUTS)) {
|
|
159
|
+
assertLayout('mempad', struct, fields);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=mempad.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mempad.js","sourceRoot":"","sources":["../../src/codec/mempad.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAa,MAAM,WAAW,CAAA;AACzD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAEzE,kGAAkG;AAClG,MAAM,CAAC,MAAM,cAAc,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,CAAC,cAAc,CAAC,EAAE,CAAC;QAC9D,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Asset } from './asset.ts';
|
|
2
|
+
/**
|
|
3
|
+
* An amount of a specific asset, held exactly as an integer of the asset's
|
|
4
|
+
* smallest unit. Never a float: decimal input is parsed digit by digit, and
|
|
5
|
+
* carrying the asset stops amounts with different decimals from being mixed.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Amount {
|
|
8
|
+
/** The value in the asset's smallest unit. */
|
|
9
|
+
readonly raw: bigint;
|
|
10
|
+
readonly asset: Asset;
|
|
11
|
+
constructor(raw: bigint, asset: Asset);
|
|
12
|
+
/** Wraps a value that is already in the smallest unit. */
|
|
13
|
+
static raw(value: bigint | number, asset: Asset): Amount;
|
|
14
|
+
/**
|
|
15
|
+
* Parses a human-readable amount: `Amount.of('10.5', ton)`.
|
|
16
|
+
*
|
|
17
|
+
* Prefer strings: a number with more than 15 significant digits has already
|
|
18
|
+
* lost precision before it gets here.
|
|
19
|
+
*/
|
|
20
|
+
static of(value: string | number, asset: Asset): Amount;
|
|
21
|
+
static zero(asset: Asset): Amount;
|
|
22
|
+
isZero(): boolean;
|
|
23
|
+
private sameAsset;
|
|
24
|
+
plus(other: Amount): Amount;
|
|
25
|
+
minus(other: Amount): Amount;
|
|
26
|
+
/** Multiplies by a fraction, rounding down. Used for slippage and shares. */
|
|
27
|
+
mulDiv(numerator: bigint, denominator: bigint): Amount;
|
|
28
|
+
compare(other: Amount): -1 | 0 | 1;
|
|
29
|
+
/** Human-readable form, trailing zeros trimmed: `10.5`, `0.000000001`, `3`. */
|
|
30
|
+
toDecimal(): string;
|
|
31
|
+
toString(): string;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=amount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../../src/core/amount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC;;;;GAIG;AACH,qBAAa,MAAM;IACjB,8CAA8C;IAC9C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;gBAET,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;IAMrC,0DAA0D;IAC1D,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM;IAIxD;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM;IAevD,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;IAIjC,MAAM,IAAI,OAAO;IAIjB,OAAO,CAAC,SAAS;IAQjB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAK3B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAK5B,6EAA6E;IAC7E,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM;IAKtD,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAKlC,+EAA+E;IAC/E,SAAS,IAAI,MAAM;IAQnB,QAAQ,IAAI,MAAM;CAInB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Asset } from "./asset.js";
|
|
2
|
+
/**
|
|
3
|
+
* An amount of a specific asset, held exactly as an integer of the asset's
|
|
4
|
+
* smallest unit. Never a float: decimal input is parsed digit by digit, and
|
|
5
|
+
* carrying the asset stops amounts with different decimals from being mixed.
|
|
6
|
+
*/
|
|
7
|
+
export class Amount {
|
|
8
|
+
/** The value in the asset's smallest unit. */
|
|
9
|
+
raw;
|
|
10
|
+
asset;
|
|
11
|
+
constructor(raw, asset) {
|
|
12
|
+
if (raw < 0n)
|
|
13
|
+
throw new TypeError(`amount cannot be negative, got ${raw}`);
|
|
14
|
+
this.raw = raw;
|
|
15
|
+
this.asset = asset;
|
|
16
|
+
}
|
|
17
|
+
/** Wraps a value that is already in the smallest unit. */
|
|
18
|
+
static raw(value, asset) {
|
|
19
|
+
return new Amount(BigInt(value), asset);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Parses a human-readable amount: `Amount.of('10.5', ton)`.
|
|
23
|
+
*
|
|
24
|
+
* Prefer strings: a number with more than 15 significant digits has already
|
|
25
|
+
* lost precision before it gets here.
|
|
26
|
+
*/
|
|
27
|
+
static of(value, asset) {
|
|
28
|
+
const text = typeof value === 'number' ? String(value) : value.trim();
|
|
29
|
+
if (!/^\d+(\.\d+)?$/.test(text)) {
|
|
30
|
+
throw new TypeError(`expected a non-negative decimal amount, got ${JSON.stringify(value)}`);
|
|
31
|
+
}
|
|
32
|
+
const [whole = '0', fraction = ''] = text.split('.');
|
|
33
|
+
if (fraction.length > asset.decimals) {
|
|
34
|
+
throw new TypeError(`${asset.toString()} has ${asset.decimals} decimals, but ${text} needs ${fraction.length}`);
|
|
35
|
+
}
|
|
36
|
+
const padded = fraction.padEnd(asset.decimals, '0');
|
|
37
|
+
return new Amount(BigInt(whole) * 10n ** BigInt(asset.decimals) + BigInt(padded || '0'), asset);
|
|
38
|
+
}
|
|
39
|
+
static zero(asset) {
|
|
40
|
+
return new Amount(0n, asset);
|
|
41
|
+
}
|
|
42
|
+
isZero() {
|
|
43
|
+
return this.raw === 0n;
|
|
44
|
+
}
|
|
45
|
+
sameAsset(other) {
|
|
46
|
+
if (!this.asset.equals(other.asset)) {
|
|
47
|
+
throw new TypeError(`cannot combine ${this.asset.toString()} with ${other.asset.toString()}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
plus(other) {
|
|
51
|
+
this.sameAsset(other);
|
|
52
|
+
return new Amount(this.raw + other.raw, this.asset);
|
|
53
|
+
}
|
|
54
|
+
minus(other) {
|
|
55
|
+
this.sameAsset(other);
|
|
56
|
+
return new Amount(this.raw - other.raw, this.asset);
|
|
57
|
+
}
|
|
58
|
+
/** Multiplies by a fraction, rounding down. Used for slippage and shares. */
|
|
59
|
+
mulDiv(numerator, denominator) {
|
|
60
|
+
if (denominator === 0n)
|
|
61
|
+
throw new TypeError('division by zero');
|
|
62
|
+
return new Amount((this.raw * numerator) / denominator, this.asset);
|
|
63
|
+
}
|
|
64
|
+
compare(other) {
|
|
65
|
+
this.sameAsset(other);
|
|
66
|
+
return this.raw === other.raw ? 0 : this.raw < other.raw ? -1 : 1;
|
|
67
|
+
}
|
|
68
|
+
/** Human-readable form, trailing zeros trimmed: `10.5`, `0.000000001`, `3`. */
|
|
69
|
+
toDecimal() {
|
|
70
|
+
const unit = 10n ** BigInt(this.asset.decimals);
|
|
71
|
+
const whole = this.raw / unit;
|
|
72
|
+
const fraction = (this.raw % unit).toString().padStart(this.asset.decimals, '0');
|
|
73
|
+
const trimmed = fraction.replace(/0+$/, '');
|
|
74
|
+
return trimmed.length > 0 ? `${whole}.${trimmed}` : whole.toString();
|
|
75
|
+
}
|
|
76
|
+
toString() {
|
|
77
|
+
const symbol = this.asset.symbol;
|
|
78
|
+
return symbol !== undefined ? `${this.toDecimal()} ${symbol}` : this.toDecimal();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=amount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../src/core/amount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC;;;;GAIG;AACH,MAAM,OAAO,MAAM;IACjB,8CAA8C;IACrC,GAAG,CAAQ;IACX,KAAK,CAAO;IAErB,YAAY,GAAW,EAAE,KAAY;QACnC,IAAI,GAAG,GAAG,EAAE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AAC,KAAK,CAAC,CAAA;QACrB,OAAO,IAAI,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACnE,CAAC;IAED,+EAA+E;IAC/E,SAAS;QACP,MAAM,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,GAAG,IAAI,CAAA;QAC7B,MAAM,QAAQ,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;QAChF,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QAC3C,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAA;IACtE,CAAC;IAED,QAAQ;QACN,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA;QAChC,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,CAAA;IAClF,CAAC;CACF"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Address } from '@ton/core';
|
|
2
|
+
import type { OpenableClient } from '../jetton/index.ts';
|
|
3
|
+
/**
|
|
4
|
+
* An asset that can be traded or provided as liquidity: native TON, or a jetton
|
|
5
|
+
* identified by its master address.
|
|
6
|
+
*
|
|
7
|
+
* Use {@link Asset.native} and {@link Asset.jetton}; the SDK works out which
|
|
8
|
+
* pool side (`x` or `y`) an asset is on.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Asset {
|
|
11
|
+
/** `'native'` for TON, `'jetton'` for everything else. */
|
|
12
|
+
readonly kind: 'native' | 'jetton';
|
|
13
|
+
/** Jetton master address; `null` for native TON. */
|
|
14
|
+
readonly master: Address | null;
|
|
15
|
+
/** Decimal places used when formatting amounts. TON is always 9. */
|
|
16
|
+
readonly decimals: number;
|
|
17
|
+
/** Optional display symbol. Never used in message building. */
|
|
18
|
+
readonly symbol: string | undefined;
|
|
19
|
+
/** Optional display name from the jetton metadata. Never used in message building. */
|
|
20
|
+
readonly name: string | undefined;
|
|
21
|
+
/** Optional image URL from the jetton metadata (http(s) or ipfs://), as the master states it. */
|
|
22
|
+
readonly image: string | undefined;
|
|
23
|
+
constructor(kind: 'native' | 'jetton', master: Address | null, decimals: number, symbol?: string, details?: {
|
|
24
|
+
name?: string;
|
|
25
|
+
image?: string;
|
|
26
|
+
});
|
|
27
|
+
/** Native TON. Always 9 decimals. */
|
|
28
|
+
static native(): Asset;
|
|
29
|
+
/**
|
|
30
|
+
* A jetton by master address, with the details you already know. Nothing is
|
|
31
|
+
* read from the chain; use {@link Asset.fetch} (or `moon.asset`) for that.
|
|
32
|
+
*
|
|
33
|
+
* @param master jetton master (minter) address, or its string form
|
|
34
|
+
* @param options `decimals` defaults to 9 — pass the real value if it differs,
|
|
35
|
+
* otherwise human-readable amounts will be off by orders of magnitude
|
|
36
|
+
*/
|
|
37
|
+
static jetton(master: Address | string, options?: {
|
|
38
|
+
decimals?: number;
|
|
39
|
+
symbol?: string;
|
|
40
|
+
name?: string;
|
|
41
|
+
image?: string;
|
|
42
|
+
}): Asset;
|
|
43
|
+
/**
|
|
44
|
+
* The asset at this master, with decimals, symbol, name and image read from
|
|
45
|
+
* its TEP-64 metadata (on-chain or behind an HTTP/IPFS link). `null` or
|
|
46
|
+
* `'TON'` gives native TON without a request.
|
|
47
|
+
*
|
|
48
|
+
* Each call reads again; inside a `Moon`, prefer `moon.asset(master)`, which
|
|
49
|
+
* caches per master.
|
|
50
|
+
*
|
|
51
|
+
* @param client any client that can open a jetton minter, e.g. `TonClient` from `@ton/ton`
|
|
52
|
+
* @throws JettonLookupError when the master cannot be read or its metadata
|
|
53
|
+
* is unusable (for example decimals outside 0..30)
|
|
54
|
+
*/
|
|
55
|
+
static fetch(master: Address | string | null, client: OpenableClient): Promise<Asset>;
|
|
56
|
+
isNative(): boolean;
|
|
57
|
+
equals(other: Asset): boolean;
|
|
58
|
+
toString(): string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Lexicographic comparison of two serialised addresses — the TypeScript
|
|
62
|
+
* counterpart of TVM's `SDLEXCMP`, which orders a pool's two assets on chain.
|
|
63
|
+
*
|
|
64
|
+
* Returns -1, 0 or 1. A shorter slice that is a prefix of the longer one
|
|
65
|
+
* compares as smaller, matching TVM semantics.
|
|
66
|
+
*/
|
|
67
|
+
export declare function compareAddresses(a: Address | null, b: Address | null): -1 | 0 | 1;
|
|
68
|
+
/**
|
|
69
|
+
* Orders a pair the way the factory does, so the pool address you derive
|
|
70
|
+
* is the one that actually exists on chain.
|
|
71
|
+
*
|
|
72
|
+
* Native TON always becomes X. Two jettons are ordered by `SDLEXCMP`.
|
|
73
|
+
*
|
|
74
|
+
* @returns the ordered pair, plus `inverted: true` when the arguments were
|
|
75
|
+
* swapped — check it if you need to know which side your leg ended up on
|
|
76
|
+
*/
|
|
77
|
+
export declare function orderAssets(a: Asset, b: Asset): {
|
|
78
|
+
x: Asset;
|
|
79
|
+
y: Asset;
|
|
80
|
+
inverted: boolean;
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=asset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset.d.ts","sourceRoot":"","sources":["../../src/core/asset.ts"],"names":[],"mappings":"AAAA,OAAO,EA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AW3F,QAAQ,IAAI,OAAO;IAInB,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAM7B,QAAQ,IAAI,MAAM;CAGnB;AAWD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,IAAI,EAAE,CAAC,EAAE,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAWjF;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CACzB,CAAC,EAAE,KAAK,EACR,CAAC,EAAE,KAAK,GACP;IAAE,CAAC,EAAE,KAAK,CAAC;IAAC,CAAC,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAY3C"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Address, beginCell } from '@ton/core';
|
|
2
|
+
/**
|
|
3
|
+
* An asset that can be traded or provided as liquidity: native TON, or a jetton
|
|
4
|
+
* identified by its master address.
|
|
5
|
+
*
|
|
6
|
+
* Use {@link Asset.native} and {@link Asset.jetton}; the SDK works out which
|
|
7
|
+
* pool side (`x` or `y`) an asset is on.
|
|
8
|
+
*/
|
|
9
|
+
export class Asset {
|
|
10
|
+
/** `'native'` for TON, `'jetton'` for everything else. */
|
|
11
|
+
kind;
|
|
12
|
+
/** Jetton master address; `null` for native TON. */
|
|
13
|
+
master;
|
|
14
|
+
/** Decimal places used when formatting amounts. TON is always 9. */
|
|
15
|
+
decimals;
|
|
16
|
+
/** Optional display symbol. Never used in message building. */
|
|
17
|
+
symbol;
|
|
18
|
+
/** Optional display name from the jetton metadata. Never used in message building. */
|
|
19
|
+
name;
|
|
20
|
+
/** Optional image URL from the jetton metadata (http(s) or ipfs://), as the master states it. */
|
|
21
|
+
image;
|
|
22
|
+
constructor(kind, master, decimals, symbol, details) {
|
|
23
|
+
if (kind === 'jetton' && master === null) {
|
|
24
|
+
throw new TypeError('Asset.jetton requires a master address');
|
|
25
|
+
}
|
|
26
|
+
if (!Number.isInteger(decimals) || decimals < 0 || decimals > 30) {
|
|
27
|
+
throw new TypeError(`decimals must be an integer in 0..30, got ${decimals}`);
|
|
28
|
+
}
|
|
29
|
+
this.kind = kind;
|
|
30
|
+
this.master = master;
|
|
31
|
+
this.decimals = decimals;
|
|
32
|
+
this.symbol = symbol;
|
|
33
|
+
this.name = details?.name;
|
|
34
|
+
this.image = details?.image;
|
|
35
|
+
}
|
|
36
|
+
/** Native TON. Always 9 decimals. */
|
|
37
|
+
static native() {
|
|
38
|
+
return new Asset('native', null, 9, 'TON');
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A jetton by master address, with the details you already know. Nothing is
|
|
42
|
+
* read from the chain; use {@link Asset.fetch} (or `moon.asset`) for that.
|
|
43
|
+
*
|
|
44
|
+
* @param master jetton master (minter) address, or its string form
|
|
45
|
+
* @param options `decimals` defaults to 9 — pass the real value if it differs,
|
|
46
|
+
* otherwise human-readable amounts will be off by orders of magnitude
|
|
47
|
+
*/
|
|
48
|
+
static jetton(master, options) {
|
|
49
|
+
const address = typeof master === 'string' ? Address.parse(master) : master;
|
|
50
|
+
return new Asset('jetton', address, options?.decimals ?? 9, options?.symbol, {
|
|
51
|
+
...(options?.name !== undefined ? { name: options.name } : {}),
|
|
52
|
+
...(options?.image !== undefined ? { image: options.image } : {}),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The asset at this master, with decimals, symbol, name and image read from
|
|
57
|
+
* its TEP-64 metadata (on-chain or behind an HTTP/IPFS link). `null` or
|
|
58
|
+
* `'TON'` gives native TON without a request.
|
|
59
|
+
*
|
|
60
|
+
* Each call reads again; inside a `Moon`, prefer `moon.asset(master)`, which
|
|
61
|
+
* caches per master.
|
|
62
|
+
*
|
|
63
|
+
* @param client any client that can open a jetton minter, e.g. `TonClient` from `@ton/ton`
|
|
64
|
+
* @throws JettonLookupError when the master cannot be read or its metadata
|
|
65
|
+
* is unusable (for example decimals outside 0..30)
|
|
66
|
+
*/
|
|
67
|
+
static async fetch(master, client) {
|
|
68
|
+
if (master === null || (typeof master === 'string' && master.trim().toUpperCase() === 'TON')) {
|
|
69
|
+
return Asset.native();
|
|
70
|
+
}
|
|
71
|
+
const address = typeof master === 'string' ? Address.parse(master) : master;
|
|
72
|
+
// Dynamic import keeps assets-sdk out of the light subpaths (`./math`,
|
|
73
|
+
// `./protocol`) that also load this module.
|
|
74
|
+
const { Jettons } = await import("../jetton/index.js");
|
|
75
|
+
return new Jettons(client).asset(address);
|
|
76
|
+
}
|
|
77
|
+
isNative() {
|
|
78
|
+
return this.kind === 'native';
|
|
79
|
+
}
|
|
80
|
+
equals(other) {
|
|
81
|
+
if (this.kind !== other.kind)
|
|
82
|
+
return false;
|
|
83
|
+
if (this.master === null || other.master === null)
|
|
84
|
+
return this.master === other.master;
|
|
85
|
+
return this.master.equals(other.master);
|
|
86
|
+
}
|
|
87
|
+
toString() {
|
|
88
|
+
return this.isNative() ? 'TON' : `jetton:${this.master.toString()}`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Serialised MsgAddress bits, exactly as they are stored on chain.
|
|
93
|
+
* addr_none is 2 bits; addr_std is 267.
|
|
94
|
+
*/
|
|
95
|
+
function addressBits(address) {
|
|
96
|
+
const { bits } = beginCell().storeAddress(address).endCell();
|
|
97
|
+
return { at: (i) => bits.at(i), length: bits.length };
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Lexicographic comparison of two serialised addresses — the TypeScript
|
|
101
|
+
* counterpart of TVM's `SDLEXCMP`, which orders a pool's two assets on chain.
|
|
102
|
+
*
|
|
103
|
+
* Returns -1, 0 or 1. A shorter slice that is a prefix of the longer one
|
|
104
|
+
* compares as smaller, matching TVM semantics.
|
|
105
|
+
*/
|
|
106
|
+
export function compareAddresses(a, b) {
|
|
107
|
+
const left = addressBits(a);
|
|
108
|
+
const right = addressBits(b);
|
|
109
|
+
const common = Math.min(left.length, right.length);
|
|
110
|
+
for (let i = 0; i < common; i++) {
|
|
111
|
+
const l = left.at(i);
|
|
112
|
+
const r = right.at(i);
|
|
113
|
+
if (l !== r)
|
|
114
|
+
return l ? 1 : -1;
|
|
115
|
+
}
|
|
116
|
+
if (left.length === right.length)
|
|
117
|
+
return 0;
|
|
118
|
+
return left.length < right.length ? -1 : 1;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Orders a pair the way the factory does, so the pool address you derive
|
|
122
|
+
* is the one that actually exists on chain.
|
|
123
|
+
*
|
|
124
|
+
* Native TON always becomes X. Two jettons are ordered by `SDLEXCMP`.
|
|
125
|
+
*
|
|
126
|
+
* @returns the ordered pair, plus `inverted: true` when the arguments were
|
|
127
|
+
* swapped — check it if you need to know which side your leg ended up on
|
|
128
|
+
*/
|
|
129
|
+
export function orderAssets(a, b) {
|
|
130
|
+
if (a.isNative() && b.isNative()) {
|
|
131
|
+
throw new TypeError('a pool needs two different assets, both sides are native TON');
|
|
132
|
+
}
|
|
133
|
+
if (a.isNative())
|
|
134
|
+
return { x: a, y: b, inverted: false };
|
|
135
|
+
if (b.isNative())
|
|
136
|
+
return { x: b, y: a, inverted: true };
|
|
137
|
+
const order = compareAddresses(a.master, b.master);
|
|
138
|
+
if (order === 0) {
|
|
139
|
+
throw new TypeError(`a pool needs two different assets, both sides are ${a.toString()}`);
|
|
140
|
+
}
|
|
141
|
+
return order === -1 ? { x: a, y: b, inverted: false } : { x: b, y: a, inverted: true };
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=asset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset.js","sourceRoot":"","sources":["../../src/core/asset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAG9C;;;;;;GAMG;AACH,MAAM,OAAO,KAAK;IAChB,0DAA0D;IACjD,IAAI,CAAqB;IAClC,oDAAoD;IAC3C,MAAM,C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|
2
|
+
/**
|
|
3
|
+
* Base class for every SDK error. Subclasses carry the numbers involved as
|
|
4
|
+
* fields, so callers can react without parsing the message.
|
|
5
|
+
*/
|
|
6
|
+
export declare class MoonError extends Error {
|
|
7
|
+
constructor(message: string);
|
|
8
|
+
}
|
|
9
|
+
/** The built transaction would be rejected or would lose funds. Nothing was sent. */
|
|
10
|
+
export declare class BuildError extends MoonError {
|
|
11
|
+
}
|
|
12
|
+
/** The requested pool does not exist, or its address could not be derived. */
|
|
13
|
+
export declare class PoolNotFoundError extends MoonError {
|
|
14
|
+
readonly assets: [string, string];
|
|
15
|
+
constructor(assetA: string, assetB: string);
|
|
16
|
+
}
|
|
17
|
+
/** The pool exists but cannot trade yet — usually no liquidity, or wallets not resolved. */
|
|
18
|
+
export declare class PoolNotReadyError extends MoonError {
|
|
19
|
+
readonly address: Address;
|
|
20
|
+
readonly reason: string;
|
|
21
|
+
constructor(address: Address, reason: string);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The attached TON would not clear an on-chain gas gate. Thrown before
|
|
25
|
+
* building: on a jetton leg the receiving pool or range throws after the
|
|
26
|
+
* jettons are credited.
|
|
27
|
+
*/
|
|
28
|
+
export declare class InsufficientGasError extends BuildError {
|
|
29
|
+
readonly need: bigint;
|
|
30
|
+
readonly have: bigint;
|
|
31
|
+
readonly gate: string;
|
|
32
|
+
constructor(need: bigint, have: bigint, gate: string);
|
|
33
|
+
}
|
|
34
|
+
/** The amount is below a minimum enforced on chain. */
|
|
35
|
+
export declare class AmountTooSmallError extends BuildError {
|
|
36
|
+
readonly minimum: bigint;
|
|
37
|
+
readonly got: bigint;
|
|
38
|
+
constructor(what: string, minimum: bigint, got: bigint, gate: string);
|
|
39
|
+
}
|
|
40
|
+
/** An on-chain limit would be exceeded: bins per position, bins per swap, range window. */
|
|
41
|
+
export declare class LimitExceededError extends BuildError {
|
|
42
|
+
readonly limit: number;
|
|
43
|
+
readonly got: number;
|
|
44
|
+
constructor(what: string, limit: number, got: number, hint?: string);
|
|
45
|
+
}
|
|
46
|
+
/** The quote moved further than the tolerance allows. */
|
|
47
|
+
export declare class SlippageError extends MoonError {
|
|
48
|
+
readonly expected: bigint;
|
|
49
|
+
readonly got: bigint;
|
|
50
|
+
constructor(expected: bigint, got: bigint);
|
|
51
|
+
}
|
|
52
|
+
/** On-chain state could not be read or did not parse as the expected pool, range, position or wallet. */
|
|
53
|
+
export declare class StateError extends MoonError {
|
|
54
|
+
readonly address: Address;
|
|
55
|
+
constructor(address: Address, message: string);
|
|
56
|
+
}
|
|
57
|
+
/** A sent message was rejected on chain. */
|
|
58
|
+
export declare class ContractRejectedError extends MoonError {
|
|
59
|
+
readonly exitCode: number;
|
|
60
|
+
readonly queryId: bigint | undefined;
|
|
61
|
+
constructor(exitCode: number, description: string, queryId?: bigint);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Plain-language descriptions of the protocol's exit codes (identical in CPMM
|
|
65
|
+
* and CLMM; pinned by the protocol drift test).
|
|
66
|
+
*/
|
|
67
|
+
export declare const EXIT_CODES: Readonly<Record<number, string>>;
|
|
68
|
+
/** Turns an exit code into a sentence, falling back to the bare number. */
|
|
69
|
+
export declare function describeExitCode(exitCode: number): string;
|
|
70
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAExC;;;GAGG;AACH,qBAAa,SAAU,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAI5B;AAED,qFAAqF;AACrF,qBAAa,UAAW,SAAQ,SAAS;CAAG;AAE5C,8EAA8E;AAC9E,qBAAa,iBAAkB,SAAQ,SAAS;IAC9C,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;gBAErB,MAAM,EAAE,MAAM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