@orbs-network/twap 1.8.0 → 1.8.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.
- package/dist/src/configs.d.ts +9 -0
- package/dist/src/configs.js +4 -0
- package/dist/src/lib.d.ts +3 -3
- package/dist/src/lib.js +10 -9
- package/package.json +2 -2
package/dist/src/configs.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface TokenData {
|
|
|
7
7
|
}
|
|
8
8
|
export interface Config {
|
|
9
9
|
chainId: number;
|
|
10
|
+
chainName: string;
|
|
10
11
|
twapAddress: string;
|
|
11
12
|
lensAddress: string;
|
|
12
13
|
bidDelaySeconds: number;
|
|
@@ -19,6 +20,7 @@ export interface Config {
|
|
|
19
20
|
}
|
|
20
21
|
export declare const ChainConfigs: {
|
|
21
22
|
eth: {
|
|
23
|
+
chainName: string;
|
|
22
24
|
chainId: number;
|
|
23
25
|
twapAddress: string;
|
|
24
26
|
lensAddress: string;
|
|
@@ -32,6 +34,7 @@ export declare const ChainConfigs: {
|
|
|
32
34
|
};
|
|
33
35
|
};
|
|
34
36
|
ftm: {
|
|
37
|
+
chainName: string;
|
|
35
38
|
chainId: number;
|
|
36
39
|
twapAddress: string;
|
|
37
40
|
lensAddress: string;
|
|
@@ -45,6 +48,7 @@ export declare const ChainConfigs: {
|
|
|
45
48
|
};
|
|
46
49
|
};
|
|
47
50
|
poly: {
|
|
51
|
+
chainName: string;
|
|
48
52
|
chainId: number;
|
|
49
53
|
twapAddress: string;
|
|
50
54
|
lensAddress: string;
|
|
@@ -58,6 +62,7 @@ export declare const ChainConfigs: {
|
|
|
58
62
|
};
|
|
59
63
|
};
|
|
60
64
|
avax: {
|
|
65
|
+
chainName: string;
|
|
61
66
|
chainId: number;
|
|
62
67
|
twapAddress: string;
|
|
63
68
|
lensAddress: string;
|
|
@@ -80,6 +85,7 @@ export declare const Configs: {
|
|
|
80
85
|
export declare const nativeTokenAddresses: string[];
|
|
81
86
|
export declare const isNativeAddress: (address: string) => boolean;
|
|
82
87
|
export declare const chainConfig: (chainId: number) => {
|
|
88
|
+
chainName: string;
|
|
83
89
|
chainId: number;
|
|
84
90
|
twapAddress: string;
|
|
85
91
|
lensAddress: string;
|
|
@@ -92,6 +98,7 @@ export declare const chainConfig: (chainId: number) => {
|
|
|
92
98
|
logoUrl: string;
|
|
93
99
|
};
|
|
94
100
|
} | {
|
|
101
|
+
chainName: string;
|
|
95
102
|
chainId: number;
|
|
96
103
|
twapAddress: string;
|
|
97
104
|
lensAddress: string;
|
|
@@ -104,6 +111,7 @@ export declare const chainConfig: (chainId: number) => {
|
|
|
104
111
|
logoUrl: string;
|
|
105
112
|
};
|
|
106
113
|
} | {
|
|
114
|
+
chainName: string;
|
|
107
115
|
chainId: number;
|
|
108
116
|
twapAddress: string;
|
|
109
117
|
lensAddress: string;
|
|
@@ -116,6 +124,7 @@ export declare const chainConfig: (chainId: number) => {
|
|
|
116
124
|
logoUrl: string;
|
|
117
125
|
};
|
|
118
126
|
} | {
|
|
127
|
+
chainName: string;
|
|
119
128
|
chainId: number;
|
|
120
129
|
twapAddress: string;
|
|
121
130
|
lensAddress: string;
|
package/dist/src/configs.js
CHANGED
|
@@ -9,6 +9,7 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
|
9
9
|
const paraswap_1 = require("./paraswap");
|
|
10
10
|
exports.ChainConfigs = {
|
|
11
11
|
eth: {
|
|
12
|
+
chainName: "eth",
|
|
12
13
|
chainId: 1,
|
|
13
14
|
twapAddress: "",
|
|
14
15
|
lensAddress: "",
|
|
@@ -22,6 +23,7 @@ exports.ChainConfigs = {
|
|
|
22
23
|
},
|
|
23
24
|
},
|
|
24
25
|
ftm: {
|
|
26
|
+
chainName: "ftm",
|
|
25
27
|
chainId: 250,
|
|
26
28
|
twapAddress: "0xBb9F828E34A1327607c3e4eA3dD35891398DD5EE",
|
|
27
29
|
lensAddress: "0x042799657E971855eD619046aeDf7F30DB56d2D6",
|
|
@@ -35,6 +37,7 @@ exports.ChainConfigs = {
|
|
|
35
37
|
},
|
|
36
38
|
},
|
|
37
39
|
poly: {
|
|
40
|
+
chainName: "poly",
|
|
38
41
|
chainId: 137,
|
|
39
42
|
twapAddress: "0xBAFdE1cc254BB94Be5866d5a86ddafde4BB44EEF",
|
|
40
43
|
lensAddress: "0xc918bdC47264687796Cd54FE362FaC4f8b99Eb55",
|
|
@@ -48,6 +51,7 @@ exports.ChainConfigs = {
|
|
|
48
51
|
},
|
|
49
52
|
},
|
|
50
53
|
avax: {
|
|
54
|
+
chainName: "avax",
|
|
51
55
|
chainId: 43114,
|
|
52
56
|
twapAddress: "0xD63430c74C8E70D9dbdCA04C6a9E6E9E929028DA",
|
|
53
57
|
lensAddress: "0xD13609A8ace04D11Ea2FFE176B69dF77C6d9375E",
|
package/dist/src/lib.d.ts
CHANGED
|
@@ -39,11 +39,11 @@ export declare class TWAPLib {
|
|
|
39
39
|
getAllOrders(): Promise<Order[]>;
|
|
40
40
|
parseOrder(r: any): Order;
|
|
41
41
|
getToken(address: string): Promise<TokenData>;
|
|
42
|
-
findSwapDataForBid(
|
|
42
|
+
findSwapDataForBid(order: Order): Promise<{
|
|
43
43
|
srcToken: TokenData;
|
|
44
44
|
dstToken: TokenData;
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
srcNextChunkAmountIn: BN;
|
|
46
|
+
dstNextChunkAmountOut: BN;
|
|
47
47
|
raw: any;
|
|
48
48
|
data: string;
|
|
49
49
|
}>;
|
package/dist/src/lib.js
CHANGED
|
@@ -209,24 +209,25 @@ class TWAPLib {
|
|
|
209
209
|
return { address, decimals: yield t.decimals(), symbol: yield t.methods.symbol().call() };
|
|
210
210
|
});
|
|
211
211
|
}
|
|
212
|
-
findSwapDataForBid(
|
|
212
|
+
findSwapDataForBid(order) {
|
|
213
213
|
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
if (order.ask.exchange !== web3_candies_1.zeroAddress && !(0, web3_candies_1.eqIgnoreCase)(order.ask.exchange, this.config.exchangeAddress))
|
|
215
|
+
throw new Error(`mismatched exchange and config`);
|
|
216
|
+
const srcNextChunkAmountIn = bignumber_js_1.default.min(order.ask.srcBidAmount, order.ask.srcAmount.minus(order.srcFilledAmount));
|
|
216
217
|
const [srcToken, dstToken] = yield Promise.all([
|
|
217
218
|
this.getToken(order.ask.srcToken),
|
|
218
219
|
this.getToken(order.ask.dstToken),
|
|
219
220
|
]);
|
|
220
|
-
const route = yield paraswap_1.Paraswap.findRoute(this.config.chainId, srcToken, dstToken,
|
|
221
|
-
const
|
|
221
|
+
const route = yield paraswap_1.Paraswap.findRoute(this.config.chainId, srcToken, dstToken, srcNextChunkAmountIn, this.config.pathfinderKey);
|
|
222
|
+
const dstNextChunkAmountOut = (0, bignumber_js_1.default)(route.destAmount);
|
|
222
223
|
switch (this.config.exchangeType) {
|
|
223
224
|
case "UniswapV2Exchange":
|
|
224
225
|
const path = paraswap_1.Paraswap.getDirectPath(route, this.config.pathfinderKey);
|
|
225
226
|
return {
|
|
226
227
|
srcToken,
|
|
227
228
|
dstToken,
|
|
228
|
-
|
|
229
|
-
|
|
229
|
+
srcNextChunkAmountIn,
|
|
230
|
+
dstNextChunkAmountOut,
|
|
230
231
|
raw: path,
|
|
231
232
|
data: (0, web3_candies_1.web3)().eth.abi.encodeParameters(["bool", "address[]"], [true, path]),
|
|
232
233
|
};
|
|
@@ -234,8 +235,8 @@ class TWAPLib {
|
|
|
234
235
|
return {
|
|
235
236
|
srcToken,
|
|
236
237
|
dstToken,
|
|
237
|
-
|
|
238
|
-
|
|
238
|
+
srcNextChunkAmountIn,
|
|
239
|
+
dstNextChunkAmountOut,
|
|
239
240
|
raw: route,
|
|
240
241
|
data: yield paraswap_1.Paraswap.buildSwapData(route, this.config.twapAddress),
|
|
241
242
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orbs-network/twap",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/orbs-network/twap.git"
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"prettier": "prettier --write '{test,src,contracts}/**/*.{ts,js,json,sol}'",
|
|
24
24
|
"typechain": "npm run clean && hardhat typechain",
|
|
25
25
|
"prebuild": "npm run prettier && npm run typechain",
|
|
26
|
-
"build": "hardhat compile && solhint 'contracts/**/*.sol' && tsc",
|
|
26
|
+
"build": "hardhat compile && solhint 'contracts/**/*.sol' && tsc && hardhat github-pages",
|
|
27
27
|
"prepublishOnly": "npm run build",
|
|
28
28
|
"test:logs": "for t in eth ftm poly avax; do DEBUG=web3-candies npm run test:$t -- --logs; done",
|
|
29
29
|
"test": "for t in eth ftm poly avax; do npm run test:$t; done",
|