@curvefi/api 2.47.0 → 2.47.1
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/README.md +2 -1
- package/lib/index.d.ts +1 -1
- package/lib/router.d.ts +1 -1
- package/lib/router.js +26 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1052,7 +1052,8 @@ import curve from "@curvefi/api";
|
|
|
1052
1052
|
// OR await curve.router.getBestRouteAndOutput('0x6B175474E89094C44Da98b954EedeAC495271d0F', '0xD533a949740bb3306d119CC777fa900bA034cd52', '1000');
|
|
1053
1053
|
const expected = await curve.router.expected('DAI', 'CRV', '1000');
|
|
1054
1054
|
// OR await curve.router.expected('0x6B175474E89094C44Da98b954EedeAC495271d0F', '0xD533a949740bb3306d119CC777fa900bA034cd52', '1000');
|
|
1055
|
-
const required = await curve.router.required(
|
|
1055
|
+
const required = await curve.router.required('DAI', 'CRV', expected);
|
|
1056
|
+
// OR await curve.router.required('0x6B175474E89094C44Da98b954EedeAC495271d0F', '0xD533a949740bb3306d119CC777fa900bA034cd52', expected);
|
|
1056
1057
|
const priceImpact = await curve.router.priceImpact('DAI', 'CRV', '1000');
|
|
1057
1058
|
// OR await curve.router.priceImpact('0x6B175474E89094C44Da98b954EedeAC495271d0F', '0xD533a949740bb3306d119CC777fa900bA034cd52', '1000');
|
|
1058
1059
|
const args = curve.router.getArgs(route);
|
package/lib/index.d.ts
CHANGED
|
@@ -188,7 +188,7 @@ declare const curve: {
|
|
|
188
188
|
_secondBaseTokens: string[];
|
|
189
189
|
};
|
|
190
190
|
expected: (inputCoin: string, outputCoin: string, amount: string | number) => Promise<string>;
|
|
191
|
-
required: (
|
|
191
|
+
required: (inputCoin: string, outputCoin: string, outAmount: string | number) => Promise<string>;
|
|
192
192
|
priceImpact: (inputCoin: string, outputCoin: string, amount: string | number) => Promise<number>;
|
|
193
193
|
isApproved: (inputCoin: string, amount: string | number) => Promise<boolean>;
|
|
194
194
|
approve: (inputCoin: string, amount: string | number) => Promise<string[]>;
|
package/lib/router.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare const getArgs: (route: IRoute) => {
|
|
|
14
14
|
_secondBaseTokens: string[];
|
|
15
15
|
};
|
|
16
16
|
export declare const swapExpected: (inputCoin: string, outputCoin: string, amount: number | string) => Promise<string>;
|
|
17
|
-
export declare const swapRequired: (
|
|
17
|
+
export declare const swapRequired: (inputCoin: string, outputCoin: string, outAmount: number | string) => Promise<string>;
|
|
18
18
|
export declare const swapPriceImpact: (inputCoin: string, outputCoin: string, amount: number | string) => Promise<number>;
|
|
19
19
|
export declare const swapIsApproved: (inputCoin: string, amount: number | string) => Promise<boolean>;
|
|
20
20
|
export declare const swapApproveEstimateGas: (inputCoin: string, amount: number | string) => Promise<number>;
|
package/lib/router.js
CHANGED
|
@@ -598,28 +598,37 @@ export var swapExpected = function (inputCoin, outputCoin, amount) { return __aw
|
|
|
598
598
|
}
|
|
599
599
|
});
|
|
600
600
|
}); };
|
|
601
|
-
export var swapRequired = function (
|
|
602
|
-
var inputCoinAddress, outputCoinAddress,
|
|
603
|
-
return __generator(this, function (
|
|
604
|
-
switch (
|
|
601
|
+
export var swapRequired = function (inputCoin, outputCoin, outAmount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
602
|
+
var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, _outAmount, p1, p2, approximateRequiredAmount, route, contract, _c, _route, _swapParams, _pools, _basePools, _baseTokens, _secondBasePools, _secondBaseTokens, _required;
|
|
603
|
+
return __generator(this, function (_d) {
|
|
604
|
+
switch (_d.label) {
|
|
605
605
|
case 0:
|
|
606
|
-
inputCoinAddress =
|
|
607
|
-
outputCoinAddress =
|
|
608
|
-
_a = _getCoinDecimals(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _a[0], outputCoinDecimals = _a[1];
|
|
606
|
+
_a = _getCoinAddresses(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
607
|
+
_b = _getCoinDecimals(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _b[0], outputCoinDecimals = _b[1];
|
|
609
608
|
_outAmount = parseUnits(outAmount, outputCoinDecimals);
|
|
609
|
+
return [4 /*yield*/, _getUsdRate(inputCoinAddress)];
|
|
610
|
+
case 1:
|
|
611
|
+
p1 = (_d.sent()) || 1;
|
|
612
|
+
return [4 /*yield*/, _getUsdRate(outputCoinAddress)];
|
|
613
|
+
case 2:
|
|
614
|
+
p2 = (_d.sent()) || 1;
|
|
615
|
+
approximateRequiredAmount = Number(outAmount) * p2 / p1;
|
|
616
|
+
return [4 /*yield*/, _getBestRoute(inputCoinAddress, outputCoinAddress, approximateRequiredAmount)];
|
|
617
|
+
case 3:
|
|
618
|
+
route = _d.sent();
|
|
610
619
|
contract = curve.contracts[curve.constants.ALIASES.router].contract;
|
|
611
|
-
|
|
620
|
+
_c = _getExchangeArgs(route), _route = _c._route, _swapParams = _c._swapParams, _pools = _c._pools, _basePools = _c._basePools, _baseTokens = _c._baseTokens, _secondBasePools = _c._secondBasePools, _secondBaseTokens = _c._secondBaseTokens;
|
|
612
621
|
_required = 0;
|
|
613
|
-
if (!("get_dx(address[11],uint256[5][5],uint256,address[5],address[5],address[5],address[5],address[5])" in contract)) return [3 /*break*/,
|
|
622
|
+
if (!("get_dx(address[11],uint256[5][5],uint256,address[5],address[5],address[5],address[5],address[5])" in contract)) return [3 /*break*/, 5];
|
|
614
623
|
return [4 /*yield*/, contract.get_dx(_route, _swapParams, _outAmount, _pools, _basePools, _baseTokens, _secondBasePools, _secondBaseTokens, curve.constantOptions)];
|
|
615
|
-
case
|
|
616
|
-
_required =
|
|
617
|
-
return [3 /*break*/,
|
|
618
|
-
case
|
|
619
|
-
case
|
|
620
|
-
_required =
|
|
621
|
-
|
|
622
|
-
case
|
|
624
|
+
case 4:
|
|
625
|
+
_required = _d.sent();
|
|
626
|
+
return [3 /*break*/, 7];
|
|
627
|
+
case 5: return [4 /*yield*/, contract.get_dx(_route, _swapParams, _outAmount, _pools, _basePools, _baseTokens, curve.constantOptions)];
|
|
628
|
+
case 6:
|
|
629
|
+
_required = _d.sent();
|
|
630
|
+
_d.label = 7;
|
|
631
|
+
case 7: return [2 /*return*/, curve.formatUnits(_required, inputCoinDecimals)];
|
|
623
632
|
}
|
|
624
633
|
});
|
|
625
634
|
}); };
|