@paraswap/dex-lib 2.16.1 → 2.16.2-balancer-v2-buy.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/build/abi/uniswap-v3/UniswapV3Pool.abi.json +363 -67
  2. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +119 -23
  3. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +285 -0
  4. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +583 -0
  5. package/build/config.js +6 -6
  6. package/build/dex/balancer-v2/balancer-v2.d.ts +9 -14
  7. package/build/dex/balancer-v2/balancer-v2.js +19 -16
  8. package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
  9. package/build/dex/balancer-v2/config.d.ts +2 -7
  10. package/build/dex/balancer-v2/config.js +20 -30
  11. package/build/dex/balancer-v2/config.js.map +1 -1
  12. package/build/dex/balancer-v2/pools/balancer-v2-pool.d.ts +24 -0
  13. package/build/dex/balancer-v2/pools/balancer-v2-pool.js +102 -0
  14. package/build/dex/balancer-v2/pools/balancer-v2-pool.js.map +1 -0
  15. package/build/dex/balancer-v2/pools/linear/LinearMath.d.ts +19 -0
  16. package/build/dex/balancer-v2/pools/linear/LinearMath.js +179 -0
  17. package/build/dex/balancer-v2/pools/linear/LinearMath.js.map +1 -0
  18. package/build/dex/balancer-v2/pools/linear/LinearPool.d.ts +50 -0
  19. package/build/dex/balancer-v2/pools/linear/LinearPool.js +458 -0
  20. package/build/dex/balancer-v2/pools/linear/LinearPool.js.map +1 -0
  21. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.d.ts +10 -0
  22. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.js +314 -0
  23. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.js.map +1 -0
  24. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.d.ts +50 -0
  25. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.js +367 -0
  26. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.js.map +1 -0
  27. package/build/dex/balancer-v2/pools/stable/StableMath.d.ts +7 -0
  28. package/build/dex/balancer-v2/pools/stable/StableMath.js +111 -0
  29. package/build/dex/balancer-v2/pools/stable/StableMath.js.map +1 -0
  30. package/build/dex/balancer-v2/pools/stable/StablePool.d.ts +30 -0
  31. package/build/dex/balancer-v2/pools/stable/StablePool.js +129 -0
  32. package/build/dex/balancer-v2/pools/stable/StablePool.js.map +1 -0
  33. package/build/dex/balancer-v2/pools/weighted/WeightedMath.d.ts +6 -0
  34. package/build/dex/balancer-v2/pools/weighted/WeightedMath.js +61 -0
  35. package/build/dex/balancer-v2/pools/weighted/WeightedMath.js.map +1 -0
  36. package/build/dex/balancer-v2/pools/weighted/WeightedPool.d.ts +30 -0
  37. package/build/dex/balancer-v2/pools/weighted/WeightedPool.js +112 -0
  38. package/build/dex/balancer-v2/pools/weighted/WeightedPool.js.map +1 -0
  39. package/build/dex/index.js +4 -0
  40. package/build/dex/index.js.map +1 -1
  41. package/build/dex/maverick-v1/config.js +1 -1
  42. package/build/dex/maverick-v1/config.js.map +1 -1
  43. package/build/dex/quickswap/config.js +8 -0
  44. package/build/dex/quickswap/config.js.map +1 -1
  45. package/build/dex/quickswap/spiritswap-v3.d.ts +6 -0
  46. package/build/dex/quickswap/spiritswap-v3.js +19 -0
  47. package/build/dex/quickswap/spiritswap-v3.js.map +1 -0
  48. package/build/dex/uniswap-v3/config.js +42 -0
  49. package/build/dex/uniswap-v3/config.js.map +1 -1
  50. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +12 -0
  51. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +23 -0
  52. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +1 -0
  53. package/build/dex/uniswap-v3/types.d.ts +3 -0
  54. package/build/dex/uniswap-v3/types.js.map +1 -1
  55. package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +2 -1
  56. package/build/dex/uniswap-v3/uniswap-v3-pool.js +3 -2
  57. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  58. package/build/dex/uniswap-v3/uniswap-v3.js +6 -3
  59. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  60. package/package.json +1 -1
  61. package/src/abi/uniswap-v3/UniswapV3Pool.abi.json +363 -67
  62. package/src/abi/uniswap-v3/UniswapV3Quoter.abi.json +119 -23
  63. package/src/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +285 -0
  64. package/src/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +583 -0
  65. package/src/config.ts +6 -6
  66. package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +99 -160
  67. package/src/dex/balancer-v2/balancer-v2.ts +41 -29
  68. package/src/dex/balancer-v2/config.ts +23 -35
  69. package/src/dex/balancer-v2/pools/balancer-v2-pool.ts +273 -0
  70. package/src/dex/balancer-v2/{LinearMath.ts → pools/linear/LinearMath.ts} +1 -1
  71. package/src/dex/balancer-v2/{LinearPool.ts → pools/linear/LinearPool.ts} +210 -5
  72. package/src/dex/balancer-v2/{StableMath.ts → pools/phantom-stable/PhantomStableMath.ts} +101 -21
  73. package/src/dex/balancer-v2/{PhantomStablePool.ts → pools/phantom-stable/PhantomStablePool.ts} +165 -11
  74. package/src/dex/balancer-v2/pools/stable/StableMath.ts +204 -0
  75. package/src/dex/balancer-v2/pools/stable/StablePool.ts +221 -0
  76. package/src/dex/balancer-v2/pools/weighted/WeightedMath.ts +84 -0
  77. package/src/dex/balancer-v2/pools/weighted/WeightedPool.ts +189 -0
  78. package/src/dex/index.ts +4 -0
  79. package/src/dex/maverick-v1/config.ts +1 -1
  80. package/src/dex/quickswap/config.ts +9 -0
  81. package/src/dex/quickswap/quickswap-e2e.test.ts +94 -0
  82. package/src/dex/quickswap/spiritswap-v3.ts +19 -0
  83. package/src/dex/uniswap-v3/config.ts +50 -0
  84. package/src/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.ts +28 -0
  85. package/src/dex/uniswap-v3/types.ts +3 -0
  86. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +156 -0
  87. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +3 -2
  88. package/src/dex/uniswap-v3/uniswap-v3.ts +7 -3
  89. package/tests/constants-e2e.ts +11 -6
  90. package/.idea/runConfigurations.xml +0 -10
  91. package/src/dex/balancer-v2/balancer-v2-pool.ts +0 -744
@@ -0,0 +1,367 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.PhantomStablePool = void 0;
30
+ const abi_1 = require("@ethersproject/abi");
31
+ const bignumber_1 = require("@ethersproject/bignumber");
32
+ const balancer_v2_pool_1 = require("../balancer-v2-pool");
33
+ const utils_1 = require("../../utils");
34
+ const PhantomStableMath = __importStar(require("./PhantomStableMath"));
35
+ const meta_stable_pool_json_1 = __importDefault(require("../../../../abi/balancer-v2/meta-stable-pool.json"));
36
+ const ComposableStable_json_1 = __importDefault(require("../../../../abi/balancer-v2/ComposableStable.json"));
37
+ const lodash_1 = require("lodash");
38
+ var PairTypes;
39
+ (function (PairTypes) {
40
+ PairTypes[PairTypes["BptToToken"] = 0] = "BptToToken";
41
+ PairTypes[PairTypes["TokenToBpt"] = 1] = "TokenToBpt";
42
+ PairTypes[PairTypes["TokenToToken"] = 2] = "TokenToToken";
43
+ })(PairTypes || (PairTypes = {}));
44
+ /*
45
+ /**
46
+ * StablePool with preminted BPT and rate providers for each token, allowing for e.g. wrapped tokens with a known
47
+ * price ratio, such as Compound's cTokens.
48
+ * BPT is preminted on Pool initialization and registered as one of the Pool's tokens, allowing for swaps to behave as
49
+ * single-token joins or exits (by swapping a token for BPT). Regular joins and exits are disabled, since no BPT is
50
+ * minted or burned after initialization.
51
+ * Preminted BPT is sometimes called Phantom BPT, as the preminted BPT (which is deposited in the Vault as balance of
52
+ * the Pool) doesn't belong to any entity until transferred out of the Pool. The Pool's arithmetic behaves as if it
53
+ * didn't exist, and the BPT total supply is not a useful value: we rely on the 'virtual supply' (how much BPT is
54
+ * actually owned by some entity) instead.
55
+ */
56
+ class PhantomStablePool extends balancer_v2_pool_1.BasePool {
57
+ constructor(vaultAddress, vaultInterface, isComposable = false) {
58
+ super();
59
+ this.isComposable = isComposable;
60
+ // This is the maximum token amount the Vault can hold. In regular operation, the total BPT supply remains constant
61
+ // and equal to _INITIAL_BPT_SUPPLY, but most of it remains in the Pool, waiting to be exchanged for tokens. The
62
+ // actual amount of BPT in circulation is the total supply minus the amount held by the Pool, and is known as the
63
+ // 'virtual supply'.
64
+ this.MAX_TOKEN_BALANCE = bignumber_1.BigNumber.from('2').pow('112').sub('1');
65
+ this.vaultAddress = vaultAddress;
66
+ this.vaultInterface = vaultInterface;
67
+ if (isComposable)
68
+ this.poolInterface = new abi_1.Interface(ComposableStable_json_1.default);
69
+ else
70
+ this.poolInterface = new abi_1.Interface(meta_stable_pool_json_1.default);
71
+ }
72
+ /*
73
+ scaling factors should include rate:
74
+ i.e.
75
+ scalingFactors: pool.tokens.map(({ decimals, priceRate }) =>
76
+ MathSol.mulDownFixed(getTokenScalingFactor(decimals), priceRate)
77
+ )
78
+ */
79
+ onSell(amounts, poolPairData) {
80
+ return this._swapGivenIn(amounts, poolPairData.tokens, poolPairData.balances, poolPairData.indexIn, poolPairData.indexOut, poolPairData.bptIndex, poolPairData.scalingFactors, poolPairData.swapFee, poolPairData.amp, poolPairData.actualSupply);
81
+ }
82
+ onBuy(amounts, poolPairData) {
83
+ return this._swapGivenOut(amounts, poolPairData.tokens, poolPairData.balances, poolPairData.indexIn, poolPairData.indexOut, poolPairData.bptIndex, poolPairData.scalingFactors, poolPairData.swapFee, poolPairData.amp, poolPairData.actualSupply);
84
+ }
85
+ // StablePool's `_onSwapGivenIn` and `_onSwapGivenOut` handlers are meant to process swaps between Pool tokens.
86
+ // Since one of the Pool's tokens is the preminted BPT, we need to a) handle swaps where that tokens is involved
87
+ // separately (as they are effectively single-token joins or exits), and b) remove BPT from the balances array when
88
+ // processing regular swaps before delegating those to StablePool's handler.
89
+ removeBPT(balances, tokenIndexIn, tokenIndexOut, bptIndex) {
90
+ if (bptIndex != -1) {
91
+ balances.splice(bptIndex, 1);
92
+ if (bptIndex < tokenIndexIn)
93
+ tokenIndexIn -= 1;
94
+ if (bptIndex < tokenIndexOut)
95
+ tokenIndexOut -= 1;
96
+ }
97
+ return {
98
+ balances,
99
+ indexIn: tokenIndexIn,
100
+ indexOut: tokenIndexOut,
101
+ };
102
+ }
103
+ _swapGivenOut(tokenAmountsOut, tokens, balances, indexIn, indexOut, bptIndex, scalingFactors, swapFeePercentage, amplificationParameter, actualSupply) {
104
+ // Phantom pools allow trading between token and pool BPT
105
+ let pairType;
106
+ if ((0, utils_1.isSameAddress)(tokens[indexIn], tokens[bptIndex])) {
107
+ pairType = PairTypes.BptToToken;
108
+ }
109
+ else if ((0, utils_1.isSameAddress)(tokens[indexOut], tokens[bptIndex])) {
110
+ pairType = PairTypes.TokenToBpt;
111
+ }
112
+ else {
113
+ pairType = PairTypes.TokenToToken;
114
+ }
115
+ const balancesUpscaled = this._upscaleArray(balances, scalingFactors);
116
+ const tokenAmountsOutScaled = tokenAmountsOut.map(a => this._upscale(a, scalingFactors[indexOut]));
117
+ let bptSupply;
118
+ if (actualSupply)
119
+ bptSupply = actualSupply;
120
+ // VirtualBPTSupply must be used for the maths
121
+ else
122
+ bptSupply = this.MAX_TOKEN_BALANCE.sub(balances[bptIndex]).toBigInt();
123
+ const droppedBpt = this.removeBPT(balancesUpscaled, indexIn, indexOut, bptIndex);
124
+ const amountsIn = this._onSwapGivenOut(tokenAmountsOutScaled, droppedBpt.balances, droppedBpt.indexIn, droppedBpt.indexOut, amplificationParameter, bptSupply, pairType);
125
+ const amountsInDownscaled = amountsIn.map(a => this._downscaleDown(a, scalingFactors[indexIn]));
126
+ return amountsInDownscaled.map(a => this._subtractSwapFeeAmount(a, swapFeePercentage));
127
+ }
128
+ _swapGivenIn(tokenAmountsIn, tokens, balances, indexIn, indexOut, bptIndex, scalingFactors, swapFeePercentage, amplificationParameter, actualSupply) {
129
+ // Phantom pools allow trading between token and pool BPT
130
+ let pairType;
131
+ if ((0, utils_1.isSameAddress)(tokens[indexIn], tokens[bptIndex])) {
132
+ pairType = PairTypes.BptToToken;
133
+ }
134
+ else if ((0, utils_1.isSameAddress)(tokens[indexOut], tokens[bptIndex])) {
135
+ pairType = PairTypes.TokenToBpt;
136
+ }
137
+ else {
138
+ pairType = PairTypes.TokenToToken;
139
+ }
140
+ // Fees are subtracted before scaling, to reduce the complexity of the rounding direction analysis.
141
+ const tokenAmountsInWithFee = tokenAmountsIn.map(a => this._subtractSwapFeeAmount(a, swapFeePercentage));
142
+ const balancesUpscaled = this._upscaleArray(balances, scalingFactors);
143
+ const tokenAmountsInScaled = tokenAmountsInWithFee.map(a => this._upscale(a, scalingFactors[indexIn]));
144
+ let bptSupply;
145
+ if (actualSupply)
146
+ bptSupply = actualSupply;
147
+ // VirtualBPTSupply must be used for the maths
148
+ else
149
+ bptSupply = this.MAX_TOKEN_BALANCE.sub(balances[bptIndex]).toBigInt();
150
+ const droppedBpt = this.removeBPT(balancesUpscaled, indexIn, indexOut, bptIndex);
151
+ const amountsOut = this._onSwapGivenIn(tokenAmountsInScaled, droppedBpt.balances, droppedBpt.indexIn, droppedBpt.indexOut, amplificationParameter, bptSupply, pairType);
152
+ // amountOut tokens are exiting the Pool, so we round down.
153
+ return amountsOut.map(a => this._downscaleDown(a, scalingFactors[indexOut]));
154
+ }
155
+ _onSwapGivenOut(tokenAmountsOut, balances, indexIn, indexOut, _amplificationParameter, virtualBptSupply, pairType) {
156
+ const invariant = PhantomStableMath._calculateInvariant(_amplificationParameter, balances, true);
157
+ const amountsIn = [];
158
+ if (pairType === PairTypes.TokenToBpt) {
159
+ tokenAmountsOut.forEach(amountOut => {
160
+ let amt;
161
+ try {
162
+ const amountsInBigInt = Array(balances.length).fill(0n);
163
+ amountsInBigInt[indexIn] = amountOut;
164
+ amt = PhantomStableMath._calcTokenInGivenExactBptOut(_amplificationParameter, balances, indexIn, amountOut, virtualBptSupply, 0n, invariant);
165
+ }
166
+ catch (err) {
167
+ amt = 0n;
168
+ }
169
+ amountsIn.push(amt);
170
+ });
171
+ }
172
+ else if (pairType === PairTypes.BptToToken) {
173
+ tokenAmountsOut.forEach(amountOut => {
174
+ let amt;
175
+ try {
176
+ const amountsOutBigInt = Array(balances.length).fill(0n);
177
+ amountsOutBigInt[indexOut] = amountOut;
178
+ amt = PhantomStableMath._calcBptInGivenExactTokensOut(_amplificationParameter, balances, amountsOutBigInt, virtualBptSupply, 0n, invariant);
179
+ }
180
+ catch (err) {
181
+ amt = 0n;
182
+ }
183
+ amountsIn.push(amt);
184
+ });
185
+ }
186
+ else {
187
+ tokenAmountsOut.forEach(amountOut => {
188
+ let amt;
189
+ try {
190
+ amt = PhantomStableMath._calcInGivenOut(_amplificationParameter, balances, indexIn, indexOut, amountOut, 0n, invariant);
191
+ }
192
+ catch (err) {
193
+ amt = 0n;
194
+ }
195
+ amountsIn.push(amt);
196
+ });
197
+ }
198
+ return amountsIn;
199
+ }
200
+ /*
201
+ Called when a swap with the Pool occurs, where the amount of tokens entering the Pool is known.
202
+ All amounts are upscaled.
203
+ Swap fee is already deducted.
204
+ The return value is also considered upscaled, and should be downscaled (rounding down)
205
+ */
206
+ _onSwapGivenIn(tokenAmountsIn, balances, indexIn, indexOut, _amplificationParameter, virtualBptSupply, pairType) {
207
+ const invariant = PhantomStableMath._calculateInvariant(_amplificationParameter, balances, true);
208
+ const amountsOut = [];
209
+ if (pairType === PairTypes.TokenToBpt) {
210
+ tokenAmountsIn.forEach(amountIn => {
211
+ let amt;
212
+ try {
213
+ const amountsInBigInt = Array(balances.length).fill(0n);
214
+ amountsInBigInt[indexIn] = amountIn;
215
+ amt = PhantomStableMath._calcBptOutGivenExactTokensIn(_amplificationParameter, balances, amountsInBigInt, virtualBptSupply, invariant);
216
+ }
217
+ catch (err) {
218
+ amt = 0n;
219
+ }
220
+ amountsOut.push(amt);
221
+ });
222
+ }
223
+ else if (pairType === PairTypes.BptToToken) {
224
+ tokenAmountsIn.forEach(amountIn => {
225
+ let amt;
226
+ try {
227
+ amt = PhantomStableMath._calcTokenOutGivenExactBptIn(_amplificationParameter, balances, indexOut, amountIn, virtualBptSupply, invariant);
228
+ }
229
+ catch (err) {
230
+ amt = 0n;
231
+ }
232
+ amountsOut.push(amt);
233
+ });
234
+ }
235
+ else {
236
+ tokenAmountsIn.forEach(amountIn => {
237
+ let amt;
238
+ try {
239
+ amt = PhantomStableMath._calcOutGivenIn(_amplificationParameter, balances, indexIn, indexOut, amountIn, invariant);
240
+ }
241
+ catch (err) {
242
+ amt = 0n;
243
+ }
244
+ amountsOut.push(amt);
245
+ });
246
+ }
247
+ return amountsOut;
248
+ }
249
+ /*
250
+ Helper function to parse pool data into params for onSell function.
251
+ */
252
+ parsePoolPairData(pool, poolState, tokenIn, tokenOut) {
253
+ let indexIn = 0, indexOut = 0, bptIndex = 0;
254
+ const balances = [];
255
+ const scalingFactors = [];
256
+ const tokens = poolState.orderedTokens.map((tokenAddress, i) => {
257
+ const t = pool.tokensMap[tokenAddress.toLowerCase()];
258
+ if (t.address.toLowerCase() === tokenIn.toLowerCase())
259
+ indexIn = i;
260
+ if (t.address.toLowerCase() === tokenOut.toLowerCase())
261
+ indexOut = i;
262
+ if (t.address.toLowerCase() === pool.address.toLowerCase())
263
+ bptIndex = i;
264
+ balances.push(poolState.tokens[t.address.toLowerCase()].balance);
265
+ scalingFactors.push(poolState.tokens[t.address.toLowerCase()].scalingFactor || 0n);
266
+ return t.address;
267
+ });
268
+ const poolPairData = {
269
+ tokens,
270
+ balances,
271
+ indexIn,
272
+ indexOut,
273
+ scalingFactors,
274
+ bptIndex,
275
+ swapFee: poolState.swapFee,
276
+ amp: poolState.amp ? poolState.amp : 0n,
277
+ actualSupply: poolState.actualSupply,
278
+ };
279
+ return poolPairData;
280
+ }
281
+ /*
282
+ Helper function to construct onchain multicall data for PhantomStablePool.
283
+ Main difference to standard StablePool is scaling factors which includes rate.
284
+ This also applies to MetaStablePool.
285
+ */
286
+ getOnChainCalls(pool) {
287
+ const calls = [
288
+ {
289
+ target: this.vaultAddress,
290
+ callData: this.vaultInterface.encodeFunctionData('getPoolTokens', [
291
+ pool.id,
292
+ ]),
293
+ },
294
+ {
295
+ target: pool.address,
296
+ callData: this.poolInterface.encodeFunctionData('getSwapFeePercentage'),
297
+ },
298
+ {
299
+ target: pool.address,
300
+ callData: this.poolInterface.encodeFunctionData('getScalingFactors'),
301
+ },
302
+ {
303
+ target: pool.address,
304
+ callData: this.poolInterface.encodeFunctionData('getAmplificationParameter'),
305
+ },
306
+ ];
307
+ /**
308
+ * Returns the effective BPT supply.
309
+ * In other pools, this would be the same as `totalSupply`, but there are two key differences here:
310
+ * - this pool pre-mints BPT and holds it in the Vault as a token, and as such we need to subtract the Vault's
311
+ * balance to get the total "circulating supply". This is called the 'virtualSupply'.
312
+ * - the Pool owes debt to the Protocol in the form of unminted BPT, which will be minted immediately before the
313
+ * next join or exit. We need to take these into account since, even if they don't yet exist, they will
314
+ * effectively be included in any Pool operation that involves BPT.
315
+ * In the vast majority of cases, this function should be used instead of `totalSupply()`.
316
+ */
317
+ if (this.isComposable)
318
+ calls.push({
319
+ target: pool.address,
320
+ callData: this.poolInterface.encodeFunctionData('getActualSupply'),
321
+ });
322
+ return calls;
323
+ }
324
+ /*
325
+ Helper function to decodes multicall data for a PhantomStable Pool.
326
+ Main difference to standard StablePool is scaling factors which includes rate.
327
+ This also applies to MetaStablePool.
328
+ data must contain returnData
329
+ startIndex is where to start in returnData. Allows this decode function to be called along with other pool types.
330
+ */
331
+ decodeOnChainCalls(pool, data, startIndex) {
332
+ const pools = {};
333
+ const poolTokens = (0, utils_1.decodeThrowError)(this.vaultInterface, 'getPoolTokens', data[startIndex++], pool.address);
334
+ const swapFee = (0, utils_1.decodeThrowError)(this.poolInterface, 'getSwapFeePercentage', data[startIndex++], pool.address)[0];
335
+ const scalingFactors = (0, utils_1.decodeThrowError)(this.poolInterface, 'getScalingFactors', data[startIndex++], pool.address)[0];
336
+ const amp = (0, utils_1.decodeThrowError)(this.poolInterface, 'getAmplificationParameter', data[startIndex++], pool.address);
337
+ const tokens = poolTokens.tokens.map((address, idx) => ({
338
+ address: address.toLowerCase(),
339
+ balance: BigInt(poolTokens.balances[idx].toString()),
340
+ scalingFactor: BigInt(scalingFactors[idx].toString()),
341
+ }));
342
+ const poolState = {
343
+ swapFee: BigInt(swapFee.toString()),
344
+ tokens: (0, lodash_1.keyBy)(tokens, 'address'),
345
+ orderedTokens: poolTokens.tokens,
346
+ };
347
+ if (amp) {
348
+ poolState.amp = BigInt(amp.value.toString());
349
+ }
350
+ if (this.isComposable) {
351
+ const totalSupply = (0, utils_1.decodeThrowError)(this.poolInterface, 'getActualSupply', data[startIndex++], pool.address);
352
+ poolState.actualSupply = BigInt(totalSupply.toString());
353
+ }
354
+ pools[pool.address] = poolState;
355
+ return [pools, startIndex];
356
+ }
357
+ /*
358
+ For stable pools there is no Swap limit. As an approx - use almost the total balance of token out as we can add any amount of tokenIn and expect some back.
359
+ */
360
+ getSwapMaxAmount(poolPairData, side) {
361
+ return ((this._upscale(poolPairData.balances[poolPairData.indexOut], poolPairData.scalingFactors[poolPairData.indexOut]) *
362
+ 99n) /
363
+ 100n);
364
+ }
365
+ }
366
+ exports.PhantomStablePool = PhantomStablePool;
367
+ //# sourceMappingURL=PhantomStablePool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PhantomStablePool.js","sourceRoot":"","sources":["../../../../../src/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA+C;AAC/C,wDAAqD;AACrD,0DAA+C;AAC/C,uCAA8D;AAC9D,uEAAyD;AAGzD,8GAAkF;AAClF,8GAAwF;AACxF,mCAA+B;AAE/B,IAAK,SAIJ;AAJD,WAAK,SAAS;IACZ,qDAAU,CAAA;IACV,qDAAU,CAAA;IACV,yDAAY,CAAA;AACd,CAAC,EAJI,SAAS,KAAT,SAAS,QAIb;AAcD;;;;;;;;;;;GAWG;AACH,MAAa,iBAAkB,SAAQ,2BAAQ;IAU7C,YACE,YAAoB,EACpB,cAAyB,EACjB,eAAe,KAAK;QAE5B,KAAK,EAAE,CAAC;QAFA,iBAAY,GAAZ,YAAY,CAAQ;QAZ9B,mHAAmH;QACnH,gHAAgH;QAChH,iHAAiH;QACjH,oBAAoB;QACpB,sBAAiB,GAAG,qBAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,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ariant(amplificationParameter: bigint, balances: bigint[], roundUp: boolean): bigint;
4
+ static _calcInGivenOut(amplificationParameter: bigint, balances: bigint[], tokenIndexIn: number, tokenIndexOut: number, tokenAmountsOut: bigint[]): bigint[];
5
+ static _calcOutGivenIn(amplificationParameter: bigint, balances: bigint[], tokenIndexIn: number, tokenIndexOut: number, tokenAmountsIn: bigint[]): bigint[];
6
+ static _getTokenBalanceGivenInvariantAndAllOtherBalances(amplificationParameter: bigint, balances: bigint[], invariant: bigint, tokenIndex: number): bigint;
7
+ }
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StableMath = void 0;
4
+ const bigint_constants_1 = require("../../../../bigint-constants");
5
+ const balancer_v2_math_1 = require("../../balancer-v2-math");
6
+ class StableMath {
7
+ static _calculateInvariant(amplificationParameter, balances, roundUp) {
8
+ /**********************************************************************************************
9
+ // invariant //
10
+ // D = invariant D^(n+1) //
11
+ // A = amplification coefficient A n^n S + D = A D n^n + ----------- //
12
+ // S = sum of balances n^n P //
13
+ // P = product of balances //
14
+ // n = number of tokens //
15
+ *********x************************************************************************************/
16
+ // We support rounding up or down.
17
+ let sum = 0n;
18
+ const numTokens = balances.length;
19
+ for (let i = 0; i < numTokens; i++) {
20
+ sum = sum + balances[i];
21
+ }
22
+ if (sum == 0n) {
23
+ return 0n;
24
+ }
25
+ let prevInvariant = 0n;
26
+ let invariant = sum;
27
+ const ampTimesTotal = amplificationParameter * BigInt(numTokens);
28
+ for (let i = 0; i < 255; i++) {
29
+ let P_D = balances[0] * BigInt(numTokens);
30
+ for (let j = 1; j < numTokens; j++) {
31
+ P_D = balancer_v2_math_1.MathSol.div(balancer_v2_math_1.MathSol.mul(balancer_v2_math_1.MathSol.mul(P_D, balances[j]), BigInt(numTokens)), invariant, roundUp);
32
+ }
33
+ prevInvariant = invariant;
34
+ invariant = balancer_v2_math_1.MathSol.div(balancer_v2_math_1.MathSol.mul(balancer_v2_math_1.MathSol.mul(BigInt(numTokens), invariant), invariant) +
35
+ balancer_v2_math_1.MathSol.div(balancer_v2_math_1.MathSol.mul(balancer_v2_math_1.MathSol.mul(ampTimesTotal, sum), P_D), this._AMP_PRECISION, roundUp), balancer_v2_math_1.MathSol.mul(BigInt(numTokens + 1), invariant) +
36
+ // No need to use checked arithmetic for the amp precision, the amp is guaranteed to be at least 1
37
+ balancer_v2_math_1.MathSol.div(balancer_v2_math_1.MathSol.mul(ampTimesTotal - this._AMP_PRECISION, P_D), this._AMP_PRECISION, !roundUp), roundUp);
38
+ if (invariant > prevInvariant) {
39
+ if (invariant - prevInvariant <= 1) {
40
+ return invariant;
41
+ }
42
+ }
43
+ else if (prevInvariant - invariant <= 1) {
44
+ return invariant;
45
+ }
46
+ }
47
+ throw new Error('Errors.STABLE_INVARIANT_DIDNT_CONVERGE');
48
+ }
49
+ static _calcInGivenOut(amplificationParameter, balances, tokenIndexIn, tokenIndexOut, tokenAmountsOut) {
50
+ const invariant = this._calculateInvariant(amplificationParameter, balances, false);
51
+ return tokenAmountsOut.map(a => {
52
+ balances[tokenIndexOut] = balancer_v2_math_1.MathSol.sub(balances[tokenIndexOut], a);
53
+ const finalBalanceIn = this._getTokenBalanceGivenInvariantAndAllOtherBalances(amplificationParameter, balances, invariant, tokenIndexIn);
54
+ return balancer_v2_math_1.MathSol.add(balancer_v2_math_1.MathSol.sub(finalBalanceIn, balances[tokenIndexIn]), 1n);
55
+ });
56
+ }
57
+ ;
58
+ static _calcOutGivenIn(amplificationParameter, balances, tokenIndexIn, tokenIndexOut, tokenAmountsIn) {
59
+ // Amount out, so we round down overall.
60
+ // Given that we need to have a greater final balance out, the invariant needs to be rounded up
61
+ const invariant = this._calculateInvariant(amplificationParameter, balances, true);
62
+ const initBalance = balances[tokenIndexIn];
63
+ // Modification: The original code was implemented for a single tokenAmountsIn
64
+ return tokenAmountsIn.map(a => {
65
+ balances[tokenIndexIn] = initBalance + a;
66
+ const finalBalanceOut = this._getTokenBalanceGivenInvariantAndAllOtherBalances(amplificationParameter, balances, invariant, tokenIndexOut);
67
+ // No need to use checked arithmetic since `tokenAmountIn` was actually added to the same balance right before
68
+ // calling `_getTokenBalanceGivenInvariantAndAllOtherBalances` which doesn't alter the balances array.
69
+ // balances[tokenIndexIn] = balances[tokenIndexIn] - tokenAmountIn;
70
+ return balances[tokenIndexOut] - finalBalanceOut - 1n;
71
+ });
72
+ }
73
+ static _getTokenBalanceGivenInvariantAndAllOtherBalances(amplificationParameter, balances, invariant, tokenIndex) {
74
+ // Rounds result up overall
75
+ const ampTimesTotal = amplificationParameter * BigInt(balances.length);
76
+ let sum = balances[0];
77
+ let P_D = balances[0] * BigInt(balances.length);
78
+ for (let j = 1; j < balances.length; j++) {
79
+ P_D = balancer_v2_math_1.MathSol.divDown(balancer_v2_math_1.MathSol.mul(balancer_v2_math_1.MathSol.mul(P_D, balances[j]), BigInt(balances.length)), invariant);
80
+ sum = sum + balances[j];
81
+ }
82
+ // No need to use safe math, based on the loop above `sum` is greater than or equal to `balances[tokenIndex]`
83
+ sum = sum - balances[tokenIndex];
84
+ const inv2 = balancer_v2_math_1.MathSol.mul(invariant, invariant);
85
+ // We remove the balance fromm c by multiplying it
86
+ const c = balancer_v2_math_1.MathSol.mul(balancer_v2_math_1.MathSol.mul(balancer_v2_math_1.MathSol.divUp(inv2, balancer_v2_math_1.MathSol.mul(ampTimesTotal, P_D)), this._AMP_PRECISION), balances[tokenIndex]);
87
+ const b = sum +
88
+ balancer_v2_math_1.MathSol.mul(balancer_v2_math_1.MathSol.divDown(invariant, ampTimesTotal), this._AMP_PRECISION);
89
+ // We iterate to find the balance
90
+ let prevTokenBalance = 0n;
91
+ // We multiply the first iteration outside the loop with the invariant to set the value of the
92
+ // initial approximation.
93
+ let tokenBalance = balancer_v2_math_1.MathSol.divUp(inv2 + c, invariant + b);
94
+ for (let i = 0; i < 255; i++) {
95
+ prevTokenBalance = tokenBalance;
96
+ tokenBalance = balancer_v2_math_1.MathSol.divUp(balancer_v2_math_1.MathSol.mul(tokenBalance, tokenBalance) + c, balancer_v2_math_1.MathSol.mul(tokenBalance, 2n) + b - invariant);
97
+ if (tokenBalance > prevTokenBalance) {
98
+ if (tokenBalance - prevTokenBalance <= 1) {
99
+ return tokenBalance;
100
+ }
101
+ }
102
+ else if (prevTokenBalance - tokenBalance <= 1) {
103
+ return tokenBalance;
104
+ }
105
+ }
106
+ throw new Error('Errors.STABLE_GET_BALANCE_DIDNT_CONVERGE');
107
+ }
108
+ }
109
+ exports.StableMath = StableMath;
110
+ StableMath._AMP_PRECISION = bigint_constants_1.BI_POWS[3];
111
+ //# sourceMappingURL=StableMath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StableMath.js","sourceRoot":"","sources":["../../../../../src/dex/balancer-v2/pools/stable/StableMath.ts"],"names":[],"mappings":";;;AAAA,mEAAuD;AACvD,6DAAiD;AAEjD,MAAa,UAAU;IAGrB,MAAM,CAAC,mBAAmB,CACxB,sBAA8B,EAC9B,QAAkB,EAClB,OAAgB;QAEhB;;;;;;;wGAOgG;QAEhG,kCAAkC;QAClC,IAAI,GAAG,GAAG,EAAE,CAAC;QACb,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC;QAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,EAAE;YAClC,GAAG,GAAG,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;SACzB;QACD,IAAI,GAAG,IAAI,EAAE,EAAE;YACb,OAAO,EAAE,CAAC;SACX;QAED,IAAI,aAAa,GAAG,EAAE,CAAC;QACvB,IAAI,SAAS,GAAG,GAAG,CAAC;QACpB,MAAM,aAAa,GAAG,sBAAsB,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;QAEjE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;YAC5B,IAAI,GAAG,GAAG,QAAQ,CAAC,CA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,GAAG,CACT,0BAAO,CAAC,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC,EACzC,IAAI,CAAC,cAAc,CACpB,CAAC;QAEJ,iCAAiC;QACjC,IAAI,gBAAgB,GAAG,EAAE,CAAC;QAC1B,8FAA8F;QAC9F,yBAAyB;QACzB,IAAI,YAAY,GAAG,0BAAO,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC;QAE1D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;YAC5B,gBAAgB,GAAG,YAAY,CAAC;YAEhC,YAAY,GAAG,0BAAO,CAAC,KAAK,CAC1B,0BAAO,CAAC,GAAG,CAAC,YAAY,EAAE,YAAY,CAAC,GAAG,CAAC,EAC3C,0BAAO,CAAC,GAAG,CAAC,YAAY,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAC9C,CAAC;YAEF,IAAI,YAAY,GAAG,gBAAgB,EAAE;gBACnC,IAAI,YAAY,GAAG,gBAAgB,IAAI,CAAC,EAAE;oBACxC,OAAO,YAAY,CAAC;iBACrB;aACF;iBAAM,IAAI,gBAAgB,GAAG,YAAY,IAAI,CAAC,EAAE;gBAC/C,OAAO,YAAY,CAAC;aACrB;SACF;QAED,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;;AAvMH,gCAwMC;AAvMQ,yBAAc,GAAG,0BAAO,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { callData, PoolState, SubgraphPoolBase } from '../../types';
3
+ import { SwapSide } from '../../../../constants';
4
+ import { BaseGeneralPool } from '../balancer-v2-pool';
5
+ export declare type StablePoolPairData = {
6
+ balances: bigint[];
7
+ indexIn: number;
8
+ indexOut: number;
9
+ scalingFactors: bigint[];
10
+ swapFee: bigint;
11
+ amp: bigint;
12
+ };
13
+ export declare class StablePool extends BaseGeneralPool {
14
+ vaultAddress: string;
15
+ vaultInterface: Interface;
16
+ poolInterface: Interface;
17
+ metaPoolInterface: Interface;
18
+ constructor(vaultAddress: string, vaultInterface: Interface);
19
+ _onSwapGivenOut(tokenAmountsOut: bigint[], balances: bigint[], indexIn: number, indexOut: number, _amplificationParameter: bigint): bigint[];
20
+ _onSwapGivenIn(tokenAmountsIn: bigint[], balances: bigint[], indexIn: number, indexOut: number, _amplificationParameter: bigint): bigint[];
21
+ parsePoolPairData(pool: SubgraphPoolBase, poolState: PoolState, tokenIn: string, tokenOut: string): StablePoolPairData;
22
+ getOnChainCalls(pool: SubgraphPoolBase): callData[];
23
+ decodeOnChainCalls(pool: SubgraphPoolBase, data: {
24
+ success: boolean;
25
+ returnData: any;
26
+ }[], startIndex: number): [{
27
+ [address: string]: PoolState;
28
+ }, number];
29
+ getSwapMaxAmount(poolPairData: StablePoolPairData, side: SwapSide): bigint;
30
+ }