@orbs-network/twap 1.5.5 → 1.5.7
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/src/configs.d.ts +38 -0
- package/dist/src/configs.js +9 -1
- package/dist/src/lib.d.ts +2 -2
- package/dist/src/lib.js +5 -5
- package/dist/src/paraswap.js +3 -1
- package/package.json +1 -1
package/dist/src/configs.d.ts
CHANGED
|
@@ -20,3 +20,41 @@ export declare const QuickSwapConfig: Config;
|
|
|
20
20
|
export declare const SpiritSwapConfig: Config;
|
|
21
21
|
export declare const SpookySwapConfig: Config;
|
|
22
22
|
export declare const nativeTokenAddresses: string[];
|
|
23
|
+
export declare const isNativeAddress: (address: string) => boolean;
|
|
24
|
+
export declare const chainConfig: (chainId: number) => {
|
|
25
|
+
chainId: number;
|
|
26
|
+
twapAddress: string;
|
|
27
|
+
lensAddress: string;
|
|
28
|
+
bidDelaySeconds: number;
|
|
29
|
+
minChunkSizeUsd: number;
|
|
30
|
+
wToken: {
|
|
31
|
+
address: string;
|
|
32
|
+
decimals: number;
|
|
33
|
+
symbol: string;
|
|
34
|
+
logoUrl: string;
|
|
35
|
+
};
|
|
36
|
+
} | {
|
|
37
|
+
chainId: number;
|
|
38
|
+
twapAddress: string;
|
|
39
|
+
lensAddress: string;
|
|
40
|
+
bidDelaySeconds: number;
|
|
41
|
+
minChunkSizeUsd: number;
|
|
42
|
+
wToken: {
|
|
43
|
+
address: string;
|
|
44
|
+
decimals: number;
|
|
45
|
+
symbol: string;
|
|
46
|
+
logoUrl: string;
|
|
47
|
+
};
|
|
48
|
+
} | {
|
|
49
|
+
chainId: number;
|
|
50
|
+
twapAddress: string;
|
|
51
|
+
lensAddress: string;
|
|
52
|
+
bidDelaySeconds: number;
|
|
53
|
+
minChunkSizeUsd: number;
|
|
54
|
+
wToken: {
|
|
55
|
+
address: string;
|
|
56
|
+
decimals: number;
|
|
57
|
+
symbol: string;
|
|
58
|
+
logoUrl: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
package/dist/src/configs.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.nativeTokenAddresses = exports.SpookySwapConfig = exports.SpiritSwapConfig = exports.QuickSwapConfig = exports.SushiSwapConfig = exports.UniswapV2Config = void 0;
|
|
6
|
+
exports.chainConfig = exports.isNativeAddress = exports.nativeTokenAddresses = exports.SpookySwapConfig = exports.SpiritSwapConfig = exports.QuickSwapConfig = exports.SushiSwapConfig = exports.UniswapV2Config = void 0;
|
|
4
7
|
const web3_candies_1 = require("@defi.org/web3-candies");
|
|
8
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
5
9
|
const ChainConfigs = {
|
|
6
10
|
eth: {
|
|
7
11
|
chainId: 1,
|
|
@@ -53,3 +57,7 @@ exports.nativeTokenAddresses = [
|
|
|
53
57
|
"0x0000000000000000000000000000000000001010",
|
|
54
58
|
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
|
55
59
|
];
|
|
60
|
+
const isNativeAddress = (address) => !!lodash_1.default.find(exports.nativeTokenAddresses, (a) => (0, web3_candies_1.eqIgnoreCase)(a, address));
|
|
61
|
+
exports.isNativeAddress = isNativeAddress;
|
|
62
|
+
const chainConfig = (chainId) => lodash_1.default.find(ChainConfigs, (c) => c.chainId === chainId);
|
|
63
|
+
exports.chainConfig = chainConfig;
|
package/dist/src/lib.d.ts
CHANGED
|
@@ -16,8 +16,8 @@ export declare class TWAPLib {
|
|
|
16
16
|
isValidChain: (chainId: number) => boolean;
|
|
17
17
|
maxPossibleChunks: (srcToken: TokenData, srcAmount: BN.Value, srcUsd: BN.Value) => number;
|
|
18
18
|
srcChunkAmount: (srcAmount: BN.Value, totalChunks: BN.Value) => BN;
|
|
19
|
-
totalChunks: (srcAmount: BN.Value, srcChunkAmount: BN.Value) =>
|
|
20
|
-
fillDelayMillis: (totalChunks: BN.Value, maxDurationMillis: BN.Value) =>
|
|
19
|
+
totalChunks: (srcAmount: BN.Value, srcChunkAmount: BN.Value) => number;
|
|
20
|
+
fillDelayMillis: (totalChunks: BN.Value, maxDurationMillis: BN.Value) => number;
|
|
21
21
|
dstMinAmountOut: (srcToken: TokenData, dstToken: TokenData, srcChunkAmount: BN.Value, limitDstPriceFor1Src: BN.Value, isMarketOrder: boolean) => BN;
|
|
22
22
|
isMarketOrder: (order: Order) => boolean;
|
|
23
23
|
orderProgress: (order: Order) => BN;
|
package/dist/src/lib.js
CHANGED
|
@@ -28,18 +28,18 @@ class TWAPLib {
|
|
|
28
28
|
this.provider = provider;
|
|
29
29
|
this.maker = maker;
|
|
30
30
|
this.dstAmount = (srcToken, dstToken, srcAmount, srcUsd, dstUsd) => (0, web3_candies_1.convertDecimals)((0, bignumber_js_1.default)(srcAmount).times(srcUsd).div(dstUsd), srcToken.decimals, dstToken.decimals).integerValue(bignumber_js_1.default.ROUND_FLOOR);
|
|
31
|
-
this.isNativeToken = (token) =>
|
|
31
|
+
this.isNativeToken = (token) => (0, configs_1.isNativeAddress)(token.address);
|
|
32
32
|
this.isValidChain = (chainId) => chainId === this.config.chainId;
|
|
33
33
|
this.maxPossibleChunks = (srcToken, srcAmount, srcUsd) => bignumber_js_1.default.max(1, (0, bignumber_js_1.default)(srcAmount).div((0, bignumber_js_1.default)(10).pow(srcToken.decimals).div(srcUsd).times(this.config.minChunkSizeUsd)))
|
|
34
34
|
.integerValue(bignumber_js_1.default.ROUND_FLOOR)
|
|
35
35
|
.toNumber();
|
|
36
36
|
this.srcChunkAmount = (srcAmount, totalChunks) => (0, bignumber_js_1.default)(srcAmount).div(totalChunks).integerValue(bignumber_js_1.default.ROUND_FLOOR);
|
|
37
|
-
this.totalChunks = (srcAmount, srcChunkAmount) => (0, bignumber_js_1.default)(srcAmount).div(srcChunkAmount).integerValue(bignumber_js_1.default.ROUND_CEIL);
|
|
38
|
-
this.fillDelayMillis = (totalChunks, maxDurationMillis) => (0, bignumber_js_1.default)(totalChunks).lte(
|
|
39
|
-
?
|
|
37
|
+
this.totalChunks = (srcAmount, srcChunkAmount) => (0, bignumber_js_1.default)(srcAmount).div(srcChunkAmount).integerValue(bignumber_js_1.default.ROUND_CEIL).toNumber();
|
|
38
|
+
this.fillDelayMillis = (totalChunks, maxDurationMillis) => (0, bignumber_js_1.default)(totalChunks).lte(1) || (0, bignumber_js_1.default)(maxDurationMillis).lte(this.config.bidDelaySeconds)
|
|
39
|
+
? 0
|
|
40
40
|
: bignumber_js_1.default.max((0, bignumber_js_1.default)(maxDurationMillis)
|
|
41
41
|
.div(totalChunks)
|
|
42
|
-
.minus((0, bignumber_js_1.default)(this.config.bidDelaySeconds * 1000)), 0);
|
|
42
|
+
.minus((0, bignumber_js_1.default)(this.config.bidDelaySeconds * 1000)), 0).toNumber();
|
|
43
43
|
this.dstMinAmountOut = (srcToken, dstToken, srcChunkAmount, limitDstPriceFor1Src, isMarketOrder) => isMarketOrder
|
|
44
44
|
? (0, bignumber_js_1.default)(1)
|
|
45
45
|
: (0, web3_candies_1.convertDecimals)((0, bignumber_js_1.default)(srcChunkAmount).times(limitDstPriceFor1Src), srcToken.decimals, dstToken.decimals).integerValue(bignumber_js_1.default.ROUND_FLOOR);
|
package/dist/src/paraswap.js
CHANGED
|
@@ -16,6 +16,7 @@ exports.Paraswap = void 0;
|
|
|
16
16
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
17
17
|
const axios_1 = __importDefault(require("axios"));
|
|
18
18
|
const web3_candies_1 = require("@defi.org/web3-candies");
|
|
19
|
+
const configs_1 = require("./configs");
|
|
19
20
|
var Paraswap;
|
|
20
21
|
(function (Paraswap) {
|
|
21
22
|
const URL = "https://apiv5.paraswap.io";
|
|
@@ -28,7 +29,8 @@ var Paraswap;
|
|
|
28
29
|
})(OnlyDex = Paraswap.OnlyDex || (Paraswap.OnlyDex = {}));
|
|
29
30
|
function priceUsd(chainId, token) {
|
|
30
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
const
|
|
32
|
+
const _token = (0, configs_1.isNativeAddress)(token.address) ? (0, configs_1.chainConfig)(chainId).wToken : token;
|
|
33
|
+
const r = yield findRoute(chainId, _token, { address: configs_1.nativeTokenAddresses[2], symbol: "NATIVE", decimals: 18 }, (0, bignumber_js_1.default)(10).pow(_token.decimals));
|
|
32
34
|
return (0, bignumber_js_1.default)(r.srcUSD);
|
|
33
35
|
});
|
|
34
36
|
}
|