@orbs-network/twap 1.7.13 → 1.7.15
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 +1 -0
- package/dist/src/configs.js +3 -17
- package/dist/src/lib.d.ts +7 -10
- package/dist/src/lib.js +37 -52
- package/dist/src/paraswap.d.ts +3 -3
- package/dist/src/paraswap.js +20 -7
- package/dist/typechain-hardhat/contracts/IExchange.d.ts +2 -3
- package/dist/typechain-hardhat/contracts/IWETH.d.ts +1 -2
- package/dist/typechain-hardhat/contracts/TWAP.d.ts +9 -10
- package/dist/typechain-hardhat/contracts/exchange/IUniswapV2.d.ts +3 -4
- package/dist/typechain-hardhat/contracts/exchange/ParaswapExchange.d.ts +2 -3
- package/dist/typechain-hardhat/contracts/exchange/UniswapV2Exchange.d.ts +2 -3
- package/dist/typechain-hardhat/contracts/periphery/Lens.d.ts +2 -3
- package/dist/typechain-hardhat/contracts/periphery/Taker.d.ts +2 -3
- package/dist/typechain-hardhat/contracts/test/MockDeflationaryToken.d.ts +5 -6
- package/dist/typechain-hardhat/contracts/test/MockExchange.d.ts +4 -5
- package/dist/typechain-hardhat/types.d.ts +9 -10
- package/package.json +1 -1
package/dist/src/configs.d.ts
CHANGED
package/dist/src/configs.js
CHANGED
|
@@ -36,8 +36,8 @@ exports.ChainConfigs = {
|
|
|
36
36
|
},
|
|
37
37
|
poly: {
|
|
38
38
|
chainId: 137,
|
|
39
|
-
twapAddress: "",
|
|
40
|
-
lensAddress: "",
|
|
39
|
+
twapAddress: "0xBAFdE1cc254BB94Be5866d5a86ddafde4BB44EEF",
|
|
40
|
+
lensAddress: "0xc918bdC47264687796Cd54FE362FaC4f8b99Eb55",
|
|
41
41
|
bidDelaySeconds: 60,
|
|
42
42
|
minChunkSizeUsd: 10,
|
|
43
43
|
wToken: {
|
|
@@ -65,22 +65,8 @@ exports.Configs = {
|
|
|
65
65
|
SpiritSwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { partner: "SpiritSwap", exchangeAddress: "0xAd19179201be5A51D1cBd3bB2fC651BB05822404", exchangeType: "ParaswapExchange", pathfinderKey: paraswap_1.Paraswap.OnlyDex.SpiritSwap }),
|
|
66
66
|
SpookySwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { partner: "SpookySwap", exchangeAddress: "0x37F427DA0D12Fe2C80aCa09EE08e7e92A1B2B114", exchangeType: "UniswapV2Exchange", pathfinderKey: paraswap_1.Paraswap.OnlyDex.SpookySwap }),
|
|
67
67
|
Pangolin: Object.assign(Object.assign({}, exports.ChainConfigs.avax), { partner: "Pangolin", exchangeAddress: "0x25a0A78f5ad07b2474D3D42F1c1432178465936d", exchangeType: "UniswapV2Exchange", pathfinderKey: paraswap_1.Paraswap.OnlyDex.Pangolin }),
|
|
68
|
+
QuickSwap: Object.assign(Object.assign({}, exports.ChainConfigs.poly), { partner: "QuickSwap", exchangeAddress: "0x260922357Ea26cd5cB5d9A75f742fDF235847620", exchangeType: "UniswapV2Exchange", pathfinderKey: paraswap_1.Paraswap.OnlyDex.QuickSwap }),
|
|
68
69
|
};
|
|
69
|
-
// export const UniswapV2Config: Config = {
|
|
70
|
-
// ...ChainConfigs.eth,
|
|
71
|
-
// partner: "UniswapV2",
|
|
72
|
-
// exchangeAddress: "0xE83df5BfA9F14a84e550c38c4ec505cB22C6A0d7",
|
|
73
|
-
// };
|
|
74
|
-
// export const SushiSwapConfig: Config = {
|
|
75
|
-
// ...ChainConfigs.eth,
|
|
76
|
-
// partner: "SushiSwap",
|
|
77
|
-
// exchangeAddress: "0x72a18A408e329E7052d08aA0746243Dc30Ad2530",
|
|
78
|
-
// };
|
|
79
|
-
// export const QuickSwapConfig: Config = {
|
|
80
|
-
// ...ChainConfigs.poly,
|
|
81
|
-
// partner: "QuickSwap",
|
|
82
|
-
// exchangeAddress: "0xeFE1B6096838949156e5130604434A2a13c68C68",
|
|
83
|
-
// };
|
|
84
70
|
exports.nativeTokenAddresses = [
|
|
85
71
|
web3_candies_1.zeroAddress,
|
|
86
72
|
"0x0000000000000000000000000000000000001010",
|
package/dist/src/lib.d.ts
CHANGED
|
@@ -27,27 +27,24 @@ export declare class TWAPLib {
|
|
|
27
27
|
percentAboveMarket: (srcUsdMarket: BN.Value, dstUsdMarket: BN.Value, limitDstPriceFor1Src: BN.Value) => number;
|
|
28
28
|
status: (order: Order) => Status;
|
|
29
29
|
makerBalance(token: TokenData): Promise<BN>;
|
|
30
|
-
wrapNativeToken(amount: BN.Value,
|
|
31
|
-
unwrapNativeToken(amount: BN.Value,
|
|
32
|
-
waitForConfirmation<T>(fn: () => Promise<T>): Promise<T>;
|
|
30
|
+
wrapNativeToken(amount: BN.Value, maxPriorityFeePerGas?: BN.Value, maxFeePerGas?: BN.Value): Promise<void>;
|
|
31
|
+
unwrapNativeToken(amount: BN.Value, maxPriorityFeePerGas?: BN.Value, maxFeePerGas?: BN.Value): Promise<void>;
|
|
33
32
|
hasAllowance(srcToken: TokenData, amount: BN.Value): Promise<boolean>;
|
|
34
|
-
approve(srcToken: TokenData, amount: BN.Value,
|
|
33
|
+
approve(srcToken: TokenData, amount: BN.Value, maxPriorityFeePerGas?: BN.Value, maxFeePerGas?: BN.Value): Promise<void>;
|
|
35
34
|
validateTokens(srcToken: TokenData, dstToken: TokenData): TokensValidation;
|
|
36
35
|
validateOrderInputs(srcToken: TokenData, dstToken: TokenData, srcAmount: BN.Value, srcChunkAmount: BN.Value, dstMinChunkAmountOut: BN.Value, deadline: BN.Value, fillDelaySeconds: BN.Value, srcUsd: BN.Value): OrderInputValidation;
|
|
37
|
-
submitOrder(srcToken: TokenData, dstToken: TokenData, srcAmount: BN.Value, srcChunkAmount: BN.Value, dstMinChunkAmountOut: BN.Value, deadline: number, fillDelaySeconds: number, srcUsd: BN.Value,
|
|
36
|
+
submitOrder(srcToken: TokenData, dstToken: TokenData, srcAmount: BN.Value, srcChunkAmount: BN.Value, dstMinChunkAmountOut: BN.Value, deadline: number, fillDelaySeconds: number, srcUsd: BN.Value, maxPriorityFeePerGas?: BN.Value, maxFeePerGas?: BN.Value): Promise<number>;
|
|
38
37
|
getOrder(id: number): Promise<Order>;
|
|
39
|
-
cancelOrder(id: number,
|
|
38
|
+
cancelOrder(id: number, maxPriorityFeePerGas?: BN.Value, maxFeePerGas?: BN.Value): Promise<void>;
|
|
40
39
|
getAllOrders(): Promise<Order[]>;
|
|
41
|
-
private sendTx;
|
|
42
40
|
parseOrder(r: any): Order;
|
|
43
41
|
getToken(address: string): Promise<TokenData>;
|
|
44
|
-
|
|
45
|
-
getSwapData(orderId: number): Promise<{
|
|
42
|
+
findSwapDataForBid(orderId: number): Promise<{
|
|
46
43
|
srcToken: TokenData;
|
|
47
44
|
dstToken: TokenData;
|
|
48
45
|
srcAmountIn: BN;
|
|
49
46
|
dstAmountOut: BN;
|
|
50
|
-
|
|
47
|
+
raw: any;
|
|
51
48
|
data: string;
|
|
52
49
|
}>;
|
|
53
50
|
}
|
package/dist/src/lib.js
CHANGED
|
@@ -20,8 +20,8 @@ const web3_candies_1 = require("@defi.org/web3-candies");
|
|
|
20
20
|
const TWAP_json_1 = __importDefault(require("../artifacts/contracts/TWAP.sol/TWAP.json"));
|
|
21
21
|
const Lens_json_1 = __importDefault(require("../artifacts/contracts/periphery/Lens.sol/Lens.json"));
|
|
22
22
|
const Taker_json_1 = __importDefault(require("../artifacts/contracts/periphery/Taker.sol/Taker.json"));
|
|
23
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
24
23
|
const paraswap_1 = require("./paraswap");
|
|
24
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
25
25
|
exports.twapAbi = TWAP_json_1.default.abi;
|
|
26
26
|
exports.lensAbi = Lens_json_1.default.abi;
|
|
27
27
|
exports.takerAbi = Taker_json_1.default.abi;
|
|
@@ -73,24 +73,14 @@ class TWAPLib {
|
|
|
73
73
|
return (0, web3_candies_1.erc20)(token.symbol, token.address, token.decimals).methods.balanceOf(this.maker).call().then(bignumber_js_1.default);
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
|
-
wrapNativeToken(amount,
|
|
77
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
return yield this.sendTx((0, web3_candies_1.erc20)(this.config.wToken.symbol, this.config.wToken.address, this.config.wToken.decimals, web3_candies_1.iwethabi).methods.deposit(), priorityFeePerGas, maxFeePerGas, amount);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
unwrapNativeToken(amount, priorityFeePerGas, maxFeePerGas) {
|
|
76
|
+
wrapNativeToken(amount, maxPriorityFeePerGas, maxFeePerGas) {
|
|
82
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
|
|
78
|
+
yield (0, web3_candies_1.sendAndWaitForConfirmations)((0, web3_candies_1.erc20)(this.config.wToken.symbol, this.config.wToken.address, this.config.wToken.decimals, web3_candies_1.iwethabi).methods.deposit(), { from: this.maker, maxPriorityFeePerGas, maxFeePerGas, value: amount });
|
|
84
79
|
});
|
|
85
80
|
}
|
|
86
|
-
|
|
81
|
+
unwrapNativeToken(amount, maxPriorityFeePerGas, maxFeePerGas) {
|
|
87
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
|
|
89
|
-
const result = yield fn();
|
|
90
|
-
while ((yield (0, web3_candies_1.web3)().eth.getTransactionCount(this.maker)) === nonceBefore) {
|
|
91
|
-
yield new Promise((r) => setTimeout(r, 1000));
|
|
92
|
-
}
|
|
93
|
-
return result;
|
|
83
|
+
yield (0, web3_candies_1.sendAndWaitForConfirmations)((0, web3_candies_1.erc20)(this.config.wToken.symbol, this.config.wToken.address, this.config.wToken.decimals, web3_candies_1.iwethabi).methods.withdraw((0, bignumber_js_1.default)(amount).toFixed(0)), { from: this.maker, maxPriorityFeePerGas, maxFeePerGas });
|
|
94
84
|
});
|
|
95
85
|
}
|
|
96
86
|
hasAllowance(srcToken, amount) {
|
|
@@ -102,10 +92,14 @@ class TWAPLib {
|
|
|
102
92
|
return allowance.gte(amount);
|
|
103
93
|
});
|
|
104
94
|
}
|
|
105
|
-
approve(srcToken, amount,
|
|
95
|
+
approve(srcToken, amount, maxPriorityFeePerGas, maxFeePerGas) {
|
|
106
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
97
|
const token = (0, web3_candies_1.erc20)(srcToken.symbol, srcToken.address, srcToken.decimals);
|
|
108
|
-
yield
|
|
98
|
+
yield (0, web3_candies_1.sendAndWaitForConfirmations)(token.methods.approve(this.config.twapAddress, (0, bignumber_js_1.default)(amount).toFixed(0)), {
|
|
99
|
+
from: this.maker,
|
|
100
|
+
maxPriorityFeePerGas,
|
|
101
|
+
maxFeePerGas,
|
|
102
|
+
});
|
|
109
103
|
});
|
|
110
104
|
}
|
|
111
105
|
validateTokens(srcToken, dstToken) {
|
|
@@ -144,12 +138,16 @@ class TWAPLib {
|
|
|
144
138
|
return OrderInputValidation.invalidSmallestSrcChunkUsd;
|
|
145
139
|
return OrderInputValidation.valid;
|
|
146
140
|
}
|
|
147
|
-
submitOrder(srcToken, dstToken, srcAmount, srcChunkAmount, dstMinChunkAmountOut, deadline, fillDelaySeconds, srcUsd,
|
|
141
|
+
submitOrder(srcToken, dstToken, srcAmount, srcChunkAmount, dstMinChunkAmountOut, deadline, fillDelaySeconds, srcUsd, maxPriorityFeePerGas, maxFeePerGas) {
|
|
148
142
|
return __awaiter(this, void 0, void 0, function* () {
|
|
149
143
|
let validation = this.validateOrderInputs(srcToken, dstToken, srcAmount, srcChunkAmount, dstMinChunkAmountOut, deadline, fillDelaySeconds, srcUsd);
|
|
150
144
|
if (validation !== OrderInputValidation.valid)
|
|
151
145
|
throw new Error(`invalid inputs: ${validation}`);
|
|
152
|
-
const tx = yield
|
|
146
|
+
const tx = yield (0, web3_candies_1.sendAndWaitForConfirmations)(this.twap.methods.ask(this.config.exchangeAddress, srcToken.address, dstToken.address, (0, bignumber_js_1.default)(srcAmount).toFixed(0), (0, bignumber_js_1.default)(srcChunkAmount).toFixed(0), (0, bignumber_js_1.default)(dstMinChunkAmountOut).toFixed(0), (0, bignumber_js_1.default)(deadline).div(1000).toFixed(0), (0, bignumber_js_1.default)(this.config.bidDelaySeconds).toFixed(0), (0, bignumber_js_1.default)(fillDelaySeconds).toFixed(0)), {
|
|
147
|
+
from: this.maker,
|
|
148
|
+
maxPriorityFeePerGas,
|
|
149
|
+
maxFeePerGas,
|
|
150
|
+
});
|
|
153
151
|
const events = (0, web3_candies_1.parseEvents)(tx, this.twap.options.jsonInterface);
|
|
154
152
|
return Number(events[0].returnValues.id);
|
|
155
153
|
});
|
|
@@ -159,9 +157,13 @@ class TWAPLib {
|
|
|
159
157
|
return this.parseOrder(yield this.twap.methods.order(id).call());
|
|
160
158
|
});
|
|
161
159
|
}
|
|
162
|
-
cancelOrder(id,
|
|
160
|
+
cancelOrder(id, maxPriorityFeePerGas, maxFeePerGas) {
|
|
163
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
yield
|
|
162
|
+
yield (0, web3_candies_1.sendAndWaitForConfirmations)(this.twap.methods.cancel(id), {
|
|
163
|
+
from: this.maker,
|
|
164
|
+
maxPriorityFeePerGas,
|
|
165
|
+
maxFeePerGas,
|
|
166
|
+
});
|
|
165
167
|
});
|
|
166
168
|
}
|
|
167
169
|
getAllOrders() {
|
|
@@ -169,17 +171,6 @@ class TWAPLib {
|
|
|
169
171
|
return lodash_1.default.map(yield this.lens.methods.makerOrders(this.maker).call(), (o) => this.parseOrder(o));
|
|
170
172
|
});
|
|
171
173
|
}
|
|
172
|
-
sendTx(tx, priorityFeePerGas, maxFeePerGas, amount) {
|
|
173
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
-
return yield tx.send({
|
|
175
|
-
from: this.maker,
|
|
176
|
-
gas: Math.floor((yield tx.estimateGas({ from: this.maker, value: amount ? (0, bignumber_js_1.default)(amount).toFixed(0) : undefined })) * 1.2),
|
|
177
|
-
maxPriorityFeePerGas: priorityFeePerGas ? (0, bignumber_js_1.default)(priorityFeePerGas).toFixed(0) : undefined,
|
|
178
|
-
maxFeePerGas: maxFeePerGas ? (0, bignumber_js_1.default)(maxFeePerGas).toFixed(0) : undefined,
|
|
179
|
-
value: amount ? (0, bignumber_js_1.default)(amount).toFixed(0) : undefined,
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
174
|
parseOrder(r) {
|
|
184
175
|
var _a, _b, _c, _d, _e, _f;
|
|
185
176
|
return {
|
|
@@ -212,38 +203,32 @@ class TWAPLib {
|
|
|
212
203
|
}
|
|
213
204
|
getToken(address) {
|
|
214
205
|
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
-
if ((0, configs_1.isNativeAddress)(address))
|
|
206
|
+
if ((0, configs_1.isNativeAddress)(address) || (0, web3_candies_1.eqIgnoreCase)(address, this.config.wToken.address))
|
|
216
207
|
return this.config.wToken;
|
|
217
208
|
const t = (0, web3_candies_1.erc20)("", address);
|
|
218
209
|
return { address, decimals: yield t.decimals(), symbol: yield t.methods.symbol().call() };
|
|
219
210
|
});
|
|
220
211
|
}
|
|
221
|
-
|
|
222
|
-
deployTaker(priorityFeePerGas, maxFeePerGas) {
|
|
223
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
-
const taker = (0, web3_candies_1.contract)(exports.takerAbi, "");
|
|
225
|
-
yield this.sendTx(taker.deploy({ data: Taker_json_1.default.bytecode, arguments: [this.config.twapAddress, [this.maker]] }), priorityFeePerGas, maxFeePerGas);
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
//TODO
|
|
229
|
-
getSwapData(orderId) {
|
|
212
|
+
findSwapDataForBid(orderId) {
|
|
230
213
|
return __awaiter(this, void 0, void 0, function* () {
|
|
231
214
|
const order = yield this.getOrder(orderId);
|
|
232
|
-
const srcAmountIn = order.ask.srcBidAmount;
|
|
233
|
-
const srcToken = yield
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const
|
|
215
|
+
const srcAmountIn = bignumber_js_1.default.min(order.ask.srcBidAmount, order.ask.srcAmount.minus(order.srcFilledAmount));
|
|
216
|
+
const [srcToken, dstToken] = yield Promise.all([
|
|
217
|
+
this.getToken(order.ask.srcToken),
|
|
218
|
+
this.getToken(order.ask.dstToken),
|
|
219
|
+
]);
|
|
220
|
+
const route = yield paraswap_1.Paraswap.findRoute(this.config.chainId, srcToken, dstToken, srcAmountIn, this.config.pathfinderKey);
|
|
221
|
+
const dstAmountOut = (0, bignumber_js_1.default)(route.destAmount);
|
|
238
222
|
switch (this.config.exchangeType) {
|
|
239
223
|
case "UniswapV2Exchange":
|
|
224
|
+
const path = paraswap_1.Paraswap.getDirectPath(route, this.config.pathfinderKey);
|
|
240
225
|
return {
|
|
241
226
|
srcToken,
|
|
242
227
|
dstToken,
|
|
243
228
|
srcAmountIn,
|
|
244
229
|
dstAmountOut,
|
|
245
|
-
path,
|
|
246
|
-
data: (0, web3_candies_1.web3)().eth.abi.encodeParameters(["bool", "address[]"], [
|
|
230
|
+
raw: path,
|
|
231
|
+
data: (0, web3_candies_1.web3)().eth.abi.encodeParameters(["bool", "address[]"], [true, path]),
|
|
247
232
|
};
|
|
248
233
|
case "ParaswapExchange":
|
|
249
234
|
return {
|
|
@@ -251,8 +236,8 @@ class TWAPLib {
|
|
|
251
236
|
dstToken,
|
|
252
237
|
srcAmountIn,
|
|
253
238
|
dstAmountOut,
|
|
254
|
-
|
|
255
|
-
data: yield paraswap_1.Paraswap.buildSwapData(
|
|
239
|
+
raw: route,
|
|
240
|
+
data: yield paraswap_1.Paraswap.buildSwapData(route, this.config.twapAddress),
|
|
256
241
|
};
|
|
257
242
|
default:
|
|
258
243
|
throw new Error(`unhandled exchange ${this.config.exchangeType}`);
|
package/dist/src/paraswap.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare namespace Paraswap {
|
|
|
7
7
|
QuickSwap = "QuickSwap",
|
|
8
8
|
SpiritSwap = "SpiritSwap,SpiritSwapV2",
|
|
9
9
|
SpookySwap = "SpookySwap",
|
|
10
|
-
Pangolin = "
|
|
10
|
+
Pangolin = "PangolinSwap",
|
|
11
11
|
TraderJoe = "TraderJoe"
|
|
12
12
|
}
|
|
13
13
|
interface ParaswapRoute {
|
|
@@ -39,7 +39,7 @@ export declare namespace Paraswap {
|
|
|
39
39
|
instant: BN;
|
|
40
40
|
}>;
|
|
41
41
|
function priceUsd(chainId: number, token: TokenData): Promise<BN>;
|
|
42
|
-
function findRoute(chainId: number, src: TokenData, dst: TokenData, amountIn: BN.Value, onlyDex?: OnlyDex): Promise<ParaswapRoute>;
|
|
43
|
-
function
|
|
42
|
+
function findRoute(chainId: number, src: TokenData, dst: TokenData, amountIn: BN.Value, onlyDex?: OnlyDex, otherExchanges?: boolean): Promise<ParaswapRoute>;
|
|
43
|
+
function getDirectPath(route: ParaswapRoute, onlyDex: OnlyDex): string[];
|
|
44
44
|
function buildSwapData(paraswapRoute: ParaswapRoute, exchangeAdapter: string): Promise<string>;
|
|
45
45
|
}
|
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 web3_candies_1 = require("@defi.org/web3-candies");
|
|
18
18
|
const configs_1 = require("./configs");
|
|
19
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
19
20
|
var Paraswap;
|
|
20
21
|
(function (Paraswap) {
|
|
21
22
|
const URL = "https://apiv5.paraswap.io";
|
|
@@ -26,7 +27,7 @@ var Paraswap;
|
|
|
26
27
|
OnlyDex["QuickSwap"] = "QuickSwap";
|
|
27
28
|
OnlyDex["SpiritSwap"] = "SpiritSwap,SpiritSwapV2";
|
|
28
29
|
OnlyDex["SpookySwap"] = "SpookySwap";
|
|
29
|
-
OnlyDex["Pangolin"] = "
|
|
30
|
+
OnlyDex["Pangolin"] = "PangolinSwap";
|
|
30
31
|
OnlyDex["TraderJoe"] = "TraderJoe";
|
|
31
32
|
})(OnlyDex = Paraswap.OnlyDex || (Paraswap.OnlyDex = {}));
|
|
32
33
|
function gasPrices(chainId) {
|
|
@@ -52,7 +53,7 @@ var Paraswap;
|
|
|
52
53
|
});
|
|
53
54
|
}
|
|
54
55
|
Paraswap.priceUsd = priceUsd;
|
|
55
|
-
function findRoute(chainId, src, dst, amountIn, onlyDex) {
|
|
56
|
+
function findRoute(chainId, src, dst, amountIn, onlyDex, otherExchanges = false) {
|
|
56
57
|
var _a, _b;
|
|
57
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
59
|
const params = new URLSearchParams({
|
|
@@ -65,19 +66,31 @@ var Paraswap;
|
|
|
65
66
|
side: "SELL",
|
|
66
67
|
includeDEXS: onlyDex || "",
|
|
67
68
|
partner: ((_b = (_a = onlyDex === null || onlyDex === void 0 ? void 0 : onlyDex.toLowerCase()) === null || _a === void 0 ? void 0 : _a.split(",")) === null || _b === void 0 ? void 0 : _b[0]) || "",
|
|
68
|
-
|
|
69
|
+
otherExchangePrices: otherExchanges.toString(),
|
|
69
70
|
});
|
|
70
71
|
const response = yield fetch(`${URL}/prices/?${params}`);
|
|
71
72
|
if (response.status < 200 || response.status >= 400)
|
|
72
73
|
throw new Error(`${response.statusText}`);
|
|
73
|
-
return (yield response.json()).priceRoute;
|
|
74
|
+
return (yield response.json()).priceRoute;
|
|
74
75
|
});
|
|
75
76
|
}
|
|
76
77
|
Paraswap.findRoute = findRoute;
|
|
77
|
-
function
|
|
78
|
-
|
|
78
|
+
function getDirectPath(route, onlyDex) {
|
|
79
|
+
const bestRoute = lodash_1.default.sortBy(route.bestRoute, (r) => r.percent).reverse()[0];
|
|
80
|
+
if (bestRoute.swaps.length > 1)
|
|
81
|
+
throw new Error(`invalid direct path more than 1 path`);
|
|
82
|
+
if (!(0, web3_candies_1.eqIgnoreCase)(bestRoute.swaps[0].srcToken, route.srcToken) ||
|
|
83
|
+
!(0, web3_candies_1.eqIgnoreCase)(bestRoute.swaps[0].destToken, route.destToken))
|
|
84
|
+
throw new Error(`invalid direct path tokens`);
|
|
85
|
+
const bestSwap = lodash_1.default.sortBy(bestRoute.swaps[0].swapExchanges, (s) => s.percent).reverse()[0];
|
|
86
|
+
if (!onlyDex.split(",").includes(bestSwap.exchange))
|
|
87
|
+
throw new Error(`invalid direct path exchange`);
|
|
88
|
+
const path = bestSwap.data.path;
|
|
89
|
+
if (!path || path.length < 2)
|
|
90
|
+
throw new Error(`invalid direct path`);
|
|
91
|
+
return path;
|
|
79
92
|
}
|
|
80
|
-
Paraswap.
|
|
93
|
+
Paraswap.getDirectPath = getDirectPath;
|
|
81
94
|
function buildSwapData(paraswapRoute, exchangeAdapter) {
|
|
82
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
96
|
const response = yield fetch(`${URL}/transactions/${paraswapRoute.network}?ignoreChecks=true`, {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type BN from "bn.js";
|
|
3
2
|
import type BigNumber from "bignumber.js";
|
|
4
3
|
import type { ContractOptions } from "web3-eth-contract";
|
|
5
4
|
import type { EventLog } from "web3-core";
|
|
@@ -14,8 +13,8 @@ export interface IExchange extends BaseContract {
|
|
|
14
13
|
constructor(jsonInterface: any[], address?: string, options?: ContractOptions): IExchange;
|
|
15
14
|
clone(): IExchange;
|
|
16
15
|
methods: {
|
|
17
|
-
getAmountOut(srcToken: string, dstToken: string, amountIn: number | string |
|
|
18
|
-
swap(srcToken: string, dstToken: string, amountIn: number | string |
|
|
16
|
+
getAmountOut(srcToken: string, dstToken: string, amountIn: number | string | BigNumber, data: string | number[]): NonPayableTransactionObject<string>;
|
|
17
|
+
swap(srcToken: string, dstToken: string, amountIn: number | string | BigNumber, amountOutMin: number | string | BigNumber, data: string | number[]): NonPayableTransactionObject<void>;
|
|
19
18
|
};
|
|
20
19
|
events: {
|
|
21
20
|
allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type BN from "bn.js";
|
|
3
2
|
import type BigNumber from "bignumber.js";
|
|
4
3
|
import type { ContractOptions } from "web3-eth-contract";
|
|
5
4
|
import type { EventLog } from "web3-core";
|
|
@@ -14,7 +13,7 @@ export interface IWETH extends BaseContract {
|
|
|
14
13
|
constructor(jsonInterface: any[], address?: string, options?: ContractOptions): IWETH;
|
|
15
14
|
clone(): IWETH;
|
|
16
15
|
methods: {
|
|
17
|
-
withdraw(wad: number | string |
|
|
16
|
+
withdraw(wad: number | string | BigNumber): NonPayableTransactionObject<void>;
|
|
18
17
|
};
|
|
19
18
|
events: {
|
|
20
19
|
allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type BN from "bn.js";
|
|
3
2
|
import type BigNumber from "bignumber.js";
|
|
4
3
|
import type { ContractOptions } from "web3-eth-contract";
|
|
5
4
|
import type { EventLog } from "web3-core";
|
|
@@ -103,9 +102,9 @@ export interface TWAP extends BaseContract {
|
|
|
103
102
|
STATUS_CANCELED(): NonPayableTransactionObject<string>;
|
|
104
103
|
STATUS_COMPLETED(): NonPayableTransactionObject<string>;
|
|
105
104
|
VERSION(): NonPayableTransactionObject<string>;
|
|
106
|
-
ask(exchange: string, srcToken: string, dstToken: string, srcAmount: number | string |
|
|
107
|
-
bid(id: number | string |
|
|
108
|
-
book(arg0: number | string |
|
|
105
|
+
ask(exchange: string, srcToken: string, dstToken: string, srcAmount: number | string | BigNumber, srcBidAmount: number | string | BigNumber, dstMinAmount: number | string | BigNumber, deadline: number | string | BigNumber, bidDelay: number | string | BigNumber, fillDelay: number | string | BigNumber): NonPayableTransactionObject<string>;
|
|
106
|
+
bid(id: number | string | BigNumber, exchange: string, dstFee: number | string | BigNumber, slippagePercent: number | string | BigNumber, data: string | number[]): NonPayableTransactionObject<void>;
|
|
107
|
+
book(arg0: number | string | BigNumber): NonPayableTransactionObject<{
|
|
109
108
|
id: string;
|
|
110
109
|
status: string;
|
|
111
110
|
filledTime: string;
|
|
@@ -143,12 +142,12 @@ export interface TWAP extends BaseContract {
|
|
|
143
142
|
];
|
|
144
143
|
5: [string, string, string, string, string, string];
|
|
145
144
|
}>;
|
|
146
|
-
cancel(id: number | string |
|
|
147
|
-
fill(id: number | string |
|
|
145
|
+
cancel(id: number | string | BigNumber): NonPayableTransactionObject<void>;
|
|
146
|
+
fill(id: number | string | BigNumber): NonPayableTransactionObject<void>;
|
|
148
147
|
iweth(): NonPayableTransactionObject<string>;
|
|
149
148
|
length(): NonPayableTransactionObject<string>;
|
|
150
|
-
makerOrders(arg0: string, arg1: number | string |
|
|
151
|
-
order(id: number | string |
|
|
149
|
+
makerOrders(arg0: string, arg1: number | string | BigNumber): NonPayableTransactionObject<string>;
|
|
150
|
+
order(id: number | string | BigNumber): NonPayableTransactionObject<[
|
|
152
151
|
string,
|
|
153
152
|
string,
|
|
154
153
|
string,
|
|
@@ -176,8 +175,8 @@ export interface TWAP extends BaseContract {
|
|
|
176
175
|
]
|
|
177
176
|
]>;
|
|
178
177
|
orderIdsByMaker(maker: string): NonPayableTransactionObject<string[]>;
|
|
179
|
-
prune(id: number | string |
|
|
180
|
-
status(arg0: number | string |
|
|
178
|
+
prune(id: number | string | BigNumber): NonPayableTransactionObject<void>;
|
|
179
|
+
status(arg0: number | string | BigNumber): NonPayableTransactionObject<string>;
|
|
181
180
|
};
|
|
182
181
|
events: {
|
|
183
182
|
OrderBid(cb?: Callback<OrderBid>): EventEmitter;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type BN from "bn.js";
|
|
3
2
|
import type BigNumber from "bignumber.js";
|
|
4
3
|
import type { ContractOptions } from "web3-eth-contract";
|
|
5
4
|
import type { EventLog } from "web3-core";
|
|
@@ -14,9 +13,9 @@ export interface IUniswapV2 extends BaseContract {
|
|
|
14
13
|
constructor(jsonInterface: any[], address?: string, options?: ContractOptions): IUniswapV2;
|
|
15
14
|
clone(): IUniswapV2;
|
|
16
15
|
methods: {
|
|
17
|
-
getAmountsOut(amountIn: number | string |
|
|
18
|
-
swapExactTokensForTokens(amountIn: number | string |
|
|
19
|
-
swapExactTokensForTokensSupportingFeeOnTransferTokens(amountIn: number | string |
|
|
16
|
+
getAmountsOut(amountIn: number | string | BigNumber, path: string[]): NonPayableTransactionObject<string[]>;
|
|
17
|
+
swapExactTokensForTokens(amountIn: number | string | BigNumber, amountOutMin: number | string | BigNumber, path: string[], to: string, deadline: number | string | BigNumber): NonPayableTransactionObject<string[]>;
|
|
18
|
+
swapExactTokensForTokensSupportingFeeOnTransferTokens(amountIn: number | string | BigNumber, amountOutMin: number | string | BigNumber, path: string[], to: string, deadline: number | string | BigNumber): NonPayableTransactionObject<void>;
|
|
20
19
|
};
|
|
21
20
|
events: {
|
|
22
21
|
allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type BN from "bn.js";
|
|
3
2
|
import type BigNumber from "bignumber.js";
|
|
4
3
|
import type { ContractOptions } from "web3-eth-contract";
|
|
5
4
|
import type { EventLog } from "web3-core";
|
|
@@ -14,9 +13,9 @@ export interface ParaswapExchange extends BaseContract {
|
|
|
14
13
|
constructor(jsonInterface: any[], address?: string, options?: ContractOptions): ParaswapExchange;
|
|
15
14
|
clone(): ParaswapExchange;
|
|
16
15
|
methods: {
|
|
17
|
-
getAmountOut(arg0: string, arg1: string, arg2: number | string |
|
|
16
|
+
getAmountOut(arg0: string, arg1: string, arg2: number | string | BigNumber, data: string | number[]): NonPayableTransactionObject<string>;
|
|
18
17
|
paraswap(): NonPayableTransactionObject<string>;
|
|
19
|
-
swap(_srcToken: string, _dstToken: string, amountIn: number | string |
|
|
18
|
+
swap(_srcToken: string, _dstToken: string, amountIn: number | string | BigNumber, amountOutMin: number | string | BigNumber, data: string | number[]): NonPayableTransactionObject<void>;
|
|
20
19
|
};
|
|
21
20
|
events: {
|
|
22
21
|
allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type BN from "bn.js";
|
|
3
2
|
import type BigNumber from "bignumber.js";
|
|
4
3
|
import type { ContractOptions } from "web3-eth-contract";
|
|
5
4
|
import type { EventLog } from "web3-core";
|
|
@@ -14,8 +13,8 @@ export interface UniswapV2Exchange extends BaseContract {
|
|
|
14
13
|
constructor(jsonInterface: any[], address?: string, options?: ContractOptions): UniswapV2Exchange;
|
|
15
14
|
clone(): UniswapV2Exchange;
|
|
16
15
|
methods: {
|
|
17
|
-
getAmountOut(arg0: string, arg1: string, amountIn: number | string |
|
|
18
|
-
swap(_srcToken: string, arg1: string, amountIn: number | string |
|
|
16
|
+
getAmountOut(arg0: string, arg1: string, amountIn: number | string | BigNumber, data: string | number[]): NonPayableTransactionObject<string>;
|
|
17
|
+
swap(_srcToken: string, arg1: string, amountIn: number | string | BigNumber, amountOutMin: number | string | BigNumber, data: string | number[]): NonPayableTransactionObject<void>;
|
|
19
18
|
uniswap(): NonPayableTransactionObject<string>;
|
|
20
19
|
};
|
|
21
20
|
events: {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type BN from "bn.js";
|
|
3
2
|
import type BigNumber from "bignumber.js";
|
|
4
3
|
import type { ContractOptions } from "web3-eth-contract";
|
|
5
4
|
import type { EventLog } from "web3-core";
|
|
@@ -42,7 +41,7 @@ export interface Lens extends BaseContract {
|
|
|
42
41
|
string
|
|
43
42
|
]
|
|
44
43
|
][]>;
|
|
45
|
-
takerBiddableOrders(taker: string, lastIndex: number | string |
|
|
44
|
+
takerBiddableOrders(taker: string, lastIndex: number | string | BigNumber, pageSize: number | string | BigNumber): NonPayableTransactionObject<[
|
|
46
45
|
string,
|
|
47
46
|
string,
|
|
48
47
|
string,
|
|
@@ -69,7 +68,7 @@ export interface Lens extends BaseContract {
|
|
|
69
68
|
string
|
|
70
69
|
]
|
|
71
70
|
][]>;
|
|
72
|
-
takerFillableOrders(taker: string, lastIndex: number | string |
|
|
71
|
+
takerFillableOrders(taker: string, lastIndex: number | string | BigNumber, pageSize: number | string | BigNumber): NonPayableTransactionObject<[
|
|
73
72
|
string,
|
|
74
73
|
string,
|
|
75
74
|
string,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type BN from "bn.js";
|
|
3
2
|
import type BigNumber from "bignumber.js";
|
|
4
3
|
import type { ContractOptions } from "web3-eth-contract";
|
|
5
4
|
import type { EventLog } from "web3-core";
|
|
@@ -14,8 +13,8 @@ export interface Taker extends BaseContract {
|
|
|
14
13
|
constructor(jsonInterface: any[], address?: string, options?: ContractOptions): Taker;
|
|
15
14
|
clone(): Taker;
|
|
16
15
|
methods: {
|
|
17
|
-
bid(id: number | string |
|
|
18
|
-
fill(id: number | string |
|
|
16
|
+
bid(id: number | string | BigNumber, exchange: string, dstFee: number | string | BigNumber, slippagePercent: number | string | BigNumber, data: string | number[]): NonPayableTransactionObject<void>;
|
|
17
|
+
fill(id: number | string | BigNumber, feeExchange: string, feeMinAmountOut: number | string | BigNumber, feeData: string | number[]): NonPayableTransactionObject<void>;
|
|
19
18
|
owners(arg0: string): NonPayableTransactionObject<boolean>;
|
|
20
19
|
rescue(token: string): NonPayableTransactionObject<void>;
|
|
21
20
|
twap(): NonPayableTransactionObject<string>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type BN from "bn.js";
|
|
3
2
|
import type BigNumber from "bignumber.js";
|
|
4
3
|
import type { ContractOptions } from "web3-eth-contract";
|
|
5
4
|
import type { EventLog } from "web3-core";
|
|
@@ -31,16 +30,16 @@ export interface MockDeflationaryToken extends BaseContract {
|
|
|
31
30
|
clone(): MockDeflationaryToken;
|
|
32
31
|
methods: {
|
|
33
32
|
allowance(owner: string, spender: string): NonPayableTransactionObject<string>;
|
|
34
|
-
approve(spender: string, amount: number | string |
|
|
33
|
+
approve(spender: string, amount: number | string | BigNumber): NonPayableTransactionObject<boolean>;
|
|
35
34
|
balanceOf(account: string): NonPayableTransactionObject<string>;
|
|
36
35
|
decimals(): NonPayableTransactionObject<string>;
|
|
37
|
-
decreaseAllowance(spender: string, subtractedValue: number | string |
|
|
38
|
-
increaseAllowance(spender: string, addedValue: number | string |
|
|
36
|
+
decreaseAllowance(spender: string, subtractedValue: number | string | BigNumber): NonPayableTransactionObject<boolean>;
|
|
37
|
+
increaseAllowance(spender: string, addedValue: number | string | BigNumber): NonPayableTransactionObject<boolean>;
|
|
39
38
|
name(): NonPayableTransactionObject<string>;
|
|
40
39
|
symbol(): NonPayableTransactionObject<string>;
|
|
41
40
|
totalSupply(): NonPayableTransactionObject<string>;
|
|
42
|
-
transfer(to: string, amount: number | string |
|
|
43
|
-
transferFrom(from: string, to: string, amount: number | string |
|
|
41
|
+
transfer(to: string, amount: number | string | BigNumber): NonPayableTransactionObject<boolean>;
|
|
42
|
+
transferFrom(from: string, to: string, amount: number | string | BigNumber): NonPayableTransactionObject<boolean>;
|
|
44
43
|
};
|
|
45
44
|
events: {
|
|
46
45
|
Approval(cb?: Callback<Approval>): EventEmitter;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type BN from "bn.js";
|
|
3
2
|
import type BigNumber from "bignumber.js";
|
|
4
3
|
import type { ContractOptions } from "web3-eth-contract";
|
|
5
4
|
import type { EventLog } from "web3-core";
|
|
@@ -14,10 +13,10 @@ export interface MockExchange extends BaseContract {
|
|
|
14
13
|
constructor(jsonInterface: any[], address?: string, options?: ContractOptions): MockExchange;
|
|
15
14
|
clone(): MockExchange;
|
|
16
15
|
methods: {
|
|
17
|
-
amounts(arg0: number | string |
|
|
18
|
-
getAmountOut(arg0: string, arg1: string, arg2: number | string |
|
|
19
|
-
setMockAmounts(_amounts: (number | string |
|
|
20
|
-
swap(_srcToken: string, _dstToken: string, amountIn: number | string |
|
|
16
|
+
amounts(arg0: number | string | BigNumber): NonPayableTransactionObject<string>;
|
|
17
|
+
getAmountOut(arg0: string, arg1: string, arg2: number | string | BigNumber, arg3: string | number[]): NonPayableTransactionObject<string>;
|
|
18
|
+
setMockAmounts(_amounts: (number | string | BigNumber)[]): NonPayableTransactionObject<void>;
|
|
19
|
+
swap(_srcToken: string, _dstToken: string, amountIn: number | string | BigNumber, arg3: number | string | BigNumber, arg4: string | number[]): NonPayableTransactionObject<void>;
|
|
21
20
|
};
|
|
22
21
|
events: {
|
|
23
22
|
allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type BN from "bn.js";
|
|
3
2
|
import type BigNumber from "bignumber.js";
|
|
4
3
|
import type { EventEmitter } from "events";
|
|
5
4
|
import type { EventLog, PromiEvent, TransactionReceipt } from "web3-core/types";
|
|
@@ -7,7 +6,7 @@ import type { Contract } from "web3-eth-contract";
|
|
|
7
6
|
export interface EstimateGasOptions {
|
|
8
7
|
from?: string;
|
|
9
8
|
gas?: number;
|
|
10
|
-
value?: number | string |
|
|
9
|
+
value?: number | string | BigNumber;
|
|
11
10
|
}
|
|
12
11
|
export interface EventOptions {
|
|
13
12
|
filter?: object;
|
|
@@ -24,18 +23,18 @@ export interface ContractEventEmitter<T> extends EventEmitter {
|
|
|
24
23
|
on(event: "error", listener: (error: Error) => void): this;
|
|
25
24
|
}
|
|
26
25
|
export interface NonPayableTx {
|
|
27
|
-
nonce?: string | number |
|
|
28
|
-
chainId?: string | number |
|
|
26
|
+
nonce?: string | number | BigNumber;
|
|
27
|
+
chainId?: string | number | BigNumber;
|
|
29
28
|
from?: string;
|
|
30
29
|
to?: string;
|
|
31
30
|
data?: string;
|
|
32
|
-
gas?: string | number |
|
|
33
|
-
maxPriorityFeePerGas?: string | number |
|
|
34
|
-
maxFeePerGas?: string | number |
|
|
35
|
-
gasPrice?: string | number |
|
|
31
|
+
gas?: string | number | BigNumber;
|
|
32
|
+
maxPriorityFeePerGas?: string | number | BigNumber;
|
|
33
|
+
maxFeePerGas?: string | number | BigNumber;
|
|
34
|
+
gasPrice?: string | number | BigNumber;
|
|
36
35
|
}
|
|
37
36
|
export interface PayableTx extends NonPayableTx {
|
|
38
|
-
value?: string | number |
|
|
37
|
+
value?: string | number | BigNumber;
|
|
39
38
|
}
|
|
40
39
|
export interface NonPayableTransactionObject<T> {
|
|
41
40
|
arguments: any[];
|
|
@@ -51,5 +50,5 @@ export interface PayableTransactionObject<T> {
|
|
|
51
50
|
estimateGas(tx?: PayableTx): Promise<number>;
|
|
52
51
|
encodeABI(): string;
|
|
53
52
|
}
|
|
54
|
-
export type BlockType = "latest" | "pending" | "genesis" | "earliest" | number |
|
|
53
|
+
export type BlockType = "latest" | "pending" | "genesis" | "earliest" | number | BigNumber;
|
|
55
54
|
export type BaseContract = Omit<Contract, "clone" | "once">;
|