@uniswap/sdk-core 7.12.2 → 7.13.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.
- package/dist/{addresses.d.ts → cjs/src/addresses.d.ts} +58 -58
- package/dist/cjs/src/addresses.js +549 -0
- package/dist/cjs/src/addresses.js.map +1 -0
- package/dist/{chains.d.ts → cjs/src/chains.d.ts} +48 -48
- package/dist/cjs/src/chains.js +88 -0
- package/dist/cjs/src/chains.js.map +1 -0
- package/dist/{constants.d.ts → cjs/src/constants.d.ts} +12 -12
- package/dist/cjs/src/constants.js +18 -0
- package/dist/cjs/src/constants.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/baseCurrency.d.ts +49 -49
- package/dist/cjs/src/entities/baseCurrency.js +27 -0
- package/dist/cjs/src/entities/baseCurrency.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/currency.d.ts +3 -3
- package/dist/cjs/src/entities/currency.js +3 -0
- package/dist/cjs/src/entities/currency.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/ether.d.ts +13 -13
- package/dist/cjs/src/entities/ether.js +30 -0
- package/dist/cjs/src/entities/ether.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/fractions/currencyAmount.d.ts +31 -31
- package/dist/cjs/src/entities/fractions/currencyAmount.js +72 -0
- package/dist/cjs/src/entities/fractions/currencyAmount.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/fractions/fraction.d.ts +24 -24
- package/dist/cjs/src/entities/fractions/fraction.js +104 -0
- package/dist/cjs/src/entities/fractions/fraction.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/fractions/index.d.ts +4 -4
- package/dist/cjs/src/entities/fractions/index.js +12 -0
- package/dist/cjs/src/entities/fractions/index.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/fractions/percent.d.ts +14 -14
- package/dist/cjs/src/entities/fractions/percent.js +43 -0
- package/dist/cjs/src/entities/fractions/percent.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/fractions/price.d.ts +38 -38
- package/dist/cjs/src/entities/fractions/price.js +73 -0
- package/dist/cjs/src/entities/fractions/price.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/index.d.ts +6 -6
- package/dist/cjs/src/entities/index.js +10 -0
- package/dist/cjs/src/entities/index.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/nativeCurrency.d.ts +8 -8
- package/dist/cjs/src/entities/nativeCurrency.js +16 -0
- package/dist/cjs/src/entities/nativeCurrency.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/token.d.ts +48 -48
- package/dist/cjs/src/entities/token.js +69 -0
- package/dist/cjs/src/entities/token.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/weth9.d.ts +7 -7
- package/dist/cjs/src/entities/weth9.js +37 -0
- package/dist/cjs/src/entities/weth9.js.map +1 -0
- package/dist/{index.d.ts → cjs/src/index.d.ts} +5 -5
- package/dist/cjs/src/index.js +9 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/computePriceImpact.d.ts +8 -8
- package/dist/cjs/src/utils/computePriceImpact.js +18 -0
- package/dist/cjs/src/utils/computePriceImpact.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/computeZksyncCreate2Address.d.ts +2 -2
- package/dist/cjs/src/utils/computeZksyncCreate2Address.js +15 -0
- package/dist/cjs/src/utils/computeZksyncCreate2Address.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/index.d.ts +5 -5
- package/dist/cjs/src/utils/index.js +14 -0
- package/dist/cjs/src/utils/index.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/sortedInsert.d.ts +1 -1
- package/dist/cjs/src/utils/sortedInsert.js +38 -0
- package/dist/cjs/src/utils/sortedInsert.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/sqrt.d.ts +7 -7
- package/dist/cjs/src/utils/sqrt.js +32 -0
- package/dist/cjs/src/utils/sqrt.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/validateAndParseAddress.d.ts +10 -10
- package/dist/cjs/src/utils/validateAndParseAddress.js +31 -0
- package/dist/cjs/src/utils/validateAndParseAddress.js.map +1 -0
- package/dist/esm/src/addresses.d.ts +58 -0
- package/dist/esm/src/addresses.js +545 -0
- package/dist/esm/src/addresses.js.map +1 -0
- package/dist/esm/src/chains.d.ts +48 -0
- package/dist/esm/src/chains.js +85 -0
- package/dist/esm/src/chains.js.map +1 -0
- package/dist/esm/src/constants.d.ts +12 -0
- package/dist/esm/src/constants.js +14 -0
- package/dist/esm/src/constants.js.map +1 -0
- package/dist/esm/src/entities/baseCurrency.d.ts +49 -0
- package/dist/esm/src/entities/baseCurrency.js +22 -0
- package/dist/esm/src/entities/baseCurrency.js.map +1 -0
- package/dist/esm/src/entities/currency.d.ts +3 -0
- package/dist/esm/src/entities/currency.js +2 -0
- package/dist/esm/src/entities/currency.js.map +1 -0
- package/dist/esm/src/entities/ether.d.ts +13 -0
- package/dist/esm/src/entities/ether.js +25 -0
- package/dist/esm/src/entities/ether.js.map +1 -0
- package/dist/esm/src/entities/fractions/currencyAmount.d.ts +31 -0
- package/dist/esm/src/entities/fractions/currencyAmount.js +67 -0
- package/dist/esm/src/entities/fractions/currencyAmount.js.map +1 -0
- package/dist/esm/src/entities/fractions/fraction.d.ts +24 -0
- package/dist/esm/src/entities/fractions/fraction.js +99 -0
- package/dist/esm/src/entities/fractions/fraction.js.map +1 -0
- package/dist/esm/src/entities/fractions/index.d.ts +4 -0
- package/dist/esm/src/entities/fractions/index.js +5 -0
- package/dist/esm/src/entities/fractions/index.js.map +1 -0
- package/dist/esm/src/entities/fractions/percent.d.ts +14 -0
- package/dist/esm/src/entities/fractions/percent.js +38 -0
- package/dist/esm/src/entities/fractions/percent.js.map +1 -0
- package/dist/esm/src/entities/fractions/price.d.ts +38 -0
- package/dist/esm/src/entities/fractions/price.js +68 -0
- package/dist/esm/src/entities/fractions/price.js.map +1 -0
- package/dist/esm/src/entities/index.d.ts +6 -0
- package/dist/esm/src/entities/index.js +7 -0
- package/dist/esm/src/entities/index.js.map +1 -0
- package/dist/esm/src/entities/nativeCurrency.d.ts +8 -0
- package/dist/esm/src/entities/nativeCurrency.js +12 -0
- package/dist/esm/src/entities/nativeCurrency.js.map +1 -0
- package/dist/esm/src/entities/token.d.ts +48 -0
- package/dist/esm/src/entities/token.js +64 -0
- package/dist/esm/src/entities/token.js.map +1 -0
- package/dist/esm/src/entities/weth9.d.ts +7 -0
- package/dist/esm/src/entities/weth9.js +34 -0
- package/dist/esm/src/entities/weth9.js.map +1 -0
- package/dist/esm/src/index.d.ts +5 -0
- package/dist/esm/src/index.js +6 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/utils/computePriceImpact.d.ts +8 -0
- package/dist/esm/src/utils/computePriceImpact.js +14 -0
- package/dist/esm/src/utils/computePriceImpact.js.map +1 -0
- package/dist/esm/src/utils/computeZksyncCreate2Address.d.ts +2 -0
- package/dist/esm/src/utils/computeZksyncCreate2Address.js +11 -0
- package/dist/esm/src/utils/computeZksyncCreate2Address.js.map +1 -0
- package/dist/esm/src/utils/index.d.ts +5 -0
- package/dist/esm/src/utils/index.js +6 -0
- package/dist/esm/src/utils/index.js.map +1 -0
- package/dist/esm/src/utils/sortedInsert.d.ts +1 -0
- package/dist/esm/src/utils/sortedInsert.js +33 -0
- package/dist/esm/src/utils/sortedInsert.js.map +1 -0
- package/dist/esm/src/utils/sqrt.d.ts +7 -0
- package/dist/esm/src/utils/sqrt.js +27 -0
- package/dist/esm/src/utils/sqrt.js.map +1 -0
- package/dist/esm/src/utils/validateAndParseAddress.d.ts +10 -0
- package/dist/esm/src/utils/validateAndParseAddress.js +26 -0
- package/dist/esm/src/utils/validateAndParseAddress.js.map +1 -0
- package/dist/types/src/addresses.d.ts +58 -0
- package/dist/types/src/chains.d.ts +48 -0
- package/dist/types/src/constants.d.ts +12 -0
- package/dist/types/src/entities/baseCurrency.d.ts +49 -0
- package/dist/types/src/entities/currency.d.ts +3 -0
- package/dist/types/src/entities/ether.d.ts +13 -0
- package/dist/types/src/entities/fractions/currencyAmount.d.ts +31 -0
- package/dist/types/src/entities/fractions/fraction.d.ts +24 -0
- package/dist/types/src/entities/fractions/index.d.ts +4 -0
- package/dist/types/src/entities/fractions/percent.d.ts +14 -0
- package/dist/types/src/entities/fractions/price.d.ts +38 -0
- package/dist/types/src/entities/index.d.ts +6 -0
- package/dist/types/src/entities/nativeCurrency.d.ts +8 -0
- package/dist/types/src/entities/token.d.ts +48 -0
- package/dist/types/src/entities/weth9.d.ts +7 -0
- package/dist/types/src/index.d.ts +5 -0
- package/dist/types/src/utils/computePriceImpact.d.ts +8 -0
- package/dist/types/src/utils/computeZksyncCreate2Address.d.ts +2 -0
- package/dist/types/src/utils/index.d.ts +5 -0
- package/dist/types/src/utils/sortedInsert.d.ts +1 -0
- package/dist/types/src/utils/sqrt.d.ts +7 -0
- package/dist/types/src/utils/validateAndParseAddress.d.ts +10 -0
- package/package.json +21 -11
- package/dist/index.js +0 -8
- package/dist/sdk-core.cjs.development.js +0 -1185
- package/dist/sdk-core.cjs.development.js.map +0 -1
- package/dist/sdk-core.cjs.production.min.js +0 -2
- package/dist/sdk-core.cjs.production.min.js.map +0 -1
- package/dist/sdk-core.esm.js +0 -1146
- package/dist/sdk-core.esm.js.map +0 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import JSBI from 'jsbi';
|
|
2
|
+
import invariant from 'tiny-invariant';
|
|
3
|
+
import { Fraction } from './fraction';
|
|
4
|
+
import { CurrencyAmount } from './currencyAmount';
|
|
5
|
+
export class Price extends Fraction {
|
|
6
|
+
/**
|
|
7
|
+
* Construct a price, either with the base and quote currency amount, or the
|
|
8
|
+
* @param args
|
|
9
|
+
*/
|
|
10
|
+
constructor(...args) {
|
|
11
|
+
let baseCurrency, quoteCurrency, denominator, numerator;
|
|
12
|
+
if (args.length === 4) {
|
|
13
|
+
;
|
|
14
|
+
[baseCurrency, quoteCurrency, denominator, numerator] = args;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const result = args[0].quoteAmount.divide(args[0].baseAmount);
|
|
18
|
+
[baseCurrency, quoteCurrency, denominator, numerator] = [
|
|
19
|
+
args[0].baseAmount.currency,
|
|
20
|
+
args[0].quoteAmount.currency,
|
|
21
|
+
result.denominator,
|
|
22
|
+
result.numerator,
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
super(numerator, denominator);
|
|
26
|
+
this.baseCurrency = baseCurrency;
|
|
27
|
+
this.quoteCurrency = quoteCurrency;
|
|
28
|
+
this.scalar = new Fraction(JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(baseCurrency.decimals)), JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(quoteCurrency.decimals)));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Flip the price, switching the base and quote currency
|
|
32
|
+
*/
|
|
33
|
+
invert() {
|
|
34
|
+
return new Price(this.quoteCurrency, this.baseCurrency, this.numerator, this.denominator);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Multiply the price by another price, returning a new price. The other price must have the same base currency as this price's quote currency
|
|
38
|
+
* @param other the other price
|
|
39
|
+
*/
|
|
40
|
+
multiply(other) {
|
|
41
|
+
invariant(this.quoteCurrency.equals(other.baseCurrency), 'TOKEN');
|
|
42
|
+
const fraction = super.multiply(other);
|
|
43
|
+
return new Price(this.baseCurrency, other.quoteCurrency, fraction.denominator, fraction.numerator);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Return the amount of quote currency corresponding to a given amount of the base currency
|
|
47
|
+
* @param currencyAmount the amount of base currency to quote against the price
|
|
48
|
+
*/
|
|
49
|
+
quote(currencyAmount) {
|
|
50
|
+
invariant(currencyAmount.currency.equals(this.baseCurrency), 'TOKEN');
|
|
51
|
+
const result = super.multiply(currencyAmount);
|
|
52
|
+
return CurrencyAmount.fromFractionalAmount(this.quoteCurrency, result.numerator, result.denominator);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get the value scaled by decimals for formatting
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
get adjustedForDecimals() {
|
|
59
|
+
return super.multiply(this.scalar);
|
|
60
|
+
}
|
|
61
|
+
toSignificant(significantDigits = 6, format, rounding) {
|
|
62
|
+
return this.adjustedForDecimals.toSignificant(significantDigits, format, rounding);
|
|
63
|
+
}
|
|
64
|
+
toFixed(decimalPlaces = 4, format, rounding) {
|
|
65
|
+
return this.adjustedForDecimals.toFixed(decimalPlaces, format, rounding);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=price.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../../../../src/entities/fractions/price.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAItC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,MAAM,OAAO,KAAuD,SAAQ,QAAQ;IAKlF;;;OAGG;IACH,YACE,GAAG,IAE6E;QAEhF,IAAI,YAAmB,EAAE,aAAqB,EAAE,WAAsB,EAAE,SAAoB,CAAA;QAE5F,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YACrB,CAAC;YAAA,CAAC,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,CAAC,GAAG,IAAI,CAAA;SAC9D;aAAM;YACL,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAC5D;YAAA,CAAC,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,CAAC,GAAG;gBACvD,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ;gBAC3B,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CAAA;QACrE,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAA;QAC7C,OAAO,cAAc,CAAC,oBAAoB,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,CAAA;IACtG,CAAC;IAED;;;OAGG;IACH,IAAY,mBAAmB;QAC7B,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACpC,CAAC;IAEM,aAAa,CAAC,oBAA4B,CAAC,EAAE,MAAe,EAAE,QAAmB;QACtF,OAAO,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,iBAAiB,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;IACpF,CAAC;IAEM,OAAO,CAAC,gBAAwB,CAAC,EAAE,MAAe,EAAE,QAAmB;QAC5E,OAAO,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;IAC1E,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/entities/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAE3B,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseCurrency } from './baseCurrency';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the native currency of the chain on which it resides, e.g.
|
|
4
|
+
*/
|
|
5
|
+
export class NativeCurrency extends BaseCurrency {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.isNative = true;
|
|
9
|
+
this.isToken = false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=nativeCurrency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativeCurrency.js","sourceRoot":"","sources":["../../../../src/entities/nativeCurrency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C;;GAEG;AACH,MAAM,OAAgB,cAAe,SAAQ,YAAY;IAAzD;;QACkB,aAAQ,GAAS,IAAI,CAAA;QACrB,YAAO,GAAU,KAAK,CAAA;IACxC,CAAC;CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BigNumber } from '@ethersproject/bignumber';
|
|
2
|
+
import { BaseCurrency } from './baseCurrency';
|
|
3
|
+
import { Currency } from './currency';
|
|
4
|
+
/**
|
|
5
|
+
* Represents an ERC20 token with a unique address and some metadata.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Token extends BaseCurrency {
|
|
8
|
+
readonly isNative: false;
|
|
9
|
+
readonly isToken: true;
|
|
10
|
+
/**
|
|
11
|
+
* The contract address on the chain on which this token lives
|
|
12
|
+
*/
|
|
13
|
+
readonly address: string;
|
|
14
|
+
/**
|
|
15
|
+
* Relevant for fee-on-transfer (FOT) token taxes,
|
|
16
|
+
* Not every ERC20 token is FOT token, so this field is optional
|
|
17
|
+
*/
|
|
18
|
+
readonly buyFeeBps?: BigNumber;
|
|
19
|
+
readonly sellFeeBps?: BigNumber;
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param chainId {@link BaseCurrency#chainId}
|
|
23
|
+
* @param address The contract address on the chain on which this token lives
|
|
24
|
+
* @param decimals {@link BaseCurrency#decimals}
|
|
25
|
+
* @param symbol {@link BaseCurrency#symbol}
|
|
26
|
+
* @param name {@link BaseCurrency#name}
|
|
27
|
+
* @param bypassChecksum If true it only checks for length === 42, startsWith 0x and contains only hex characters
|
|
28
|
+
* @param buyFeeBps Buy fee tax for FOT tokens, in basis points
|
|
29
|
+
* @param sellFeeBps Sell fee tax for FOT tokens, in basis points
|
|
30
|
+
*/
|
|
31
|
+
constructor(chainId: number, address: string, decimals: number, symbol?: string, name?: string, bypassChecksum?: boolean, buyFeeBps?: BigNumber, sellFeeBps?: BigNumber);
|
|
32
|
+
/**
|
|
33
|
+
* Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
|
|
34
|
+
* @param other other token to compare
|
|
35
|
+
*/
|
|
36
|
+
equals(other: Currency): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Returns true if the address of this token sorts before the address of the other token
|
|
39
|
+
* @param other other token to compare
|
|
40
|
+
* @throws if the tokens have the same address
|
|
41
|
+
* @throws if the tokens are on different chains
|
|
42
|
+
*/
|
|
43
|
+
sortsBefore(other: Token): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Return this token, which does not need to be wrapped
|
|
46
|
+
*/
|
|
47
|
+
get wrapped(): Token;
|
|
48
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { BigNumber } from '@ethersproject/bignumber';
|
|
2
|
+
import invariant from 'tiny-invariant';
|
|
3
|
+
import { checkValidAddress, validateAndParseAddress } from '../utils/validateAndParseAddress';
|
|
4
|
+
import { BaseCurrency } from './baseCurrency';
|
|
5
|
+
/**
|
|
6
|
+
* Represents an ERC20 token with a unique address and some metadata.
|
|
7
|
+
*/
|
|
8
|
+
export class Token extends BaseCurrency {
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param chainId {@link BaseCurrency#chainId}
|
|
12
|
+
* @param address The contract address on the chain on which this token lives
|
|
13
|
+
* @param decimals {@link BaseCurrency#decimals}
|
|
14
|
+
* @param symbol {@link BaseCurrency#symbol}
|
|
15
|
+
* @param name {@link BaseCurrency#name}
|
|
16
|
+
* @param bypassChecksum If true it only checks for length === 42, startsWith 0x and contains only hex characters
|
|
17
|
+
* @param buyFeeBps Buy fee tax for FOT tokens, in basis points
|
|
18
|
+
* @param sellFeeBps Sell fee tax for FOT tokens, in basis points
|
|
19
|
+
*/
|
|
20
|
+
constructor(chainId, address, decimals, symbol, name, bypassChecksum, buyFeeBps, sellFeeBps) {
|
|
21
|
+
super(chainId, decimals, symbol, name);
|
|
22
|
+
this.isNative = false;
|
|
23
|
+
this.isToken = true;
|
|
24
|
+
if (bypassChecksum) {
|
|
25
|
+
this.address = checkValidAddress(address);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.address = validateAndParseAddress(address);
|
|
29
|
+
}
|
|
30
|
+
if (buyFeeBps) {
|
|
31
|
+
invariant(buyFeeBps.gte(BigNumber.from(0)), 'NON-NEGATIVE FOT FEES');
|
|
32
|
+
}
|
|
33
|
+
if (sellFeeBps) {
|
|
34
|
+
invariant(sellFeeBps.gte(BigNumber.from(0)), 'NON-NEGATIVE FOT FEES');
|
|
35
|
+
}
|
|
36
|
+
this.buyFeeBps = buyFeeBps;
|
|
37
|
+
this.sellFeeBps = sellFeeBps;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
|
|
41
|
+
* @param other other token to compare
|
|
42
|
+
*/
|
|
43
|
+
equals(other) {
|
|
44
|
+
return other.isToken && this.chainId === other.chainId && this.address.toLowerCase() === other.address.toLowerCase();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns true if the address of this token sorts before the address of the other token
|
|
48
|
+
* @param other other token to compare
|
|
49
|
+
* @throws if the tokens have the same address
|
|
50
|
+
* @throws if the tokens are on different chains
|
|
51
|
+
*/
|
|
52
|
+
sortsBefore(other) {
|
|
53
|
+
invariant(this.chainId === other.chainId, 'CHAIN_IDS');
|
|
54
|
+
invariant(this.address.toLowerCase() !== other.address.toLowerCase(), 'ADDRESSES');
|
|
55
|
+
return this.address.toLowerCase() < other.address.toLowerCase();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Return this token, which does not need to be wrapped
|
|
59
|
+
*/
|
|
60
|
+
get wrapped() {
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../../../src/entities/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC7F,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAG7C;;GAEG;AACH,MAAM,OAAO,KAAM,SAAQ,YAAY;IAgBrC;;;;;;;;;;OAUG;IACH,YACE,OAAe,EACf,OAAe,EACf,QAAgB,EAChB,MAAe,EACf,IAAa,EACb,cAAwB,EACxB,SAAqB,EACrB,UAAsB;QAEtB,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;QApCxB,aAAQ,GAAU,KAAK,CAAA;QACvB,YAAO,GAAS,IAAI,CAAA;QAoClC,IAAI,cAAc,EAAE;YAClB,IAAI,CAAC,OAAO,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAA;SAC1C;aAAM;YACL,IAAI,CAAC,OAAO,GAAG,uBAAuB,CAAC,OAAO,CAAC,CAAA;SAChD;QACD,IAAI,SAAS,EAAE;YACb,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAA;SACrE;QACD,IAAI,UAAU,EAAE;YACd,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAA;SACtE;QACD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,KAAe;QAC3B,OAAO,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,CAAA;IACtH,CAAC;IAED;;;;;OAKG;IACI,WAAW,CAAC,KAAY;QAC7B,SAAS,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;QACtD,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,WAAW,CAAC,CAAA;QAClF,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,CAAA;IACjE,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QAChB,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Token } from './token';
|
|
2
|
+
/**
|
|
3
|
+
* Known WETH9 implementation addresses, used in our implementation of Ether#wrapped
|
|
4
|
+
*/
|
|
5
|
+
export const WETH9 = {
|
|
6
|
+
1: new Token(1, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 18, 'WETH', 'Wrapped Ether'),
|
|
7
|
+
11155111: new Token(11155111, '0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14', 18, 'WETH', 'Wrapped Ether'),
|
|
8
|
+
3: new Token(3, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH', 'Wrapped Ether'),
|
|
9
|
+
4: new Token(4, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH', 'Wrapped Ether'),
|
|
10
|
+
5: new Token(5, '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', 18, 'WETH', 'Wrapped Ether'),
|
|
11
|
+
42: new Token(42, '0xd0A1E359811322d97991E03f863a0C30C2cF029C', 18, 'WETH', 'Wrapped Ether'),
|
|
12
|
+
10: new Token(10, '0x4200000000000000000000000000000000000006', 18, 'WETH', 'Wrapped Ether'),
|
|
13
|
+
69: new Token(69, '0x4200000000000000000000000000000000000006', 18, 'WETH', 'Wrapped Ether'),
|
|
14
|
+
11155420: new Token(11155420, '0x4200000000000000000000000000000000000006', 18, 'WETH', 'Wrapped Ether'),
|
|
15
|
+
42161: new Token(42161, '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', 18, 'WETH', 'Wrapped Ether'),
|
|
16
|
+
421611: new Token(421611, '0xB47e6A5f8b33b3F17603C83a0535A9dcD7E32681', 18, 'WETH', 'Wrapped Ether'),
|
|
17
|
+
421614: new Token(421614, '0x980B62Da83eFf3D4576C647993b0c1D7faf17c73', 18, 'WETH', 'Wrapped Ether'),
|
|
18
|
+
8453: new Token(8453, '0x4200000000000000000000000000000000000006', 18, 'WETH', 'Wrapped Ether'),
|
|
19
|
+
84532: new Token(84532, '0x4200000000000000000000000000000000000006', 18, 'WETH', 'Wrapped Ether'),
|
|
20
|
+
56: new Token(56, '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', 18, 'WBNB', 'Wrapped BNB'),
|
|
21
|
+
137: new Token(137, '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270', 18, 'WMATIC', 'Wrapped MATIC'),
|
|
22
|
+
43114: new Token(43114, '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7', 18, 'WAVAX', 'Wrapped AVAX'),
|
|
23
|
+
7777777: new Token(7777777, '0x4200000000000000000000000000000000000006', 18, 'WETH', 'Wrapped Ether'),
|
|
24
|
+
81457: new Token(81457, '0x4300000000000000000000000000000000000004', 18, 'WETH', 'Wrapped Ether'),
|
|
25
|
+
324: new Token(324, '0x5AEa5775959fBC2557Cc8789bC1bf90A239D9a91', 18, 'WETH', 'Wrapped Ether'),
|
|
26
|
+
480: new Token(480, '0x4200000000000000000000000000000000000006', 18, 'WETH', 'Wrapped Ether'),
|
|
27
|
+
1301: new Token(1301, '0x4200000000000000000000000000000000000006', 18, 'WETH', 'Wrapped Ether'),
|
|
28
|
+
130: new Token(130, '0x4200000000000000000000000000000000000006', 18, 'WETH', 'Wrapped Ether'),
|
|
29
|
+
10143: new Token(10143, '0x760AfE86e5de5fa0Ee542fc7B7B713e1c5425701', 18, 'WMON', 'Wrapped Monad'),
|
|
30
|
+
1868: new Token(1868, '0x4200000000000000000000000000000000000006', 18, 'WETH', 'Wrapped Ether'),
|
|
31
|
+
143: new Token(143, '0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A', 18, 'WMON', 'Wrapped Monad'),
|
|
32
|
+
59144: new Token(59144, '0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f', 18, 'WETH', 'Wrapped Ether'),
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=weth9.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weth9.js","sourceRoot":"","sources":["../../../../src/entities/weth9.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAiC;IACjD,CAAC,EAAE,IAAI,KAAK,CAAC,CAAC,EAAE,4CAA4C,EAAE,EAAE,EAAE,MAAM,EAAE,eAAe,CAAC;IAC1F,QAAQ,EAAE,IAAI,KAAK,CAAC,QAAQ,EAAE,4CAA4C,EAAE,EAAE,EAAE,MAAM,EAAE,eAAe,CAAC;IACxG,CAAC,EAAE,IAAI,KAAK,CAAC,CAAC,EAAE,4CAA4C,EAAE,EAAE,EAAE,MAAM,EAAE,eAAe,CAAC;IAC1F,CAAC,EAAE,IAAI,KAAK,CAAC,CAAC,EAAE,4CAA4C,EAAE,EAAE,EAAE,MAAM,EAAE,eAAe,CAAC;IAC1F,CAAC,EAAE,IAAI,KAAK,CAAC,CAAC,EAAE,4CAA4C,EAAE,EAAE,EAAE,M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 @@
|
|
|
1
|
+
import { Currency, CurrencyAmount, Percent, Price } from '../entities';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the percent difference between the mid price and the execution price, i.e. price impact.
|
|
4
|
+
* @param midPrice mid price before the trade
|
|
5
|
+
* @param inputAmount the input amount of the trade
|
|
6
|
+
* @param outputAmount the output amount of the trade
|
|
7
|
+
*/
|
|
8
|
+
export declare function computePriceImpact<TBase extends Currency, TQuote extends Currency>(midPrice: Price<TBase, TQuote>, inputAmount: CurrencyAmount<TBase>, outputAmount: CurrencyAmount<TQuote>): Percent;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Percent } from '../entities';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the percent difference between the mid price and the execution price, i.e. price impact.
|
|
4
|
+
* @param midPrice mid price before the trade
|
|
5
|
+
* @param inputAmount the input amount of the trade
|
|
6
|
+
* @param outputAmount the output amount of the trade
|
|
7
|
+
*/
|
|
8
|
+
export function computePriceImpact(midPrice, inputAmount, outputAmount) {
|
|
9
|
+
const quotedOutputAmount = midPrice.quote(inputAmount);
|
|
10
|
+
// calculate price impact := (exactQuote - outputAmount) / exactQuote
|
|
11
|
+
const priceImpact = quotedOutputAmount.subtract(outputAmount).divide(quotedOutputAmount);
|
|
12
|
+
return new Percent(priceImpact.numerator, priceImpact.denominator);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=computePriceImpact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computePriceImpact.js","sourceRoot":"","sources":["../../../../src/utils/computePriceImpact.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,OAAO,EAAS,MAAM,aAAa,CAAA;AAEtE;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAA8B,EAC9B,WAAkC,EAClC,YAAoC;IAEpC,MAAM,kBAAkB,GAAG,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;IACtD,qEAAqE;IACrE,MAAM,WAAW,GAAG,kBAAkB,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAA;IACxF,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,WAAW,CAAC,CAAA;AACpE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getAddress } from '@ethersproject/address';
|
|
2
|
+
import { concat, hexZeroPad } from '@ethersproject/bytes';
|
|
3
|
+
import { keccak256 } from '@ethersproject/keccak256';
|
|
4
|
+
import { toUtf8Bytes } from '@ethersproject/strings';
|
|
5
|
+
export function computeZksyncCreate2Address(sender, bytecodeHash, salt, input = '0x') {
|
|
6
|
+
const prefix = keccak256(toUtf8Bytes('zksyncCreate2'));
|
|
7
|
+
const inputHash = keccak256(input);
|
|
8
|
+
const addressBytes = keccak256(concat([prefix, hexZeroPad(sender, 32), salt, bytecodeHash, inputHash])).slice(26);
|
|
9
|
+
return getAddress(addressBytes);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=computeZksyncCreate2Address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computeZksyncCreate2Address.js","sourceRoot":"","sources":["../../../../src/utils/computeZksyncCreate2Address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAa,MAAM,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEpD,MAAM,UAAU,2BAA2B,CACzC,MAAc,EACd,YAAuB,EACvB,IAAe,EACf,QAAmB,IAAI;IAEvB,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,CAAA;IACtD,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;IAClC,MAAM,YAAY,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IACjH,OAAO,UAAU,CAAC,YAAY,CAAC,CAAA;AACjC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { computePriceImpact } from './computePriceImpact';
|
|
2
|
+
export { computeZksyncCreate2Address } from './computeZksyncCreate2Address';
|
|
3
|
+
export { sortedInsert } from './sortedInsert';
|
|
4
|
+
export { sqrt } from './sqrt';
|
|
5
|
+
export { validateAndParseAddress } from './validateAndParseAddress';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { computePriceImpact } from './computePriceImpact';
|
|
2
|
+
export { computeZksyncCreate2Address } from './computeZksyncCreate2Address';
|
|
3
|
+
export { sortedInsert } from './sortedInsert';
|
|
4
|
+
export { sqrt } from './sqrt';
|
|
5
|
+
export { validateAndParseAddress } from './validateAndParseAddress';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAA;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sortedInsert<T>(items: T[], add: T, maxSize: number, comparator: (a: T, b: T) => number): T | null;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import invariant from 'tiny-invariant';
|
|
2
|
+
// given an array of items sorted by `comparator`, insert an item into its sort index and constrain the size to
|
|
3
|
+
// `maxSize` by removing the last item
|
|
4
|
+
export function sortedInsert(items, add, maxSize, comparator) {
|
|
5
|
+
invariant(maxSize > 0, 'MAX_SIZE_ZERO');
|
|
6
|
+
// this is an invariant because the interface cannot return multiple removed items if items.length exceeds maxSize
|
|
7
|
+
invariant(items.length <= maxSize, 'ITEMS_SIZE');
|
|
8
|
+
// short circuit first item add
|
|
9
|
+
if (items.length === 0) {
|
|
10
|
+
items.push(add);
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
const isFull = items.length === maxSize;
|
|
15
|
+
// short circuit if full and the additional item does not come before the last item
|
|
16
|
+
if (isFull && comparator(items[items.length - 1], add) <= 0) {
|
|
17
|
+
return add;
|
|
18
|
+
}
|
|
19
|
+
let lo = 0, hi = items.length;
|
|
20
|
+
while (lo < hi) {
|
|
21
|
+
const mid = (lo + hi) >>> 1;
|
|
22
|
+
if (comparator(items[mid], add) <= 0) {
|
|
23
|
+
lo = mid + 1;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
hi = mid;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
items.splice(lo, 0, add);
|
|
30
|
+
return isFull ? items.pop() : null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=sortedInsert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortedInsert.js","sourceRoot":"","sources":["../../../../src/utils/sortedInsert.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAEtC,+GAA+G;AAC/G,sCAAsC;AACtC,MAAM,UAAU,YAAY,CAAI,KAAU,EAAE,GAAM,EAAE,OAAe,EAAE,UAAkC;IACrG,SAAS,CAAC,OAAO,GAAG,CAAC,EAAE,eAAe,CAAC,CAAA;IACvC,kHAAkH;IAClH,SAAS,CAAC,KAAK,CAAC,MAAM,IAAI,OAAO,EAAE,YAAY,CAAC,CAAA;IAEhD,+BAA+B;IAC/B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QACtB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACf,OAAO,IAAI,CAAA;KACZ;SAAM;QACL,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,KAAK,OAAO,CAAA;QACvC,mFAAmF;QACnF,IAAI,MAAM,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE;YAC3D,OAAO,GAAG,CAAA;SACX;QAED,IAAI,EAAE,GAAG,CAAC,EACR,EAAE,GAAG,KAAK,CAAC,MAAM,CAAA;QAEnB,OAAO,EAAE,GAAG,EAAE,EAAE;YACd,MAAM,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAA;YAC3B,IAAI,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE;gBACpC,EAAE,GAAG,GAAG,GAAG,CAAC,CAAA;aACb;iBAAM;gBACL,EAAE,GAAG,GAAG,CAAA;aACT;SACF;QACD,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA;QACxB,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAG,CAAC,CAAC,CAAC,IAAI,CAAA;KACpC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import JSBI from 'jsbi';
|
|
2
|
+
import invariant from 'tiny-invariant';
|
|
3
|
+
export const MAX_SAFE_INTEGER = JSBI.BigInt(Number.MAX_SAFE_INTEGER);
|
|
4
|
+
const ZERO = JSBI.BigInt(0);
|
|
5
|
+
const ONE = JSBI.BigInt(1);
|
|
6
|
+
const TWO = JSBI.BigInt(2);
|
|
7
|
+
/**
|
|
8
|
+
* Computes floor(sqrt(value))
|
|
9
|
+
* @param value the value for which to compute the square root, rounded down
|
|
10
|
+
*/
|
|
11
|
+
export function sqrt(value) {
|
|
12
|
+
invariant(JSBI.greaterThanOrEqual(value, ZERO), 'NEGATIVE');
|
|
13
|
+
// rely on built in sqrt if possible
|
|
14
|
+
if (JSBI.lessThan(value, MAX_SAFE_INTEGER)) {
|
|
15
|
+
return JSBI.BigInt(Math.floor(Math.sqrt(JSBI.toNumber(value))));
|
|
16
|
+
}
|
|
17
|
+
let z;
|
|
18
|
+
let x;
|
|
19
|
+
z = value;
|
|
20
|
+
x = JSBI.add(JSBI.divide(value, TWO), ONE);
|
|
21
|
+
while (JSBI.lessThan(x, z)) {
|
|
22
|
+
z = x;
|
|
23
|
+
x = JSBI.divide(JSBI.add(JSBI.divide(value, x), x), TWO);
|
|
24
|
+
}
|
|
25
|
+
return z;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=sqrt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqrt.js","sourceRoot":"","sources":["../../../../src/utils/sqrt.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAEtC,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;AAEpE,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AAE1B;;;GAGG;AACH,MAAM,UAAU,IAAI,CAAC,KAAW;IAC9B,SAAS,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,UAAU,CAAC,CAAA;IAE3D,oCAAoC;IACpC,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC,EAAE;QAC1C,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;KAChE;IAED,IAAI,CAAO,CAAA;IACX,IAAI,CAAO,CAAA;IACX,CAAC,GAAG,KAAK,CAAA;IACT,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAA;IAC1C,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;QAC1B,CAAC,GAAG,CAAC,CAAA;QACL,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;KACzD;IACD,OAAO,CAAC,CAAA;AACV,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates an address and returns the parsed (checksummed) version of that address
|
|
3
|
+
* @param address the unchecksummed hex address
|
|
4
|
+
*/
|
|
5
|
+
export declare function validateAndParseAddress(address: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Checks if an address is valid by checking 0x prefix, length === 42 and hex encoding.
|
|
8
|
+
* @param address the unchecksummed hex address
|
|
9
|
+
*/
|
|
10
|
+
export declare function checkValidAddress(address: string): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getAddress } from '@ethersproject/address';
|
|
2
|
+
/**
|
|
3
|
+
* Validates an address and returns the parsed (checksummed) version of that address
|
|
4
|
+
* @param address the unchecksummed hex address
|
|
5
|
+
*/
|
|
6
|
+
export function validateAndParseAddress(address) {
|
|
7
|
+
try {
|
|
8
|
+
return getAddress(address);
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
throw new Error(`${address} is not a valid address.`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
// Checks a string starts with 0x, is 42 characters long and contains only hex characters after 0x
|
|
15
|
+
const startsWith0xLen42HexRegex = /^0x[0-9a-fA-F]{40}$/;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if an address is valid by checking 0x prefix, length === 42 and hex encoding.
|
|
18
|
+
* @param address the unchecksummed hex address
|
|
19
|
+
*/
|
|
20
|
+
export function checkValidAddress(address) {
|
|
21
|
+
if (startsWith0xLen42HexRegex.test(address)) {
|
|
22
|
+
return address;
|
|
23
|
+
}
|
|
24
|
+
throw new Error(`${address} is not a valid address.`);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=validateAndParseAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateAndParseAddress.js","sourceRoot":"","sources":["../../../../src/utils/validateAndParseAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAEnD;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACrD,IAAI;QACF,OAAO,UAAU,CAAC,OAAO,CAAC,CAAA;KAC3B;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,0BAA0B,CAAC,CAAA;KACtD;AACH,CAAC;AAED,kGAAkG;AAClG,MAAM,yBAAyB,GAAG,qBAAqB,CAAA;AAEvD;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,IAAI,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;QAC3C,OAAO,OAAO,CAAA;KACf;IAED,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,0BAA0B,CAAC,CAAA;AACvD,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { SupportedChainsType } from './chains';
|
|
2
|
+
type AddressMap = {
|
|
3
|
+
[chainId: number]: string;
|
|
4
|
+
};
|
|
5
|
+
type ChainAddresses = {
|
|
6
|
+
v3CoreFactoryAddress: string;
|
|
7
|
+
multicallAddress: string;
|
|
8
|
+
quoterAddress: string;
|
|
9
|
+
v3MigratorAddress?: string;
|
|
10
|
+
nonfungiblePositionManagerAddress?: string;
|
|
11
|
+
tickLensAddress?: string;
|
|
12
|
+
swapRouter02Address?: string;
|
|
13
|
+
mixedRouteQuoterV1Address?: string;
|
|
14
|
+
mixedRouteQuoterV2Address?: string;
|
|
15
|
+
v4PoolManagerAddress?: string;
|
|
16
|
+
v4PositionManagerAddress?: string;
|
|
17
|
+
v4StateView?: string;
|
|
18
|
+
v4QuoterAddress?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const UNI_ADDRESSES: AddressMap;
|
|
21
|
+
export declare const UNISWAP_NFT_AIRDROP_CLAIM_ADDRESS = "0x8B799381ac40b838BBA4131ffB26197C432AFe78";
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated use V2_FACTORY_ADDRESSES instead
|
|
24
|
+
*/
|
|
25
|
+
export declare const V2_FACTORY_ADDRESS = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f";
|
|
26
|
+
export declare const V2_FACTORY_ADDRESSES: AddressMap;
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated use V2_ROUTER_ADDRESSES instead
|
|
29
|
+
*/
|
|
30
|
+
export declare const V2_ROUTER_ADDRESS = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D";
|
|
31
|
+
export declare const V2_ROUTER_ADDRESSES: AddressMap;
|
|
32
|
+
export declare const CHAIN_TO_ADDRESSES_MAP: Record<SupportedChainsType, ChainAddresses>;
|
|
33
|
+
export declare const V3_CORE_FACTORY_ADDRESSES: AddressMap;
|
|
34
|
+
export declare const V3_MIGRATOR_ADDRESSES: AddressMap;
|
|
35
|
+
export declare const MULTICALL_ADDRESSES: AddressMap;
|
|
36
|
+
/**
|
|
37
|
+
* The oldest V0 governance address
|
|
38
|
+
*/
|
|
39
|
+
export declare const GOVERNANCE_ALPHA_V0_ADDRESSES: AddressMap;
|
|
40
|
+
/**
|
|
41
|
+
* The older V1 governance address
|
|
42
|
+
*/
|
|
43
|
+
export declare const GOVERNANCE_ALPHA_V1_ADDRESSES: AddressMap;
|
|
44
|
+
/**
|
|
45
|
+
* The latest governor bravo that is currently admin of timelock
|
|
46
|
+
*/
|
|
47
|
+
export declare const GOVERNANCE_BRAVO_ADDRESSES: AddressMap;
|
|
48
|
+
export declare const TIMELOCK_ADDRESSES: AddressMap;
|
|
49
|
+
export declare const MERKLE_DISTRIBUTOR_ADDRESS: AddressMap;
|
|
50
|
+
export declare const ARGENT_WALLET_DETECTOR_ADDRESS: AddressMap;
|
|
51
|
+
export declare const QUOTER_ADDRESSES: AddressMap;
|
|
52
|
+
export declare const NONFUNGIBLE_POSITION_MANAGER_ADDRESSES: AddressMap;
|
|
53
|
+
export declare const ENS_REGISTRAR_ADDRESSES: AddressMap;
|
|
54
|
+
export declare const SOCKS_CONTROLLER_ADDRESSES: AddressMap;
|
|
55
|
+
export declare const TICK_LENS_ADDRESSES: AddressMap;
|
|
56
|
+
export declare const MIXED_ROUTE_QUOTER_V1_ADDRESSES: AddressMap;
|
|
57
|
+
export declare const SWAP_ROUTER_02_ADDRESSES: (chainId: number) => string;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare enum ChainId {
|
|
2
|
+
MAINNET = 1,
|
|
3
|
+
GOERLI = 5,
|
|
4
|
+
SEPOLIA = 11155111,
|
|
5
|
+
OPTIMISM = 10,
|
|
6
|
+
OPTIMISM_GOERLI = 420,
|
|
7
|
+
OPTIMISM_SEPOLIA = 11155420,
|
|
8
|
+
ARBITRUM_ONE = 42161,
|
|
9
|
+
ARBITRUM_GOERLI = 421613,
|
|
10
|
+
ARBITRUM_SEPOLIA = 421614,
|
|
11
|
+
POLYGON = 137,
|
|
12
|
+
POLYGON_MUMBAI = 80001,
|
|
13
|
+
CELO = 42220,
|
|
14
|
+
CELO_ALFAJORES = 44787,
|
|
15
|
+
GNOSIS = 100,
|
|
16
|
+
MOONBEAM = 1284,
|
|
17
|
+
BNB = 56,
|
|
18
|
+
AVALANCHE = 43114,
|
|
19
|
+
BASE_GOERLI = 84531,
|
|
20
|
+
BASE_SEPOLIA = 84532,
|
|
21
|
+
BASE = 8453,
|
|
22
|
+
ZORA = 7777777,
|
|
23
|
+
ZORA_SEPOLIA = 999999999,
|
|
24
|
+
ROOTSTOCK = 30,
|
|
25
|
+
BLAST = 81457,
|
|
26
|
+
ZKSYNC = 324,
|
|
27
|
+
WORLDCHAIN = 480,
|
|
28
|
+
UNICHAIN_SEPOLIA = 1301,
|
|
29
|
+
UNICHAIN = 130,
|
|
30
|
+
MONAD_TESTNET = 10143,
|
|
31
|
+
SONEIUM = 1868,
|
|
32
|
+
MONAD = 143,
|
|
33
|
+
XLAYER = 196,
|
|
34
|
+
LINEA = 59144,
|
|
35
|
+
TEMPO = 4217
|
|
36
|
+
}
|
|
37
|
+
export declare const SUPPORTED_CHAINS: readonly [ChainId.MAINNET, ChainId.OPTIMISM, ChainId.OPTIMISM_GOERLI, ChainId.OPTIMISM_SEPOLIA, ChainId.ARBITRUM_ONE, ChainId.ARBITRUM_GOERLI, ChainId.ARBITRUM_SEPOLIA, ChainId.POLYGON, ChainId.POLYGON_MUMBAI, ChainId.GOERLI, ChainId.SEPOLIA, ChainId.CELO_ALFAJORES, ChainId.CELO, ChainId.BNB, ChainId.AVALANCHE, ChainId.BASE, ChainId.BASE_GOERLI, ChainId.BASE_SEPOLIA, ChainId.ZORA, ChainId.ZORA_SEPOLIA, ChainId.ROOTSTOCK, ChainId.BLAST, ChainId.ZKSYNC, ChainId.WORLDCHAIN, ChainId.UNICHAIN_SEPOLIA, ChainId.UNICHAIN, ChainId.MONAD_TESTNET, ChainId.SONEIUM, ChainId.MONAD, ChainId.XLAYER, ChainId.LINEA, ChainId.TEMPO];
|
|
38
|
+
export type SupportedChainsType = (typeof SUPPORTED_CHAINS)[number];
|
|
39
|
+
export declare enum NativeCurrencyName {
|
|
40
|
+
ETHER = "ETH",
|
|
41
|
+
MATIC = "MATIC",
|
|
42
|
+
CELO = "CELO",
|
|
43
|
+
GNOSIS = "XDAI",
|
|
44
|
+
MOONBEAM = "GLMR",
|
|
45
|
+
BNB = "BNB",
|
|
46
|
+
AVAX = "AVAX",
|
|
47
|
+
ROOTSTOCK = "RBTC"
|
|
48
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import JSBI from 'jsbi';
|
|
2
|
+
export type BigintIsh = JSBI | string | number;
|
|
3
|
+
export declare enum TradeType {
|
|
4
|
+
EXACT_INPUT = 0,
|
|
5
|
+
EXACT_OUTPUT = 1
|
|
6
|
+
}
|
|
7
|
+
export declare enum Rounding {
|
|
8
|
+
ROUND_DOWN = 0,
|
|
9
|
+
ROUND_HALF_UP = 1,
|
|
10
|
+
ROUND_UP = 2
|
|
11
|
+
}
|
|
12
|
+
export declare const MaxUint256: JSBI;
|