@sundaeswap/math 0.0.0-dev-20250813095002
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/README.md +15 -0
- package/dist/cjs/@types/index.js +17 -0
- package/dist/cjs/@types/index.js.map +1 -0
- package/dist/cjs/PoolMath/ConstantProductPool.js +316 -0
- package/dist/cjs/PoolMath/ConstantProductPool.js.map +1 -0
- package/dist/cjs/PoolMath/index.js +11 -0
- package/dist/cjs/PoolMath/index.js.map +1 -0
- package/dist/cjs/index.js +17 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/@types/index.js +2 -0
- package/dist/esm/@types/index.js.map +1 -0
- package/dist/esm/PoolMath/ConstantProductPool.js +294 -0
- package/dist/esm/PoolMath/ConstantProductPool.js.map +1 -0
- package/dist/esm/PoolMath/index.js +2 -0
- package/dist/esm/PoolMath/index.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/types/@types/index.d.ts +2 -0
- package/dist/types/@types/index.d.ts.map +1 -0
- package/dist/types/PoolMath/ConstantProductPool.d.ts +174 -0
- package/dist/types/PoolMath/ConstantProductPool.d.ts.map +1 -0
- package/dist/types/PoolMath/index.d.ts +2 -0
- package/dist/types/PoolMath/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +51 -0
- package/src/@types/index.ts +1 -0
- package/src/PoolMath/ConstantProductPool.ts +397 -0
- package/src/PoolMath/__tests__/ConstantProductPool.test.ts +649 -0
- package/src/PoolMath/index.ts +1 -0
- package/src/index.ts +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _index = require("../PoolMath/index.js");
|
|
7
|
+
Object.keys(_index).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _index[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _index[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_index","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../../src/@types/index.ts"],"sourcesContent":["export * from \"../PoolMath/index.js\";\n"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSwapOutput = exports.getSwapInput = exports.getShare = exports.getLp = exports.getFirstLp = exports.getAssetsRatio = exports.calculateLiquidity = exports.addLiquidity = void 0;
|
|
7
|
+
exports.getSwapRatio = getSwapRatio;
|
|
8
|
+
exports.getTokensForLp = void 0;
|
|
9
|
+
var _asset = require("@sundaeswap/asset");
|
|
10
|
+
var _fraction = require("@sundaeswap/fraction");
|
|
11
|
+
var _bigintMath = require("@sundaeswap/bigint-math");
|
|
12
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
13
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
15
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
16
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
17
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
18
|
+
/**
|
|
19
|
+
* The direction of a ratio (A per B or B per A)
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Asset used in a ratio calculation
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The result of a ratio calculation on a pool
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The amounts for a token pair
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get the lp token amount for a, b
|
|
36
|
+
* @param a tokenA amount
|
|
37
|
+
* @param b tokenB amount
|
|
38
|
+
* @returns the minted lp token amount
|
|
39
|
+
*/
|
|
40
|
+
var getFirstLp = exports.getFirstLp = function getFirstLp(a, b) {
|
|
41
|
+
return (0, _bigintMath.sqrt)(a * b);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated
|
|
46
|
+
*/
|
|
47
|
+
var getLp = exports.getLp = getFirstLp;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get the share ratio as Fraction
|
|
51
|
+
* @param lp
|
|
52
|
+
* @param totalLp
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
var getShare = exports.getShare = function getShare(lp, totalLp) {
|
|
56
|
+
return new _fraction.Fraction(lp, totalLp);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Calculate the Add (Mixed-Deposit) Liquidity parameters
|
|
61
|
+
*
|
|
62
|
+
* @param {bigint} a - The amount of token A to deposit.
|
|
63
|
+
* @param {bigint} b - The amount of token B to deposit.
|
|
64
|
+
* @param {bigint} aReserve - The current reserve of token A in the pool.
|
|
65
|
+
* @param {bigint} bReserve - The current reserve of token B in the pool.
|
|
66
|
+
* @param {bigint} totalLp - The total lp tokens for the pool before the deposit.
|
|
67
|
+
* @throws {Error} If the pool doesn't have enough liquidity.
|
|
68
|
+
* @throws {Error} If either of the deposit amounts is zero.
|
|
69
|
+
* @returns {Object} An object containing:
|
|
70
|
+
* - nextTotalLp: The total lp tokens for the pool after the deposit.
|
|
71
|
+
* - generatedLp: The amount of lp tokens generated by the deposit.
|
|
72
|
+
* - shareAfterDeposit: The depositor's share of the pool after the deposit.
|
|
73
|
+
*/
|
|
74
|
+
var calculateLiquidity = exports.calculateLiquidity = function calculateLiquidity(a, b, aReserve, bReserve, totalLp) {
|
|
75
|
+
if (aReserve === 0n || bReserve === 0n) {
|
|
76
|
+
throw new Error("Not enough pool liquidity");
|
|
77
|
+
}
|
|
78
|
+
if (a === 0n || b === 0n) {
|
|
79
|
+
throw new Error("Cannot use a deposit asset amount of 0");
|
|
80
|
+
}
|
|
81
|
+
var bInUnitsOfA = b * aReserve / bReserve;
|
|
82
|
+
var aChange;
|
|
83
|
+
var bChange;
|
|
84
|
+
if (bInUnitsOfA > a) {
|
|
85
|
+
bChange = bReserve * (bInUnitsOfA - a) / aReserve;
|
|
86
|
+
aChange = 0n;
|
|
87
|
+
} else {
|
|
88
|
+
aChange = a - bInUnitsOfA;
|
|
89
|
+
bChange = 0n;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Subtract off the surplus as returned to the user
|
|
93
|
+
var actualDepositedA = a - aChange;
|
|
94
|
+
var actualDepositedB = b - bChange;
|
|
95
|
+
|
|
96
|
+
// Calculate LP Tokens
|
|
97
|
+
var newLpTokens = actualDepositedA * totalLp / aReserve;
|
|
98
|
+
var newTotalLpTokens = totalLp + newLpTokens;
|
|
99
|
+
return {
|
|
100
|
+
nextTotalLp: newTotalLpTokens,
|
|
101
|
+
generatedLp: newLpTokens,
|
|
102
|
+
shareAfterDeposit: getShare(newLpTokens, newTotalLpTokens),
|
|
103
|
+
bChange: bChange,
|
|
104
|
+
aChange: aChange,
|
|
105
|
+
actualDepositedA: actualDepositedA,
|
|
106
|
+
actualDepositedB: actualDepositedB
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @deprecated
|
|
112
|
+
*
|
|
113
|
+
* Use {@link calculateLiquidity} instead.
|
|
114
|
+
*/
|
|
115
|
+
var addLiquidity = exports.addLiquidity = function addLiquidity(a, aReserve, bReserve, totalLp) {
|
|
116
|
+
var nextTotalLp = new _fraction.Fraction(totalLp * (a + aReserve), aReserve).quotient;
|
|
117
|
+
var lp = nextTotalLp - totalLp;
|
|
118
|
+
var b = new _fraction.Fraction(bReserve * a, aReserve);
|
|
119
|
+
var share = getShare(lp, nextTotalLp);
|
|
120
|
+
if (b.quotient === 0n) {
|
|
121
|
+
throw new Error("The provided a asset is not enough to equal at least 1 of the b asset.");
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
nextTotalLp: nextTotalLp,
|
|
125
|
+
/** @deprecated */
|
|
126
|
+
lp: lp,
|
|
127
|
+
generatedLp: lp,
|
|
128
|
+
/** @deprecated */
|
|
129
|
+
b: b.quotient,
|
|
130
|
+
requiredB: b.quotient,
|
|
131
|
+
/** @deprecated */
|
|
132
|
+
share: share,
|
|
133
|
+
shareAfterDeposit: share
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Get the token amounts the given lp represents
|
|
139
|
+
* @param lp the lp amount
|
|
140
|
+
* @param aReserve the pool's reserveA amount
|
|
141
|
+
* @param bReserve the pool's reserveB amount
|
|
142
|
+
* @param totalLp the pool's total minted lp currently
|
|
143
|
+
* @returns [a, b] token amounts
|
|
144
|
+
*/
|
|
145
|
+
var getTokensForLp = exports.getTokensForLp = function getTokensForLp(lp, aReserve, bReserve, totalLp) {
|
|
146
|
+
return [new _fraction.Fraction(lp * aReserve, totalLp).quotient, new _fraction.Fraction(lp * bReserve, totalLp).quotient];
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Holds the calculated outcome of a swap
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Calculate swap outcome for a given input and pool parameters (input tokens, output tokens, fee).
|
|
155
|
+
* Throws if
|
|
156
|
+
* - any of the arguments are negative
|
|
157
|
+
* - fee is greater than or equal 1
|
|
158
|
+
*
|
|
159
|
+
* @param input The given amount of tokens to be swapped
|
|
160
|
+
* @param inputReserve The amount of tokens in the input reserve
|
|
161
|
+
* @param outputReserve The amount of tokens in the output reserve
|
|
162
|
+
* @param fee The liquidity provider fee
|
|
163
|
+
* @returns The swap details
|
|
164
|
+
*/
|
|
165
|
+
var getSwapOutput = exports.getSwapOutput = function getSwapOutput(input, inputReserve, outputReserve, fee, roundOutputUp) {
|
|
166
|
+
if (input <= 0 || inputReserve <= 0 || outputReserve <= 0) throw new Error("Input and reserves must be positive");
|
|
167
|
+
fee = _fraction.Fraction.asFraction(fee);
|
|
168
|
+
if (fee.lt(_fraction.Fraction.ZERO) || fee.gt(_fraction.Fraction.ONE)) throw new Error("fee must be between 0 and 1");
|
|
169
|
+
var feeDiff = fee.denominator - fee.numerator;
|
|
170
|
+
var outputNumerator = outputReserve * input * feeDiff;
|
|
171
|
+
var outputDenominator = inputReserve * fee.denominator + input * feeDiff;
|
|
172
|
+
var output = new _fraction.Fraction(outputNumerator, outputDenominator);
|
|
173
|
+
var safeOutput = roundOutputUp ? (outputNumerator + outputDenominator - 1n) / outputDenominator : output.quotient;
|
|
174
|
+
var inputLpFee = new _fraction.Fraction(input * fee.numerator, fee.denominator).quotient;
|
|
175
|
+
var nextInputReserve = inputReserve + input;
|
|
176
|
+
var nextOutputReserve = outputReserve - safeOutput;
|
|
177
|
+
|
|
178
|
+
// PRICEIMPACT: "priceImpact" is slightly misleadingly named in the industry as a whole
|
|
179
|
+
// just by it's name, it would imply that it's the percentage difference between
|
|
180
|
+
// the current price and the price after the swap, but it's actually the percentage
|
|
181
|
+
// difference between the real price of your swap, and the price implied by the current
|
|
182
|
+
// reserves; We got this wrong in v1, but this aligns it with the industry standard
|
|
183
|
+
// Source: https://dailydefi.org/articles/price-impact-and-how-to-calculate/
|
|
184
|
+
var amountInLessFee = input - inputLpFee;
|
|
185
|
+
var idealPrice = new _fraction.Fraction(inputReserve, outputReserve);
|
|
186
|
+
var actualPrice = new _fraction.Fraction(amountInLessFee, safeOutput);
|
|
187
|
+
var priceImpact = _fraction.Fraction.ONE.subtract(idealPrice.divide(actualPrice));
|
|
188
|
+
return {
|
|
189
|
+
input: input,
|
|
190
|
+
output: safeOutput,
|
|
191
|
+
inputLpFee: inputLpFee,
|
|
192
|
+
nextInputReserve: nextInputReserve,
|
|
193
|
+
nextOutputReserve: nextOutputReserve,
|
|
194
|
+
priceImpact: priceImpact
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Calculate input required for a swap outcome for a given output and pool parameters (input tokens, output tokens, fee).
|
|
200
|
+
* Throws if
|
|
201
|
+
* - any of the arguments are negative
|
|
202
|
+
* - fee is greater than or equal 1
|
|
203
|
+
* - output is greater than or equal to output reserve
|
|
204
|
+
*
|
|
205
|
+
* @param output
|
|
206
|
+
* @param inputReserve
|
|
207
|
+
* @param outputReserve
|
|
208
|
+
* @param fee
|
|
209
|
+
* @returns The swap details
|
|
210
|
+
*/
|
|
211
|
+
var getSwapInput = exports.getSwapInput = function getSwapInput(output, inputReserve, outputReserve, fee) {
|
|
212
|
+
if (output <= 0 || inputReserve <= 0 || outputReserve <= 0) throw new Error("Output and reserves must be positive");
|
|
213
|
+
if (output >= outputReserve) throw new Error("Output must be less than output reserve");
|
|
214
|
+
fee = _fraction.Fraction.asFraction(fee);
|
|
215
|
+
if (fee.lt(_fraction.Fraction.ZERO) || fee.gte(_fraction.Fraction.ONE)) throw new Error("fee must be [0,1)");
|
|
216
|
+
var feeDiff = BigInt(fee.denominator - fee.numerator);
|
|
217
|
+
var input = new _fraction.Fraction(inputReserve * output * fee.denominator, (outputReserve - output) * feeDiff).quotient + 1n;
|
|
218
|
+
var inputLpFee = new _fraction.Fraction(input * fee.numerator, fee.denominator).quotient;
|
|
219
|
+
var nextInputReserve = inputReserve + input;
|
|
220
|
+
var nextOutputReserve = outputReserve - output;
|
|
221
|
+
|
|
222
|
+
// See PRICEIMPACT
|
|
223
|
+
var amountInLessFee = input - inputLpFee;
|
|
224
|
+
var idealPrice = new _fraction.Fraction(inputReserve, outputReserve);
|
|
225
|
+
var actualPrice = new _fraction.Fraction(amountInLessFee, output);
|
|
226
|
+
var priceImpact = _fraction.Fraction.ONE.subtract(idealPrice.divide(actualPrice));
|
|
227
|
+
return {
|
|
228
|
+
input: input,
|
|
229
|
+
output: output,
|
|
230
|
+
inputLpFee: inputLpFee,
|
|
231
|
+
nextInputReserve: nextInputReserve,
|
|
232
|
+
nextOutputReserve: nextOutputReserve,
|
|
233
|
+
priceImpact: priceImpact
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Calculates the ratio between two values.
|
|
239
|
+
*
|
|
240
|
+
* @param {TFractionLike} firstValue - The first value for the ratio calculation.
|
|
241
|
+
* @param {TFractionLike} secondValue - The second value for the ratio calculation.
|
|
242
|
+
* @returns {string|null} The ratio of the first value to the second value, expressed as a string in base 10. If either of the inputs is zero or negative, or if either input is missing, the function returns null.
|
|
243
|
+
* @throws {Error} Will throw an error if the inputs are not valid for the Fraction class's `asFraction` method.
|
|
244
|
+
*/
|
|
245
|
+
var getAssetsRatio = exports.getAssetsRatio = function getAssetsRatio(firstValue, secondValue) {
|
|
246
|
+
var first = _fraction.Fraction.asFraction(firstValue !== null && firstValue !== void 0 ? firstValue : 0);
|
|
247
|
+
var second = _fraction.Fraction.asFraction(secondValue !== null && secondValue !== void 0 ? secondValue : 0);
|
|
248
|
+
if (!first.greaterThan(0) || !second.greaterThan(0)) {
|
|
249
|
+
return "0";
|
|
250
|
+
}
|
|
251
|
+
return first.divide(second).toString(10);
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Calculates the swap ratio between two assets and returns an AssetAmount instance representing this ratio.
|
|
256
|
+
*
|
|
257
|
+
* The assets are first sorted lexicographically by their assetId to ensure any calculation will match
|
|
258
|
+
* pool ratios (which are also sorted lexicographically when created). The direction of the swap determines the calculation.
|
|
259
|
+
* For 'A_PER_B', it calculates how much of the lexicographically first asset (A) is obtained for each unit of the
|
|
260
|
+
* lexicographically second asset (B). For 'B_PER_A', it calculates how much of the lexicographically second asset (B)
|
|
261
|
+
* is obtained for each unit of the lexicographically first asset (A).
|
|
262
|
+
*
|
|
263
|
+
* The returned AssetAmount is represented in the decimal format of the asset that is being received in the swap operation.
|
|
264
|
+
* In 'A_PER_B' direction, the lexicographically first asset (A) is received, so the AssetAmount will be in the decimal format
|
|
265
|
+
* of Asset A. In 'B_PER_A' direction, the lexicographically second asset (B) is received, so the AssetAmount will be in the decimal format of Asset B.
|
|
266
|
+
*
|
|
267
|
+
* @param {TRatioDirection} direction - The direction of the swap: 'A_PER_B' means the first asset lexicographically is received and the second is given, 'B_PER_A' means the second asset lexicographically is received and the first is given.
|
|
268
|
+
* @param {[IRatioCalculationAsset, IRatioCalculationAsset]} assets - An array of two assets involved in the swap. The order of the assets in this array does not matter as they will be sorted lexicographically by their assetId inside the function.
|
|
269
|
+
*
|
|
270
|
+
* @returns {TSwapRatio} The calculated swap ratio in different representations.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
*
|
|
274
|
+
* ```ts
|
|
275
|
+
* const asset1 = { quantity: 100, decimals: 0, assetId: 'B' };
|
|
276
|
+
* const asset2 = { quantity: 2000000, decimals: 6, assetId: 'A' };
|
|
277
|
+
* const amount = getSwapRatio('A_PER_B', [asset1, asset2]);
|
|
278
|
+
* const sameAmount = getSwapRatio('A_PER_B', [asset2, asset1]);
|
|
279
|
+
* console.log(amount.ratioAsFraction); // Returns a Fraction class of the ratio.
|
|
280
|
+
* console.log(sameAmount.ratioAsFraction); // Same as above.
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
function getSwapRatio(direction, assets) {
|
|
284
|
+
var calculatedAmount;
|
|
285
|
+
var rawRatio;
|
|
286
|
+
var adaIds = ["", ".", "ada.lovelace"];
|
|
287
|
+
var _assets$sort = assets.sort(function (a, b) {
|
|
288
|
+
var isASpecial = adaIds.includes(a.assetId);
|
|
289
|
+
var isBSpecial = adaIds.includes(b.assetId);
|
|
290
|
+
if (isASpecial && !isBSpecial) {
|
|
291
|
+
return -1;
|
|
292
|
+
}
|
|
293
|
+
if (!isASpecial && isBSpecial) {
|
|
294
|
+
return 1;
|
|
295
|
+
}
|
|
296
|
+
return a.assetId.localeCompare(b.assetId);
|
|
297
|
+
}),
|
|
298
|
+
_assets$sort2 = _slicedToArray(_assets$sort, 2),
|
|
299
|
+
firstAsset = _assets$sort2[0],
|
|
300
|
+
secondAsset = _assets$sort2[1];
|
|
301
|
+
if (direction === "A_PER_B") {
|
|
302
|
+
rawRatio = getAssetsRatio(firstAsset.quantity, secondAsset.quantity);
|
|
303
|
+
calculatedAmount = _asset.AssetAmount.fromValue(Number(rawRatio) * Math.pow(10, secondAsset.decimals - firstAsset.decimals), firstAsset.decimals);
|
|
304
|
+
} else {
|
|
305
|
+
rawRatio = getAssetsRatio(secondAsset.quantity, firstAsset.quantity);
|
|
306
|
+
calculatedAmount = _asset.AssetAmount.fromValue(Number(rawRatio) * Math.pow(10, firstAsset.decimals - secondAsset.decimals), secondAsset.decimals);
|
|
307
|
+
}
|
|
308
|
+
return {
|
|
309
|
+
calculatedAmount: calculatedAmount,
|
|
310
|
+
display: calculatedAmount.value.toString(),
|
|
311
|
+
ratioAsFraction: _fraction.Fraction.asFraction(rawRatio),
|
|
312
|
+
isDivisible: calculatedAmount.decimals > 0,
|
|
313
|
+
belowMinimumRatio: rawRatio.toString() === "0"
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
//# sourceMappingURL=ConstantProductPool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConstantProductPool.js","names":["_asset","require","_fraction","_bigintMath","_slicedToArray","r","e","_arrayWithHoles","_iterableToArrayLimit","_unsupportedIterableToArray","_nonIterableRest","TypeError","a","_arrayLikeToArray","t","toString","call","slice","constructor","name","Array","from","test","length","n","l","Symbol","iterator","i","u","f","o","next","Object","done","push","value","isArray","getFirstLp","exports","b","sqrt","getLp","getShare","lp","totalLp","Fraction","calculateLiquidity","aReserve","bReserve","Error","bInUnitsOfA","aChange","bChange","actualDepositedA","actualDepositedB","newLpTokens","newTotalLpTokens","nextTotalLp","generatedLp","shareAfterDeposit","addLiquidity","quotient","share","requiredB","getTokensForLp","getSwapOutput","input","inputReserve","outputReserve","fee","roundOutputUp","asFraction","lt","ZERO","gt","ONE","feeDiff","denominator","numerator","outputNumerator","outputDenominator","output","safeOutput","inputLpFee","nextInputReserve","nextOutputReserve","amountInLessFee","idealPrice","actualPrice","priceImpact","subtract","divide","getSwapInput","gte","BigInt","getAssetsRatio","firstValue","secondValue","first","second","greaterThan","getSwapRatio","direction","assets","calculatedAmount","rawRatio","adaIds","_assets$sort","sort","isASpecial","includes","assetId","isBSpecial","localeCompare","_assets$sort2","firstAsset","secondAsset","quantity","AssetAmount","fromValue","Number","Math","pow","decimals","display","ratioAsFraction","isDivisible","belowMinimumRatio"],"sources":["../../../src/PoolMath/ConstantProductPool.ts"],"sourcesContent":["import { AssetAmount } from \"@sundaeswap/asset\";\nimport { Fraction, type TFractionLike } from \"@sundaeswap/fraction\";\nimport { sqrt } from \"@sundaeswap/bigint-math\";\n\n/**\n * The direction of a ratio (A per B or B per A)\n */\nexport type TRatioDirection = \"A_PER_B\" | \"B_PER_A\";\n\n/**\n * Asset used in a ratio calculation\n */\nexport interface IRatioCalculationAsset {\n assetId: string;\n quantity: bigint;\n decimals: number;\n}\n\n/**\n * The result of a ratio calculation on a pool\n */\nexport interface IRatioCalculationResult {\n calculatedAmount: AssetAmount;\n ratioAsFraction: Fraction;\n display: string;\n isDivisible: boolean;\n belowMinimumRatio: boolean;\n}\n\n/**\n * The amounts for a token pair\n */\nexport type TPair = [bigint, bigint];\n\n/**\n * Get the lp token amount for a, b\n * @param a tokenA amount\n * @param b tokenB amount\n * @returns the minted lp token amount\n */\nexport const getFirstLp = (a: bigint, b: bigint) => sqrt(a * b);\n\n/**\n * @deprecated\n */\nexport const getLp = getFirstLp;\n\n/**\n * Get the share ratio as Fraction\n * @param lp\n * @param totalLp\n * @returns\n */\nexport const getShare = (lp: bigint, totalLp: bigint) =>\n new Fraction(lp, totalLp);\n\n/**\n * Calculate the Add (Mixed-Deposit) Liquidity parameters\n *\n * @param {bigint} a - The amount of token A to deposit.\n * @param {bigint} b - The amount of token B to deposit.\n * @param {bigint} aReserve - The current reserve of token A in the pool.\n * @param {bigint} bReserve - The current reserve of token B in the pool.\n * @param {bigint} totalLp - The total lp tokens for the pool before the deposit.\n * @throws {Error} If the pool doesn't have enough liquidity.\n * @throws {Error} If either of the deposit amounts is zero.\n * @returns {Object} An object containing:\n * - nextTotalLp: The total lp tokens for the pool after the deposit.\n * - generatedLp: The amount of lp tokens generated by the deposit.\n * - shareAfterDeposit: The depositor's share of the pool after the deposit.\n */\nexport const calculateLiquidity = (\n a: bigint,\n b: bigint,\n aReserve: bigint,\n bReserve: bigint,\n totalLp: bigint,\n) => {\n if (aReserve === 0n || bReserve === 0n) {\n throw new Error(\"Not enough pool liquidity\");\n }\n\n if (a === 0n || b === 0n) {\n throw new Error(\"Cannot use a deposit asset amount of 0\");\n }\n\n const bInUnitsOfA = (b * aReserve) / bReserve;\n\n let aChange: bigint;\n let bChange: bigint;\n\n if (bInUnitsOfA > a) {\n bChange = (bReserve * (bInUnitsOfA - a)) / aReserve;\n aChange = 0n;\n } else {\n aChange = a - bInUnitsOfA;\n bChange = 0n;\n }\n\n // Subtract off the surplus as returned to the user\n const actualDepositedA = a - aChange;\n const actualDepositedB = b - bChange;\n\n // Calculate LP Tokens\n const newLpTokens = (actualDepositedA * totalLp) / aReserve;\n const newTotalLpTokens = totalLp + newLpTokens;\n\n return {\n nextTotalLp: newTotalLpTokens,\n generatedLp: newLpTokens,\n shareAfterDeposit: getShare(newLpTokens, newTotalLpTokens),\n bChange,\n aChange,\n actualDepositedA,\n actualDepositedB,\n };\n};\n\n/**\n * @deprecated\n *\n * Use {@link calculateLiquidity} instead.\n */\nexport const addLiquidity = (\n a: bigint,\n aReserve: bigint,\n bReserve: bigint,\n totalLp: bigint,\n) => {\n const nextTotalLp = new Fraction(totalLp * (a + aReserve), aReserve).quotient;\n const lp = nextTotalLp - totalLp;\n const b = new Fraction(bReserve * a, aReserve);\n const share = getShare(lp, nextTotalLp);\n\n if (b.quotient === 0n) {\n throw new Error(\n \"The provided a asset is not enough to equal at least 1 of the b asset.\",\n );\n }\n\n return {\n nextTotalLp,\n /** @deprecated */\n lp,\n generatedLp: lp,\n /** @deprecated */\n b: b.quotient,\n requiredB: b.quotient,\n /** @deprecated */\n share,\n shareAfterDeposit: share,\n };\n};\n\n/**\n * Get the token amounts the given lp represents\n * @param lp the lp amount\n * @param aReserve the pool's reserveA amount\n * @param bReserve the pool's reserveB amount\n * @param totalLp the pool's total minted lp currently\n * @returns [a, b] token amounts\n */\nexport const getTokensForLp = (\n lp: bigint,\n aReserve: bigint,\n bReserve: bigint,\n totalLp: bigint,\n): TPair => [\n new Fraction(lp * aReserve, totalLp).quotient,\n new Fraction(lp * bReserve, totalLp).quotient,\n];\n\n/**\n * Holds the calculated outcome of a swap\n */\nexport type TSwapOutcome = {\n input: bigint;\n output: bigint;\n inputLpFee: bigint;\n nextInputReserve: bigint;\n nextOutputReserve: bigint;\n priceImpact: Fraction;\n};\n\n/**\n * Calculate swap outcome for a given input and pool parameters (input tokens, output tokens, fee).\n * Throws if\n * - any of the arguments are negative\n * - fee is greater than or equal 1\n *\n * @param input The given amount of tokens to be swapped\n * @param inputReserve The amount of tokens in the input reserve\n * @param outputReserve The amount of tokens in the output reserve\n * @param fee The liquidity provider fee\n * @returns The swap details\n */\nexport const getSwapOutput = (\n input: bigint,\n inputReserve: bigint,\n outputReserve: bigint,\n fee: TFractionLike,\n roundOutputUp?: boolean,\n): TSwapOutcome => {\n if (input <= 0 || inputReserve <= 0 || outputReserve <= 0)\n throw new Error(\"Input and reserves must be positive\");\n\n fee = Fraction.asFraction(fee);\n if (fee.lt(Fraction.ZERO) || fee.gt(Fraction.ONE))\n throw new Error(\"fee must be between 0 and 1\");\n\n const feeDiff = fee.denominator - fee.numerator;\n const outputNumerator = outputReserve * input * feeDiff;\n const outputDenominator = inputReserve * fee.denominator + input * feeDiff;\n const output = new Fraction(outputNumerator, outputDenominator);\n\n const safeOutput = roundOutputUp\n ? (outputNumerator + outputDenominator - 1n) / outputDenominator\n : output.quotient;\n\n const inputLpFee = new Fraction(input * fee.numerator, fee.denominator)\n .quotient;\n const nextInputReserve = inputReserve + input;\n const nextOutputReserve = outputReserve - safeOutput;\n\n // PRICEIMPACT: \"priceImpact\" is slightly misleadingly named in the industry as a whole\n // just by it's name, it would imply that it's the percentage difference between\n // the current price and the price after the swap, but it's actually the percentage\n // difference between the real price of your swap, and the price implied by the current\n // reserves; We got this wrong in v1, but this aligns it with the industry standard\n // Source: https://dailydefi.org/articles/price-impact-and-how-to-calculate/\n const amountInLessFee = input - inputLpFee;\n const idealPrice = new Fraction(inputReserve, outputReserve);\n const actualPrice = new Fraction(amountInLessFee, safeOutput);\n const priceImpact = Fraction.ONE.subtract(idealPrice.divide(actualPrice));\n return {\n input,\n output: safeOutput,\n inputLpFee,\n nextInputReserve,\n nextOutputReserve,\n priceImpact,\n };\n};\n\n/**\n * Calculate input required for a swap outcome for a given output and pool parameters (input tokens, output tokens, fee).\n * Throws if\n * - any of the arguments are negative\n * - fee is greater than or equal 1\n * - output is greater than or equal to output reserve\n *\n * @param output\n * @param inputReserve\n * @param outputReserve\n * @param fee\n * @returns The swap details\n */\nexport const getSwapInput = (\n output: bigint,\n inputReserve: bigint,\n outputReserve: bigint,\n fee: TFractionLike,\n): TSwapOutcome => {\n if (output <= 0 || inputReserve <= 0 || outputReserve <= 0)\n throw new Error(\"Output and reserves must be positive\");\n\n if (output >= outputReserve)\n throw new Error(\"Output must be less than output reserve\");\n\n fee = Fraction.asFraction(fee);\n if (fee.lt(Fraction.ZERO) || fee.gte(Fraction.ONE))\n throw new Error(\"fee must be [0,1)\");\n\n const feeDiff = BigInt(fee.denominator - fee.numerator);\n const input =\n new Fraction(\n inputReserve * output * fee.denominator,\n (outputReserve - output) * feeDiff,\n ).quotient + 1n;\n\n const inputLpFee = new Fraction(input * fee.numerator, fee.denominator)\n .quotient;\n const nextInputReserve = inputReserve + input;\n const nextOutputReserve = outputReserve - output;\n\n // See PRICEIMPACT\n const amountInLessFee = input - inputLpFee;\n const idealPrice = new Fraction(inputReserve, outputReserve);\n const actualPrice = new Fraction(amountInLessFee, output);\n const priceImpact = Fraction.ONE.subtract(idealPrice.divide(actualPrice));\n\n return {\n input,\n output,\n inputLpFee,\n nextInputReserve,\n nextOutputReserve,\n priceImpact,\n };\n};\n\n/**\n * Calculates the ratio between two values.\n *\n * @param {TFractionLike} firstValue - The first value for the ratio calculation.\n * @param {TFractionLike} secondValue - The second value for the ratio calculation.\n * @returns {string|null} The ratio of the first value to the second value, expressed as a string in base 10. If either of the inputs is zero or negative, or if either input is missing, the function returns null.\n * @throws {Error} Will throw an error if the inputs are not valid for the Fraction class's `asFraction` method.\n */\nexport const getAssetsRatio = (\n firstValue: TFractionLike,\n secondValue: TFractionLike,\n) => {\n const first = Fraction.asFraction(firstValue ?? 0);\n const second = Fraction.asFraction(secondValue ?? 0);\n\n if (!first.greaterThan(0) || !second.greaterThan(0)) {\n return \"0\";\n }\n\n return first.divide(second).toString(10);\n};\n\n/**\n * Calculates the swap ratio between two assets and returns an AssetAmount instance representing this ratio.\n *\n * The assets are first sorted lexicographically by their assetId to ensure any calculation will match\n * pool ratios (which are also sorted lexicographically when created). The direction of the swap determines the calculation.\n * For 'A_PER_B', it calculates how much of the lexicographically first asset (A) is obtained for each unit of the\n * lexicographically second asset (B). For 'B_PER_A', it calculates how much of the lexicographically second asset (B)\n * is obtained for each unit of the lexicographically first asset (A).\n *\n * The returned AssetAmount is represented in the decimal format of the asset that is being received in the swap operation.\n * In 'A_PER_B' direction, the lexicographically first asset (A) is received, so the AssetAmount will be in the decimal format\n * of Asset A. In 'B_PER_A' direction, the lexicographically second asset (B) is received, so the AssetAmount will be in the decimal format of Asset B.\n *\n * @param {TRatioDirection} direction - The direction of the swap: 'A_PER_B' means the first asset lexicographically is received and the second is given, 'B_PER_A' means the second asset lexicographically is received and the first is given.\n * @param {[IRatioCalculationAsset, IRatioCalculationAsset]} assets - An array of two assets involved in the swap. The order of the assets in this array does not matter as they will be sorted lexicographically by their assetId inside the function.\n *\n * @returns {TSwapRatio} The calculated swap ratio in different representations.\n *\n * @example\n *\n * ```ts\n * const asset1 = { quantity: 100, decimals: 0, assetId: 'B' };\n * const asset2 = { quantity: 2000000, decimals: 6, assetId: 'A' };\n * const amount = getSwapRatio('A_PER_B', [asset1, asset2]);\n * const sameAmount = getSwapRatio('A_PER_B', [asset2, asset1]);\n * console.log(amount.ratioAsFraction); // Returns a Fraction class of the ratio.\n * console.log(sameAmount.ratioAsFraction); // Same as above.\n * ```\n */\nexport function getSwapRatio(\n direction: TRatioDirection,\n assets: [IRatioCalculationAsset, IRatioCalculationAsset],\n): IRatioCalculationResult {\n let calculatedAmount: AssetAmount;\n let rawRatio: string;\n const adaIds = [\"\", \".\", \"ada.lovelace\"];\n\n const [firstAsset, secondAsset] = assets.sort((a, b) => {\n const isASpecial = adaIds.includes(a.assetId);\n const isBSpecial = adaIds.includes(b.assetId);\n\n if (isASpecial && !isBSpecial) {\n return -1;\n }\n\n if (!isASpecial && isBSpecial) {\n return 1;\n }\n\n return a.assetId.localeCompare(b.assetId);\n });\n\n if (direction === \"A_PER_B\") {\n rawRatio = getAssetsRatio(firstAsset.quantity, secondAsset.quantity);\n calculatedAmount = AssetAmount.fromValue(\n Number(rawRatio) * 10 ** (secondAsset.decimals - firstAsset.decimals),\n firstAsset.decimals,\n );\n } else {\n rawRatio = getAssetsRatio(secondAsset.quantity, firstAsset.quantity);\n calculatedAmount = AssetAmount.fromValue(\n Number(rawRatio) * 10 ** (firstAsset.decimals - secondAsset.decimals),\n secondAsset.decimals,\n );\n }\n\n return {\n calculatedAmount: calculatedAmount,\n display: calculatedAmount.value.toString(),\n ratioAsFraction: Fraction.asFraction(rawRatio),\n isDivisible: calculatedAmount.decimals > 0,\n belowMinimumRatio: rawRatio.toString() === \"0\",\n };\n}\n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IZ,SAAS,KAAK,SAAS,EAAE;IAC3BG,QAAQ,GAAGV,cAAc,CAACoB,UAAU,CAACE,QAAQ,EAAED,WAAW,CAACC,QAAQ,CAAC;IACpEb,gBAAgB,GAAGc,kBAAW,CAACC,SAAS,CACtCC,MAAM,CAACf,QAAQ,CAAC,GAAAgB,IAAA,CAAAC,GAAA,CAAG,EAAE,EAAKN,WAAW,CAACO,QAAQ,GAAGR,UAAU,CAACQ,QAAQ,CAAC,EACrER,UAAU,CAACQ,QACb,CAAC;EACH,CAAC,MAAM;IACLlB,QAAQ,GAAGV,cAAc,CAACqB,WAAW,CAACC,QAAQ,EAAEF,UAAU,CAACE,QAAQ,CAAC;IACpEb,gBAAgB,GAAGc,kBAAW,CAACC,SAAS,CACtCC,MAAM,CAACf,QAAQ,CAAC,GAAAgB,IAAA,CAAAC,GAAA,CAAG,EAAE,EAAKP,UAAU,CAACQ,QAAQ,GAAGP,WAAW,CAACO,QAAQ,CAAC,EACrEP,WAAW,CAACO,QACd,CAAC;EACH;EAEA,OAAO;IACLnB,gBAAgB,EAAEA,gBAAgB;IAClCoB,OAAO,EAAEpB,gBAAgB,CAACrE,KAAK,CAACrB,QAAQ,CAAC,CAAC;IAC1C+G,eAAe,EAAEhF,kBAAQ,CAAC0B,UAAU,CAACkC,QAAQ,CAAC;IAC9CqB,WAAW,EAAEtB,gBAAgB,CAACmB,QAAQ,GAAG,CAAC;IAC1CI,iBAAiB,EAAEtB,QAAQ,CAAC3F,QAAQ,CAAC,CAAC,KAAK;EAC7C,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.ConstantProductPool = void 0;
|
|
8
|
+
var _ConstantProductPool = _interopRequireWildcard(require("./ConstantProductPool.js"));
|
|
9
|
+
exports.ConstantProductPool = _ConstantProductPool;
|
|
10
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/PoolMath/index.ts"],"sourcesContent":["export * as ConstantProductPool from \"./ConstantProductPool.js\";\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _index = require("./@types/index.js");
|
|
7
|
+
Object.keys(_index).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _index[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _index[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_index","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"./@types/index.js\";\n"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/@types/index.ts"],"sourcesContent":["export * from \"../PoolMath/index.js\";\n"],"mappings":"AAAA,cAAc,sBAAsB","ignoreList":[]}
|