@kittycorn-labs/v2-sdk 1.0.12 → 2.0.0

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 (74) hide show
  1. package/README.md +9 -0
  2. package/dist/{constants.d.ts → cjs/src/constants.d.ts} +19 -19
  3. package/dist/cjs/src/constants.js +23 -0
  4. package/dist/cjs/src/constants.js.map +1 -0
  5. package/dist/{entities → cjs/src/entities}/index.d.ts +3 -3
  6. package/dist/cjs/src/entities/index.js +7 -0
  7. package/dist/cjs/src/entities/index.js.map +1 -0
  8. package/dist/{entities → cjs/src/entities}/pair.d.ts +147 -147
  9. package/dist/cjs/src/entities/pair.js +318 -0
  10. package/dist/cjs/src/entities/pair.js.map +1 -0
  11. package/dist/{entities → cjs/src/entities}/route.d.ts +12 -12
  12. package/dist/cjs/src/entities/route.js +45 -0
  13. package/dist/cjs/src/entities/route.js.map +1 -0
  14. package/dist/{entities → cjs/src/entities}/trade.d.ts +103 -103
  15. package/dist/cjs/src/entities/trade.js +263 -0
  16. package/dist/cjs/src/entities/trade.js.map +1 -0
  17. package/dist/{errors.d.ts → cjs/src/errors.d.ts} +16 -16
  18. package/dist/cjs/src/errors.js +34 -0
  19. package/dist/cjs/src/errors.js.map +1 -0
  20. package/dist/{index.d.ts → cjs/src/index.d.ts} +4 -4
  21. package/dist/cjs/src/index.js +12 -0
  22. package/dist/cjs/src/index.js.map +1 -0
  23. package/dist/{router.d.ts → cjs/src/router.d.ts} +64 -64
  24. package/dist/cjs/src/router.js +94 -0
  25. package/dist/cjs/src/router.js.map +1 -0
  26. package/dist/esm/package.json +1 -0
  27. package/dist/esm/src/constants.d.ts +19 -0
  28. package/dist/esm/src/constants.js +19 -0
  29. package/dist/esm/src/constants.js.map +1 -0
  30. package/dist/esm/src/entities/index.d.ts +3 -0
  31. package/dist/esm/src/entities/index.js +4 -0
  32. package/dist/esm/src/entities/index.js.map +1 -0
  33. package/dist/esm/src/entities/pair.d.ts +147 -0
  34. package/dist/esm/src/entities/pair.js +312 -0
  35. package/dist/esm/src/entities/pair.js.map +1 -0
  36. package/dist/esm/src/entities/route.d.ts +12 -0
  37. package/dist/esm/src/entities/route.js +40 -0
  38. package/dist/esm/src/entities/route.js.map +1 -0
  39. package/dist/esm/src/entities/trade.d.ts +103 -0
  40. package/dist/esm/src/entities/trade.js +256 -0
  41. package/dist/esm/src/entities/trade.js.map +1 -0
  42. package/dist/esm/src/errors.d.ts +16 -0
  43. package/dist/esm/src/errors.js +29 -0
  44. package/dist/esm/src/errors.js.map +1 -0
  45. package/dist/esm/src/index.d.ts +4 -0
  46. package/dist/esm/src/index.js +5 -0
  47. package/dist/esm/src/index.js.map +1 -0
  48. package/dist/esm/src/router.d.ts +64 -0
  49. package/dist/esm/src/router.js +89 -0
  50. package/dist/esm/src/router.js.map +1 -0
  51. package/dist/types/src/constants.d.ts +20 -0
  52. package/dist/types/src/constants.d.ts.map +1 -0
  53. package/dist/types/src/entities/index.d.ts +4 -0
  54. package/dist/types/src/entities/index.d.ts.map +1 -0
  55. package/dist/types/src/entities/pair.d.ts +148 -0
  56. package/dist/types/src/entities/pair.d.ts.map +1 -0
  57. package/dist/types/src/entities/route.d.ts +13 -0
  58. package/dist/types/src/entities/route.d.ts.map +1 -0
  59. package/dist/types/src/entities/trade.d.ts +104 -0
  60. package/dist/types/src/entities/trade.d.ts.map +1 -0
  61. package/dist/types/src/errors.d.ts +17 -0
  62. package/dist/types/src/errors.d.ts.map +1 -0
  63. package/dist/types/src/index.d.ts +5 -0
  64. package/dist/types/src/index.d.ts.map +1 -0
  65. package/dist/types/src/router.d.ts +65 -0
  66. package/dist/types/src/router.d.ts.map +1 -0
  67. package/package.json +23 -34
  68. package/dist/index.js +0 -8
  69. package/dist/v2-sdk.cjs.development.js +0 -897
  70. package/dist/v2-sdk.cjs.development.js.map +0 -1
  71. package/dist/v2-sdk.cjs.production.min.js +0 -2
  72. package/dist/v2-sdk.cjs.production.min.js.map +0 -1
  73. package/dist/v2-sdk.esm.js +0 -880
  74. package/dist/v2-sdk.esm.js.map +0 -1
package/README.md CHANGED
@@ -1,3 +1,12 @@
1
+ > **Kittycorn / Ethers v5 dependency security**
2
+ > Applications combining these SDKs with Ethers v5 must put the following override in their root `package.json`, then run `npm install` and `npm audit`. npm does not inherit dependency-package overrides.
3
+ >
4
+ > ```json
5
+ > { "overrides": { "@ethersproject/providers": { "ws": "8.21.0" } } }
6
+ > ```
7
+ >
8
+ > Ethers v5 also retains an unpatched Low [elliptic advisory](https://github.com/advisories/GHSA-848j-6mx2-7j84). The Kittycorn integration builds quotes/calldata and uses external signers; it does not generate signatures from user private keys. This is a scope assessment, not a fix for elliptic.
9
+
1
10
  # Uniswap V2 SDK
2
11
 
3
12
  [![npm version](https://img.shields.io/npm/v/@uniswap/v2-sdk/latest.svg)](https://www.npmjs.com/package/@uniswap/v2-sdk/v/latest)
@@ -1,19 +1,19 @@
1
- import { Percent } from '@kittycorn-labs/sdk-core';
2
- import JSBI from 'jsbi';
3
- /**
4
- * @deprecated use FACTORY_ADDRESS_MAP instead
5
- */
6
- export declare const FACTORY_ADDRESS = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f";
7
- export declare const FACTORY_ADDRESS_MAP: {
8
- [chainId: number]: string;
9
- };
10
- export declare const INIT_CODE_HASH = "0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f";
11
- export declare const MINIMUM_LIQUIDITY: JSBI;
12
- export declare const ZERO: JSBI;
13
- export declare const ONE: JSBI;
14
- export declare const FIVE: JSBI;
15
- export declare const _997: JSBI;
16
- export declare const _1000: JSBI;
17
- export declare const BASIS_POINTS: JSBI;
18
- export declare const ZERO_PERCENT: Percent;
19
- export declare const ONE_HUNDRED_PERCENT: Percent;
1
+ import { Percent } from '@kittycorn-labs/sdk-core';
2
+ import JSBI from 'jsbi';
3
+ /**
4
+ * @deprecated use FACTORY_ADDRESS_MAP instead
5
+ */
6
+ export declare const FACTORY_ADDRESS = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f";
7
+ export declare const FACTORY_ADDRESS_MAP: {
8
+ [chainId: number]: string;
9
+ };
10
+ export declare const INIT_CODE_HASH = "0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f";
11
+ export declare const MINIMUM_LIQUIDITY: JSBI;
12
+ export declare const ZERO: JSBI;
13
+ export declare const ONE: JSBI;
14
+ export declare const FIVE: JSBI;
15
+ export declare const _997: JSBI;
16
+ export declare const _1000: JSBI;
17
+ export declare const BASIS_POINTS: JSBI;
18
+ export declare const ZERO_PERCENT: Percent;
19
+ export declare const ONE_HUNDRED_PERCENT: Percent;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ONE_HUNDRED_PERCENT = exports.ZERO_PERCENT = exports.BASIS_POINTS = exports._1000 = exports._997 = exports.FIVE = exports.ONE = exports.ZERO = exports.MINIMUM_LIQUIDITY = exports.INIT_CODE_HASH = exports.FACTORY_ADDRESS_MAP = exports.FACTORY_ADDRESS = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const sdk_core_1 = require("@kittycorn-labs/sdk-core");
6
+ const jsbi_1 = tslib_1.__importDefault(require("jsbi"));
7
+ /**
8
+ * @deprecated use FACTORY_ADDRESS_MAP instead
9
+ */
10
+ exports.FACTORY_ADDRESS = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f';
11
+ exports.FACTORY_ADDRESS_MAP = sdk_core_1.V2_FACTORY_ADDRESSES;
12
+ exports.INIT_CODE_HASH = '0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f';
13
+ exports.MINIMUM_LIQUIDITY = jsbi_1.default.BigInt(1000);
14
+ // exports for internal consumption
15
+ exports.ZERO = jsbi_1.default.BigInt(0);
16
+ exports.ONE = jsbi_1.default.BigInt(1);
17
+ exports.FIVE = jsbi_1.default.BigInt(5);
18
+ exports._997 = jsbi_1.default.BigInt(997);
19
+ exports._1000 = jsbi_1.default.BigInt(1000);
20
+ exports.BASIS_POINTS = jsbi_1.default.BigInt(10000);
21
+ exports.ZERO_PERCENT = new sdk_core_1.Percent(exports.ZERO);
22
+ exports.ONE_HUNDRED_PERCENT = new sdk_core_1.Percent(exports.ONE);
23
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":";;;;AAAA,uDAAwE;AACxE,wDAAuB;AAEvB;;GAEG;AACU,QAAA,eAAe,GAAG,4CAA4C,CAAA;AAE9D,QAAA,mBAAmB,GAAkC,+BAAoB,CAAA;AAEzE,QAAA,cAAc,GAAG,oEAAoE,CAAA;AAErF,QAAA,iBAAiB,GAAG,cAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAElD,mCAAmC;AACtB,QAAA,IAAI,GAAG,cAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AACrB,QAAA,GAAG,GAAG,cAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AACpB,QAAA,IAAI,GAAG,cAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AACrB,QAAA,IAAI,GAAG,cAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AACvB,QAAA,KAAK,GAAG,cAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AACzB,QAAA,YAAY,GAAG,cAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAEjC,QAAA,YAAY,GAAG,IAAI,kBAAO,CAAC,YAAI,CAAC,CAAA;AAChC,QAAA,mBAAmB,GAAG,IAAI,kBAAO,CAAC,WAAG,CAAC,CAAA"}
@@ -1,3 +1,3 @@
1
- export * from './pair';
2
- export * from './route';
3
- export * from './trade';
1
+ export * from './pair';
2
+ export * from './route';
3
+ export * from './trade';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./pair"), exports);
5
+ tslib_1.__exportStar(require("./route"), exports);
6
+ tslib_1.__exportStar(require("./trade"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/entities/index.ts"],"names":[],"mappings":";;;AAAA,iDAAsB;AACtB,kDAAuB;AACvB,kDAAuB"}
@@ -1,147 +1,147 @@
1
- import { BigintIsh, CurrencyAmount, Price, Token } from '@kittycorn-labs/sdk-core';
2
- export declare const computePairAddress: ({ factoryAddress, tokenA, tokenB, }: {
3
- factoryAddress: string;
4
- tokenA: Token;
5
- tokenB: Token;
6
- }) => string;
7
- export declare class Pair {
8
- readonly liquidityToken: Token;
9
- private readonly tokenAmounts;
10
- static getAddress(tokenA: Token, tokenB: Token): string;
11
- constructor(currencyAmountA: CurrencyAmount<Token>, tokenAmountB: CurrencyAmount<Token>);
12
- /**
13
- * Returns true if the token is either token0 or token1
14
- * @param token to check
15
- */
16
- involvesToken(token: Token): boolean;
17
- /**
18
- * Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0
19
- */
20
- get token0Price(): Price<Token, Token>;
21
- /**
22
- * Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1
23
- */
24
- get token1Price(): Price<Token, Token>;
25
- /**
26
- * Return the price of the given token in terms of the other token in the pair.
27
- * @param token token to return price of
28
- */
29
- priceOf(token: Token): Price<Token, Token>;
30
- /**
31
- * Returns the chain ID of the tokens in the pair.
32
- */
33
- get chainId(): number;
34
- get token0(): Token;
35
- get token1(): Token;
36
- get reserve0(): CurrencyAmount<Token>;
37
- get reserve1(): CurrencyAmount<Token>;
38
- reserveOf(token: Token): CurrencyAmount<Token>;
39
- /**
40
- * getAmountOut is the linear algebra of reserve ratio against amountIn:amountOut.
41
- * https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000
42
- * has the math deduction for the reserve calculation without fee-on-transfer fees.
43
- *
44
- * With fee-on-transfer tax, intuitively it's just:
45
- * inputAmountWithFeeAndTax = 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
46
- * = (1 - amountIn.sellFeesBips / 10000) * amountInWithFee
47
- * where amountInWithFee is the amountIn after taking out the LP fees
48
- * outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)
49
- *
50
- * But we are illustrating the math deduction below to ensure that's the case.
51
- *
52
- * before swap A * B = K where A = reserveIn B = reserveOut
53
- *
54
- * after swap A' * B' = K where only k is a constant value
55
- *
56
- * getAmountOut
57
- *
58
- * A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted
59
- * B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000)
60
- * amountOut = (B - B') / (1 - amountOut.buyFeesBips / 10000) # where A' * B' still is k
61
- * = (B - K/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
62
- * /
63
- * (1 - amountOut.buyFeesBips / 10000)
64
- * = (B - AB/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
65
- * /
66
- * (1 - amountOut.buyFeesBips / 10000)
67
- * = ((BA + B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn - AB)/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
68
- * /
69
- * (1 - amountOut.buyFeesBips / 10000)
70
- * = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn / (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
71
- * /
72
- * (1 - amountOut.buyFeesBips / 10000)
73
- * amountOut * (1 - amountOut.buyFeesBips / 10000) = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
74
- * /
75
- * (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
76
- *
77
- * outputAmountWithTax = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
78
- * /
79
- * (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
80
- * = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn * 1000
81
- * /
82
- * ((A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn) * 1000)
83
- * = (B * (1 - amountIn.sellFeesBips / 10000) 997 * * amountIn
84
- * /
85
- * (1000 * A + (1 - amountIn.sellFeesBips / 10000) * 997 * amountIn)
86
- * = (B * (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee)
87
- * /
88
- * (1000 * A + (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee)
89
- * = (B * inputAmountWithFeeAndTax)
90
- * /
91
- * (1000 * A + inputAmountWithFeeAndTax)
92
- *
93
- * inputAmountWithFeeAndTax = (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee
94
- * outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)
95
- *
96
- * @param inputAmount
97
- * @param calculateFotFees
98
- */
99
- getOutputAmount(inputAmount: CurrencyAmount<Token>, calculateFotFees?: boolean): [CurrencyAmount<Token>, Pair];
100
- /**
101
- * getAmountIn is the linear algebra of reserve ratio against amountIn:amountOut.
102
- * https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000
103
- * has the math deduction for the reserve calculation without fee-on-transfer fees.
104
- *
105
- * With fee-on-transfer fees, intuitively it's just:
106
- * outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000)
107
- * inputAmountWithTax = amountIn / (1 - amountIn.sellFeesBips / 10000) / 0.997
108
- *
109
- * But we are illustrating the math deduction below to ensure that's the case.
110
- *
111
- * before swap A * B = K where A = reserveIn B = reserveOut
112
- *
113
- * after swap A' * B' = K where only k is a constant value
114
- *
115
- * getAmountIn
116
- *
117
- * B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000)
118
- * A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted
119
- * amountIn = (A' - A) / (0.997 * (1 - amountIn.sellFeesBips / 10000))
120
- * = (K / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A)
121
- * /
122
- * (0.997 * (1 - amountIn.sellFeesBips / 10000))
123
- * = (AB / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A)
124
- * /
125
- * (0.997 * (1 - amountIn.sellFeesBips / 10000))
126
- * = ((AB - AB + A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
127
- * /
128
- * (0.997 * (1 - amountIn.sellFeesBips / 10000))
129
- * = ((A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
130
- * /
131
- * (0.997 * (1 - amountIn.sellFeesBips / 10000))
132
- * = ((A * 1000 * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
133
- * /
134
- * (997 * (1 - amountIn.sellFeesBips / 10000))
135
- *
136
- * outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000)
137
- * inputAmountWithTax = amountIn / (997 * (1 - amountIn.sellFeesBips / 10000))
138
- * = (A * outputAmountWithTax * 1000) / ((B - outputAmountWithTax) * 997)
139
- *
140
- * @param outputAmount
141
- */
142
- getInputAmount(outputAmount: CurrencyAmount<Token>, calculateFotFees?: boolean): [CurrencyAmount<Token>, Pair];
143
- getLiquidityMinted(totalSupply: CurrencyAmount<Token>, tokenAmountA: CurrencyAmount<Token>, tokenAmountB: CurrencyAmount<Token>): CurrencyAmount<Token>;
144
- getLiquidityValue(token: Token, totalSupply: CurrencyAmount<Token>, liquidity: CurrencyAmount<Token>, feeOn?: boolean, kLast?: BigintIsh): CurrencyAmount<Token>;
145
- private derivePercentAfterSellFees;
146
- private derivePercentAfterBuyFees;
147
- }
1
+ import { BigintIsh, CurrencyAmount, Price, Token } from '@kittycorn-labs/sdk-core';
2
+ export declare const computePairAddress: ({ factoryAddress, tokenA, tokenB, }: {
3
+ factoryAddress: string;
4
+ tokenA: Token;
5
+ tokenB: Token;
6
+ }) => string;
7
+ export declare class Pair {
8
+ readonly liquidityToken: Token;
9
+ private readonly tokenAmounts;
10
+ static getAddress(tokenA: Token, tokenB: Token): string;
11
+ constructor(currencyAmountA: CurrencyAmount<Token>, tokenAmountB: CurrencyAmount<Token>);
12
+ /**
13
+ * Returns true if the token is either token0 or token1
14
+ * @param token to check
15
+ */
16
+ involvesToken(token: Token): boolean;
17
+ /**
18
+ * Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0
19
+ */
20
+ get token0Price(): Price<Token, Token>;
21
+ /**
22
+ * Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1
23
+ */
24
+ get token1Price(): Price<Token, Token>;
25
+ /**
26
+ * Return the price of the given token in terms of the other token in the pair.
27
+ * @param token token to return price of
28
+ */
29
+ priceOf(token: Token): Price<Token, Token>;
30
+ /**
31
+ * Returns the chain ID of the tokens in the pair.
32
+ */
33
+ get chainId(): number;
34
+ get token0(): Token;
35
+ get token1(): Token;
36
+ get reserve0(): CurrencyAmount<Token>;
37
+ get reserve1(): CurrencyAmount<Token>;
38
+ reserveOf(token: Token): CurrencyAmount<Token>;
39
+ /**
40
+ * getAmountOut is the linear algebra of reserve ratio against amountIn:amountOut.
41
+ * https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000
42
+ * has the math deduction for the reserve calculation without fee-on-transfer fees.
43
+ *
44
+ * With fee-on-transfer tax, intuitively it's just:
45
+ * inputAmountWithFeeAndTax = 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
46
+ * = (1 - amountIn.sellFeesBips / 10000) * amountInWithFee
47
+ * where amountInWithFee is the amountIn after taking out the LP fees
48
+ * outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)
49
+ *
50
+ * But we are illustrating the math deduction below to ensure that's the case.
51
+ *
52
+ * before swap A * B = K where A = reserveIn B = reserveOut
53
+ *
54
+ * after swap A' * B' = K where only k is a constant value
55
+ *
56
+ * getAmountOut
57
+ *
58
+ * A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted
59
+ * B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000)
60
+ * amountOut = (B - B') / (1 - amountOut.buyFeesBips / 10000) # where A' * B' still is k
61
+ * = (B - K/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
62
+ * /
63
+ * (1 - amountOut.buyFeesBips / 10000)
64
+ * = (B - AB/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
65
+ * /
66
+ * (1 - amountOut.buyFeesBips / 10000)
67
+ * = ((BA + B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn - AB)/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
68
+ * /
69
+ * (1 - amountOut.buyFeesBips / 10000)
70
+ * = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn / (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
71
+ * /
72
+ * (1 - amountOut.buyFeesBips / 10000)
73
+ * amountOut * (1 - amountOut.buyFeesBips / 10000) = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
74
+ * /
75
+ * (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
76
+ *
77
+ * outputAmountWithTax = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
78
+ * /
79
+ * (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
80
+ * = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn * 1000
81
+ * /
82
+ * ((A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn) * 1000)
83
+ * = (B * (1 - amountIn.sellFeesBips / 10000) 997 * * amountIn
84
+ * /
85
+ * (1000 * A + (1 - amountIn.sellFeesBips / 10000) * 997 * amountIn)
86
+ * = (B * (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee)
87
+ * /
88
+ * (1000 * A + (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee)
89
+ * = (B * inputAmountWithFeeAndTax)
90
+ * /
91
+ * (1000 * A + inputAmountWithFeeAndTax)
92
+ *
93
+ * inputAmountWithFeeAndTax = (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee
94
+ * outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)
95
+ *
96
+ * @param inputAmount
97
+ * @param calculateFotFees
98
+ */
99
+ getOutputAmount(inputAmount: CurrencyAmount<Token>, calculateFotFees?: boolean): [CurrencyAmount<Token>, Pair];
100
+ /**
101
+ * getAmountIn is the linear algebra of reserve ratio against amountIn:amountOut.
102
+ * https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000
103
+ * has the math deduction for the reserve calculation without fee-on-transfer fees.
104
+ *
105
+ * With fee-on-transfer fees, intuitively it's just:
106
+ * outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000)
107
+ * inputAmountWithTax = amountIn / (1 - amountIn.sellFeesBips / 10000) / 0.997
108
+ *
109
+ * But we are illustrating the math deduction below to ensure that's the case.
110
+ *
111
+ * before swap A * B = K where A = reserveIn B = reserveOut
112
+ *
113
+ * after swap A' * B' = K where only k is a constant value
114
+ *
115
+ * getAmountIn
116
+ *
117
+ * B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000)
118
+ * A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted
119
+ * amountIn = (A' - A) / (0.997 * (1 - amountIn.sellFeesBips / 10000))
120
+ * = (K / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A)
121
+ * /
122
+ * (0.997 * (1 - amountIn.sellFeesBips / 10000))
123
+ * = (AB / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A)
124
+ * /
125
+ * (0.997 * (1 - amountIn.sellFeesBips / 10000))
126
+ * = ((AB - AB + A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
127
+ * /
128
+ * (0.997 * (1 - amountIn.sellFeesBips / 10000))
129
+ * = ((A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
130
+ * /
131
+ * (0.997 * (1 - amountIn.sellFeesBips / 10000))
132
+ * = ((A * 1000 * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
133
+ * /
134
+ * (997 * (1 - amountIn.sellFeesBips / 10000))
135
+ *
136
+ * outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000)
137
+ * inputAmountWithTax = amountIn / (997 * (1 - amountIn.sellFeesBips / 10000))
138
+ * = (A * outputAmountWithTax * 1000) / ((B - outputAmountWithTax) * 997)
139
+ *
140
+ * @param outputAmount
141
+ */
142
+ getInputAmount(outputAmount: CurrencyAmount<Token>, calculateFotFees?: boolean): [CurrencyAmount<Token>, Pair];
143
+ getLiquidityMinted(totalSupply: CurrencyAmount<Token>, tokenAmountA: CurrencyAmount<Token>, tokenAmountB: CurrencyAmount<Token>): CurrencyAmount<Token>;
144
+ getLiquidityValue(token: Token, totalSupply: CurrencyAmount<Token>, liquidity: CurrencyAmount<Token>, feeOn?: boolean, kLast?: BigintIsh): CurrencyAmount<Token>;
145
+ private derivePercentAfterSellFees;
146
+ private derivePercentAfterBuyFees;
147
+ }