@shapeshiftoss/swapper 19.0.0 → 20.1.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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/exactOutputFiltering.test.d.ts +1 -0
- package/dist/cjs/exactOutputFiltering.test.js +70 -0
- package/dist/cjs/swapper.d.ts +3 -3
- package/dist/cjs/swapper.js +29 -6
- package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossStepData.d.ts +1 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossStepData.js +2 -2
- package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossTradeContext.js +1 -0
- package/dist/cjs/swappers/BebopSwapper/utils/getBebopStepData.d.ts +1 -0
- package/dist/cjs/swappers/BebopSwapper/utils/getBebopStepData.js +2 -2
- package/dist/cjs/swappers/BebopSwapper/utils/getBebopTradeContext.js +1 -0
- package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +5 -1
- package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeRate.js +11 -2
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayTradeContext.d.ts +2 -1
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayTradeContext.js +2 -1
- package/dist/cjs/swappers/BobGatewaySwapper/utils/helpers.d.ts +2 -1
- package/dist/cjs/swappers/BobGatewaySwapper/utils/helpers.js +2 -1
- package/dist/cjs/swappers/ChainflipSwapper/ChainflipSwapper.js +1 -0
- package/dist/cjs/swappers/ChainflipSwapper/checkTradeStatus.test.d.ts +1 -0
- package/dist/cjs/swappers/ChainflipSwapper/checkTradeStatus.test.js +48 -0
- package/dist/cjs/swappers/ChainflipSwapper/endpoints.js +5 -2
- package/dist/cjs/swappers/ChainflipSwapper/types.d.ts +3 -0
- package/dist/cjs/swappers/DebridgeSwapper/utils/getDebridgeStepData.d.ts +1 -0
- package/dist/cjs/swappers/DebridgeSwapper/utils/getDebridgeStepData.js +2 -2
- package/dist/cjs/swappers/DebridgeSwapper/utils/getDebridgeTradeContext.js +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/NearIntentsSwapper.js +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/checkTradeStatus.test.d.ts +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/checkTradeStatus.test.js +52 -0
- package/dist/cjs/swappers/NearIntentsSwapper/constants.d.ts +1 -1
- package/dist/cjs/swappers/NearIntentsSwapper/constants.js +4 -3
- package/dist/cjs/swappers/NearIntentsSwapper/endpoints.js +4 -1
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.d.ts +2 -1
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +14 -9
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.d.ts +2 -1
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +14 -9
- package/dist/cjs/swappers/NearIntentsSwapper/types.d.ts +3 -1
- package/dist/cjs/swappers/NearIntentsSwapper/utils/exactOutput.test.d.ts +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/exactOutput.test.js +61 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/getNearIntentsTradeContext.d.ts +2 -2
- package/dist/cjs/swappers/NearIntentsSwapper/utils/getNearIntentsTradeContext.js +4 -2
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers.d.ts +5 -5
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers.js +30 -26
- package/dist/cjs/swappers/NearIntentsSwapper/utils/quoteDeadline.test.d.ts +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/quoteDeadline.test.js +28 -0
- package/dist/cjs/swappers/PortalsSwapper/endpoints.js +51 -47
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +1 -1
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +1 -1
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchAxelarscanStatus.d.ts +0 -1
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchAxelarscanStatus.js +3 -6
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchPortalsTradeOrder.js +6 -3
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchSquidStatus.d.ts +0 -1
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchSquidStatus.js +1 -8
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsStepData.d.ts +1 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsStepData.js +16 -8
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsStepData.test.d.ts +1 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsStepData.test.js +70 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsTradeContext.d.ts +3 -2
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsTradeContext.js +34 -16
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsTradeContext.test.d.ts +1 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsTradeContext.test.js +93 -0
- package/dist/cjs/swappers/RelaySwapper/endpoints.js +9 -18
- package/dist/cjs/swappers/RelaySwapper/getTradeQuote/getTradeQuote.d.ts +2 -1
- package/dist/cjs/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +5 -2
- package/dist/cjs/swappers/RelaySwapper/getTradeRate/getTradeRate.d.ts +2 -1
- package/dist/cjs/swappers/RelaySwapper/getTradeRate/getTradeRate.js +5 -2
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayTradeContext.d.ts +2 -2
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayTradeContext.js +22 -10
- package/dist/cjs/swappers/RelaySwapper/utils/helpers.d.ts +2 -2
- package/dist/cjs/swappers/RelaySwapper/utils/relayStatus.d.ts +8 -0
- package/dist/cjs/swappers/RelaySwapper/utils/relayStatus.js +39 -0
- package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +18 -1
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.d.ts +1 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.js +2 -2
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioTradeContext.js +6 -1
- package/dist/cjs/swappers/ThorchainSwapper/generated/generatedThorLongtailTokens.json +1 -0
- package/dist/cjs/types.d.ts +21 -2
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils/cowswap/index.d.ts +4 -1
- package/dist/cjs/utils/cowswap/index.js +5 -1
- package/dist/cjs/utils/helpers.d.ts +9 -0
- package/dist/cjs/utils/helpers.js +23 -1
- package/dist/cjs/utils/helpers.test.js +41 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/exactOutputFiltering.test.d.ts +1 -0
- package/dist/esm/exactOutputFiltering.test.js +68 -0
- package/dist/esm/swapper.d.ts +3 -3
- package/dist/esm/swapper.js +29 -6
- package/dist/esm/swappers/AcrossSwapper/utils/getAcrossStepData.d.ts +1 -0
- package/dist/esm/swappers/AcrossSwapper/utils/getAcrossStepData.js +2 -2
- package/dist/esm/swappers/AcrossSwapper/utils/getAcrossTradeContext.js +1 -0
- package/dist/esm/swappers/BebopSwapper/utils/getBebopStepData.d.ts +1 -0
- package/dist/esm/swappers/BebopSwapper/utils/getBebopStepData.js +2 -2
- package/dist/esm/swappers/BebopSwapper/utils/getBebopTradeContext.js +1 -0
- package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +5 -1
- package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeRate.js +11 -2
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayTradeContext.d.ts +2 -1
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayTradeContext.js +2 -1
- package/dist/esm/swappers/BobGatewaySwapper/utils/helpers.d.ts +2 -1
- package/dist/esm/swappers/BobGatewaySwapper/utils/helpers.js +2 -1
- package/dist/esm/swappers/ChainflipSwapper/ChainflipSwapper.js +1 -0
- package/dist/esm/swappers/ChainflipSwapper/checkTradeStatus.test.d.ts +1 -0
- package/dist/esm/swappers/ChainflipSwapper/checkTradeStatus.test.js +46 -0
- package/dist/esm/swappers/ChainflipSwapper/endpoints.js +5 -2
- package/dist/esm/swappers/ChainflipSwapper/types.d.ts +3 -0
- package/dist/esm/swappers/DebridgeSwapper/utils/getDebridgeStepData.d.ts +1 -0
- package/dist/esm/swappers/DebridgeSwapper/utils/getDebridgeStepData.js +2 -2
- package/dist/esm/swappers/DebridgeSwapper/utils/getDebridgeTradeContext.js +1 -0
- package/dist/esm/swappers/NearIntentsSwapper/NearIntentsSwapper.js +1 -0
- package/dist/esm/swappers/NearIntentsSwapper/checkTradeStatus.test.d.ts +1 -0
- package/dist/esm/swappers/NearIntentsSwapper/checkTradeStatus.test.js +50 -0
- package/dist/esm/swappers/NearIntentsSwapper/constants.d.ts +1 -1
- package/dist/esm/swappers/NearIntentsSwapper/constants.js +3 -2
- package/dist/esm/swappers/NearIntentsSwapper/endpoints.js +6 -3
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.d.ts +2 -1
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +7 -3
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.d.ts +2 -1
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +7 -3
- package/dist/esm/swappers/NearIntentsSwapper/types.d.ts +3 -1
- package/dist/esm/swappers/NearIntentsSwapper/utils/exactOutput.test.d.ts +1 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/exactOutput.test.js +59 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/getNearIntentsTradeContext.d.ts +2 -2
- package/dist/esm/swappers/NearIntentsSwapper/utils/getNearIntentsTradeContext.js +4 -2
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers.d.ts +5 -5
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers.js +32 -28
- package/dist/esm/swappers/NearIntentsSwapper/utils/quoteDeadline.test.d.ts +1 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/quoteDeadline.test.js +26 -0
- package/dist/esm/swappers/PortalsSwapper/endpoints.js +53 -49
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +1 -1
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +1 -1
- package/dist/esm/swappers/PortalsSwapper/utils/fetchAxelarscanStatus.d.ts +0 -1
- package/dist/esm/swappers/PortalsSwapper/utils/fetchAxelarscanStatus.js +2 -4
- package/dist/esm/swappers/PortalsSwapper/utils/fetchPortalsTradeOrder.js +6 -3
- package/dist/esm/swappers/PortalsSwapper/utils/fetchSquidStatus.d.ts +0 -1
- package/dist/esm/swappers/PortalsSwapper/utils/fetchSquidStatus.js +0 -6
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsStepData.d.ts +1 -0
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsStepData.js +13 -5
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsStepData.test.d.ts +1 -0
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsStepData.test.js +68 -0
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsTradeContext.d.ts +3 -2
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsTradeContext.js +35 -17
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsTradeContext.test.d.ts +1 -0
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsTradeContext.test.js +91 -0
- package/dist/esm/swappers/RelaySwapper/endpoints.js +11 -20
- package/dist/esm/swappers/RelaySwapper/getTradeQuote/getTradeQuote.d.ts +2 -1
- package/dist/esm/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +3 -1
- package/dist/esm/swappers/RelaySwapper/getTradeRate/getTradeRate.d.ts +2 -1
- package/dist/esm/swappers/RelaySwapper/getTradeRate/getTradeRate.js +3 -1
- package/dist/esm/swappers/RelaySwapper/utils/getRelayTradeContext.d.ts +2 -2
- package/dist/esm/swappers/RelaySwapper/utils/getRelayTradeContext.js +23 -11
- package/dist/esm/swappers/RelaySwapper/utils/helpers.d.ts +2 -2
- package/dist/esm/swappers/RelaySwapper/utils/relayStatus.d.ts +8 -0
- package/dist/esm/swappers/RelaySwapper/utils/relayStatus.js +32 -0
- package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +18 -1
- package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.d.ts +1 -0
- package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.js +2 -2
- package/dist/esm/swappers/SunioSwapper/utils/getSunioTradeContext.js +6 -1
- package/dist/esm/swappers/ThorchainSwapper/generated/generatedThorLongtailTokens.json +1 -0
- package/dist/esm/types.d.ts +21 -2
- package/dist/esm/types.js +2 -0
- package/dist/esm/utils/cowswap/index.d.ts +4 -1
- package/dist/esm/utils/cowswap/index.js +3 -0
- package/dist/esm/utils/helpers.d.ts +9 -0
- package/dist/esm/utils/helpers.js +20 -0
- package/dist/esm/utils/helpers.test.js +42 -1
- package/package.json +6 -6
|
@@ -2,23 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPortalsStepData = void 0;
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
+
const utils_1 = require("@shapeshiftoss/utils");
|
|
5
6
|
const monads_1 = require("@sniptt/monads");
|
|
6
|
-
const
|
|
7
|
+
const utils_2 = require("../../../utils");
|
|
7
8
|
const evm_1 = require("../../../utils/evm");
|
|
8
9
|
const fetchPortalsTradeOrder_1 = require("./fetchPortalsTradeOrder");
|
|
9
10
|
async function getPortalsStepData(args) {
|
|
10
|
-
const { tx, sellAsset, spenderAddress, input, deps } = args;
|
|
11
|
+
const { tx, sellAsset, sellAmountCryptoBaseUnit, spenderAddress, input, deps } = args;
|
|
11
12
|
const adapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
|
|
12
13
|
const supportsEIP1559 = 'supportsEIP1559' in input ? input.supportsEIP1559 : false;
|
|
13
14
|
if (args.type === 'rate') {
|
|
14
15
|
try {
|
|
15
16
|
// No placeholder estimation for provider built routes - overridden estimation (approval
|
|
16
|
-
// state need not exist yet) with the Portals estimate endpoint as
|
|
17
|
+
// state need not exist yet) with the Portals order and estimate endpoint as fallbacks
|
|
17
18
|
const gasLimit = await (async () => {
|
|
18
19
|
try {
|
|
19
20
|
const gasLimit = await (0, evm_1.estimateGasWithStateOverride)({
|
|
20
21
|
sellAsset,
|
|
21
|
-
sellAmountCryptoBaseUnit
|
|
22
|
+
sellAmountCryptoBaseUnit,
|
|
22
23
|
from: tx.from,
|
|
23
24
|
spenderAddress,
|
|
24
25
|
to: tx.to,
|
|
@@ -28,6 +29,10 @@ async function getPortalsStepData(args) {
|
|
|
28
29
|
return gasLimit;
|
|
29
30
|
}
|
|
30
31
|
catch {
|
|
32
|
+
// Portals only carry a tx gas limit on the bridge routes their estimate endpoint zeroes
|
|
33
|
+
const { gasLimit: txGasLimit } = tx;
|
|
34
|
+
if (txGasLimit && (0, utils_1.bnOrZero)(txGasLimit).gt(0))
|
|
35
|
+
return txGasLimit;
|
|
31
36
|
const quoteEstimateResponse = await (0, fetchPortalsTradeOrder_1.fetchPortalsTradeEstimate)({
|
|
32
37
|
inputToken: args.inputToken,
|
|
33
38
|
outputToken: args.outputToken,
|
|
@@ -35,7 +40,10 @@ async function getPortalsStepData(args) {
|
|
|
35
40
|
slippageTolerancePercentage: args.slippageTolerancePercentage,
|
|
36
41
|
swapperConfig: deps.config,
|
|
37
42
|
});
|
|
38
|
-
|
|
43
|
+
const estimatedGasLimit = quoteEstimateResponse.context.gasLimit.toString();
|
|
44
|
+
if ((0, utils_1.bnOrZero)(estimatedGasLimit).lte(0))
|
|
45
|
+
throw new Error('no Portals gas limit');
|
|
46
|
+
return estimatedGasLimit;
|
|
39
47
|
}
|
|
40
48
|
})();
|
|
41
49
|
const networkFeeCryptoBaseUnit = await (0, evm_1.getEvmNetworkFeeCryptoBaseUnit)({
|
|
@@ -47,7 +55,7 @@ async function getPortalsStepData(args) {
|
|
|
47
55
|
return (0, monads_1.Ok)(stepData);
|
|
48
56
|
}
|
|
49
57
|
catch (error) {
|
|
50
|
-
return (0, monads_1.Err)((0,
|
|
58
|
+
return (0, monads_1.Err)((0, utils_2.makeNetworkFeeEstimationFailedErr)('getPortalsStepData', error));
|
|
51
59
|
}
|
|
52
60
|
}
|
|
53
61
|
const transactionData = {
|
|
@@ -68,7 +76,7 @@ async function getPortalsStepData(args) {
|
|
|
68
76
|
supportsEIP1559,
|
|
69
77
|
stateOverride: {
|
|
70
78
|
sellAsset,
|
|
71
|
-
sellAmountCryptoBaseUnit
|
|
79
|
+
sellAmountCryptoBaseUnit,
|
|
72
80
|
spenderAddress,
|
|
73
81
|
},
|
|
74
82
|
});
|
|
@@ -76,7 +84,7 @@ async function getPortalsStepData(args) {
|
|
|
76
84
|
return (0, monads_1.Ok)(stepData);
|
|
77
85
|
}
|
|
78
86
|
catch (error) {
|
|
79
|
-
return (0, monads_1.Err)((0,
|
|
87
|
+
return (0, monads_1.Err)((0, utils_2.makeNetworkFeeEstimationFailedErr)('getPortalsStepData', error));
|
|
80
88
|
}
|
|
81
89
|
}
|
|
82
90
|
exports.getPortalsStepData = getPortalsStepData;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const evm_1 = require("../../../utils/evm");
|
|
5
|
+
const assets_1 = require("../../../utils/test-data/assets");
|
|
6
|
+
const fetchPortalsTradeOrder_1 = require("./fetchPortalsTradeOrder");
|
|
7
|
+
const getPortalsStepData_1 = require("./getPortalsStepData");
|
|
8
|
+
vitest_1.vi.mock('../../../utils/evm', async (importOriginal) => ({
|
|
9
|
+
...(await importOriginal()),
|
|
10
|
+
estimateGasWithStateOverride: vitest_1.vi.fn(),
|
|
11
|
+
}));
|
|
12
|
+
vitest_1.vi.mock('./fetchPortalsTradeOrder', async (importOriginal) => ({
|
|
13
|
+
...(await importOriginal()),
|
|
14
|
+
fetchPortalsTradeEstimate: vitest_1.vi.fn(),
|
|
15
|
+
}));
|
|
16
|
+
const GAS_PRICE = '1000000000';
|
|
17
|
+
const deps = {
|
|
18
|
+
assertGetEvmChainAdapter: () => ({
|
|
19
|
+
getGasFeeData: () => Promise.resolve({
|
|
20
|
+
average: { gasPrice: GAS_PRICE, maxFeePerGas: '0', maxPriorityFeePerGas: '0' },
|
|
21
|
+
}),
|
|
22
|
+
}),
|
|
23
|
+
config: {},
|
|
24
|
+
};
|
|
25
|
+
const tx = (gasLimit) => ({
|
|
26
|
+
to: '0x4cd00e387622c35bddb9b4c962c136462338bc31',
|
|
27
|
+
from: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
|
|
28
|
+
data: '0xdeadbeef',
|
|
29
|
+
value: '0',
|
|
30
|
+
gasLimit,
|
|
31
|
+
});
|
|
32
|
+
const rate = (portalsTx) => (0, getPortalsStepData_1.getPortalsStepData)({
|
|
33
|
+
type: 'rate',
|
|
34
|
+
input: { supportsEIP1559: false },
|
|
35
|
+
deps,
|
|
36
|
+
tx: portalsTx,
|
|
37
|
+
sellAsset: assets_1.USDC_MAINNET,
|
|
38
|
+
sellAmountCryptoBaseUnit: '1000000000',
|
|
39
|
+
spenderAddress: '0x4cd00e387622c35bddb9b4c962c136462338bc31',
|
|
40
|
+
inputToken: 'ethereum:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
41
|
+
outputToken: 'arbitrum:0xaf88d065e77c8cc2239327c5edb3a432268e5831',
|
|
42
|
+
inputAmount: '1000000000',
|
|
43
|
+
slippageTolerancePercentage: 2.5,
|
|
44
|
+
});
|
|
45
|
+
const estimateEndpointGasLimit = (gasLimit) => vitest_1.vi.mocked(fetchPortalsTradeOrder_1.fetchPortalsTradeEstimate).mockResolvedValue({
|
|
46
|
+
context: { gasLimit },
|
|
47
|
+
});
|
|
48
|
+
(0, vitest_1.describe)('getPortalsStepData rate gas limit', () => {
|
|
49
|
+
(0, vitest_1.beforeEach)(() => vitest_1.vi.clearAllMocks());
|
|
50
|
+
(0, vitest_1.it)('falls back to the order gas limit on bridge routes the estimate endpoint zeroes', async () => {
|
|
51
|
+
vitest_1.vi.mocked(evm_1.estimateGasWithStateOverride).mockRejectedValue(new Error('execution reverted'));
|
|
52
|
+
estimateEndpointGasLimit(0);
|
|
53
|
+
const actual = await rate(tx('76384'));
|
|
54
|
+
(0, vitest_1.expect)(actual.unwrap()).toEqual({ networkFeeCryptoBaseUnit: '76384000000000' });
|
|
55
|
+
(0, vitest_1.expect)(fetchPortalsTradeOrder_1.fetchPortalsTradeEstimate).not.toHaveBeenCalled();
|
|
56
|
+
});
|
|
57
|
+
(0, vitest_1.it)('falls back to the estimate endpoint when the order carries no gas limit', async () => {
|
|
58
|
+
vitest_1.vi.mocked(evm_1.estimateGasWithStateOverride).mockRejectedValue(new Error('execution reverted'));
|
|
59
|
+
estimateEndpointGasLimit(273203);
|
|
60
|
+
const actual = await rate(tx(undefined));
|
|
61
|
+
(0, vitest_1.expect)(actual.unwrap()).toEqual({ networkFeeCryptoBaseUnit: '273203000000000' });
|
|
62
|
+
});
|
|
63
|
+
(0, vitest_1.it)('errors rather than pricing a zero gas limit as a free trade', async () => {
|
|
64
|
+
vitest_1.vi.mocked(evm_1.estimateGasWithStateOverride).mockRejectedValue(new Error('execution reverted'));
|
|
65
|
+
estimateEndpointGasLimit(0);
|
|
66
|
+
const actual = await rate(tx(undefined));
|
|
67
|
+
(0, vitest_1.expect)(actual.isErr()).toBe(true);
|
|
68
|
+
(0, vitest_1.expect)(actual.unwrapErr().message).toContain('getPortalsStepData');
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -10,16 +10,17 @@ type PortalsTradeContext = {
|
|
|
10
10
|
stepDataArgs: {
|
|
11
11
|
deps: SwapperDeps;
|
|
12
12
|
sellAsset: Asset;
|
|
13
|
+
sellAmountCryptoBaseUnit: string;
|
|
13
14
|
spenderAddress: string;
|
|
14
15
|
tx: PortalsTx;
|
|
15
16
|
};
|
|
16
17
|
};
|
|
17
|
-
export declare const getPortalsTradeContext: ({ input, deps, sellChainId,
|
|
18
|
+
export declare const getPortalsTradeContext: ({ input, deps, sellChainId, orderContext, outputToken, tx, }: {
|
|
18
19
|
input: PortalsTradeQuoteInput | PortalsTradeRateInput;
|
|
19
20
|
deps: SwapperDeps;
|
|
20
21
|
sellChainId: PortalsSupportedChainId;
|
|
21
|
-
inputToken: string;
|
|
22
22
|
orderContext: PortalsTradeOrderResponse['context'];
|
|
23
|
+
outputToken: string;
|
|
23
24
|
tx: PortalsTx;
|
|
24
25
|
}) => Result<PortalsTradeContext, SwapErrorRight>;
|
|
25
26
|
export {};
|
|
@@ -7,11 +7,26 @@ const types_1 = require("../../../types");
|
|
|
7
7
|
const utils_2 = require("../../../utils");
|
|
8
8
|
const affiliateFee_1 = require("../../../utils/affiliateFee");
|
|
9
9
|
const helpers_1 = require("./helpers");
|
|
10
|
-
const getPortalsTradeContext = ({ input, deps, sellChainId,
|
|
11
|
-
const { sellAsset, buyAsset, affiliateBps
|
|
12
|
-
const { orderId, outputAmount, minOutputAmount, target, feeAmount, feeToken } = orderContext;
|
|
10
|
+
const getPortalsTradeContext = ({ input, deps, sellChainId, orderContext, outputToken, tx, }) => {
|
|
11
|
+
const { sellAsset, buyAsset, affiliateBps } = input;
|
|
12
|
+
const { orderId, inputAmount, outputAmount, minOutputAmount, target, feeAmount, feeToken, slippageTolerancePercentage, } = orderContext;
|
|
13
|
+
// Portals can fill less than we asked for - price against what the transaction actually spends
|
|
14
|
+
const sellAmountIncludingProtocolFeesCryptoBaseUnit = inputAmount;
|
|
13
15
|
const isCrossChain = sellAsset.chainId !== buyAsset.chainId;
|
|
14
|
-
|
|
16
|
+
// Portals report the slippage they applied, not the one we requested - bridge routes apply none
|
|
17
|
+
const appliedSlippageDecimal = (0, utils_1.bnOrZero)(slippageTolerancePercentage).div(100);
|
|
18
|
+
// Unvalidated orders report the post-slippage minimum in both amount fields
|
|
19
|
+
const hasSlippageBuffer = (0, utils_1.bnOrZero)(outputAmount).gt(minOutputAmount);
|
|
20
|
+
const preSlippageOutputAmount = (0, utils_1.bnOrZero)(minOutputAmount)
|
|
21
|
+
.div((0, utils_1.bn)(1).minus(appliedSlippageDecimal))
|
|
22
|
+
.toFixed(0);
|
|
23
|
+
const buyAmountAfterFeesCryptoBaseUnit = hasSlippageBuffer
|
|
24
|
+
? outputAmount
|
|
25
|
+
: preSlippageOutputAmount;
|
|
26
|
+
const bufferSlippageDecimal = hasSlippageBuffer
|
|
27
|
+
? (0, utils_1.bnOrZero)(outputAmount).minus(minOutputAmount).div(outputAmount)
|
|
28
|
+
: appliedSlippageDecimal;
|
|
29
|
+
const slippageTolerancePercentageDecimal = utils_1.BigNumber.max(appliedSlippageDecimal, bufferSlippageDecimal).toString();
|
|
15
30
|
const rate = (0, utils_2.getInputOutputRate)({
|
|
16
31
|
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
17
32
|
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
@@ -27,16 +42,13 @@ const getPortalsTradeContext = ({ input, deps, sellChainId, inputToken, orderCon
|
|
|
27
42
|
details: { chainId: sellChainId },
|
|
28
43
|
}));
|
|
29
44
|
}
|
|
30
|
-
// Portals
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.div((0, utils_1.bn)(1).minus(actualBufferDecimal))
|
|
38
|
-
.toFixed(0);
|
|
39
|
-
const protocolFeeAsset = feeToken === inputToken ? sellAsset : buyAsset;
|
|
45
|
+
// Portals lower-case echoed tokens, and take their fee in the sell asset on ERC20 sells
|
|
46
|
+
const isBuyAssetFee = feeToken?.toLowerCase() === outputToken.toLowerCase();
|
|
47
|
+
const protocolFeeAsset = isBuyAssetFee ? buyAsset : sellAsset;
|
|
48
|
+
// Portals report an output already net of their fee
|
|
49
|
+
const buyAmountBeforeFeesCryptoBaseUnit = isBuyAssetFee && feeAmount
|
|
50
|
+
? (0, utils_1.bnOrZero)(buyAmountAfterFeesCryptoBaseUnit).plus(feeAmount).toFixed(0)
|
|
51
|
+
: buyAmountAfterFeesCryptoBaseUnit;
|
|
40
52
|
const protocolFees = (() => {
|
|
41
53
|
if (!feeToken || !feeAmount)
|
|
42
54
|
return;
|
|
@@ -54,7 +66,7 @@ const getPortalsTradeContext = ({ input, deps, sellChainId, inputToken, orderCon
|
|
|
54
66
|
rate,
|
|
55
67
|
swapperName: types_1.SwapperName.Portals,
|
|
56
68
|
affiliateBps,
|
|
57
|
-
slippageTolerancePercentageDecimal
|
|
69
|
+
slippageTolerancePercentageDecimal,
|
|
58
70
|
},
|
|
59
71
|
stepCommon: {
|
|
60
72
|
estimatedExecutionTimeMs: isCrossChain ? 300000 : 0,
|
|
@@ -77,7 +89,13 @@ const getPortalsTradeContext = ({ input, deps, sellChainId, inputToken, orderCon
|
|
|
77
89
|
}),
|
|
78
90
|
},
|
|
79
91
|
protocolFees,
|
|
80
|
-
stepDataArgs: {
|
|
92
|
+
stepDataArgs: {
|
|
93
|
+
deps,
|
|
94
|
+
sellAsset,
|
|
95
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
96
|
+
spenderAddress: allowanceContract,
|
|
97
|
+
tx,
|
|
98
|
+
},
|
|
81
99
|
});
|
|
82
100
|
};
|
|
83
101
|
exports.getPortalsTradeContext = getPortalsTradeContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const assets_1 = require("../../../utils/test-data/assets");
|
|
5
|
+
const getPortalsTradeContext_1 = require("./getPortalsTradeContext");
|
|
6
|
+
const deps = {};
|
|
7
|
+
const tx = {
|
|
8
|
+
to: '0x4cd00e387622c35bddb9b4c962c136462338bc31',
|
|
9
|
+
from: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
|
|
10
|
+
data: '0xdeadbeef',
|
|
11
|
+
value: '0',
|
|
12
|
+
};
|
|
13
|
+
const makeInput = (buyAsset = assets_1.USDC_ARBITRUM) => ({
|
|
14
|
+
sellAsset: assets_1.USDC_MAINNET,
|
|
15
|
+
buyAsset,
|
|
16
|
+
affiliateBps: '0',
|
|
17
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit: '4631313795',
|
|
18
|
+
});
|
|
19
|
+
const makeOrderContext = (overrides) => ({
|
|
20
|
+
orderId: 'eaae8ea5-30af-4463-97ab-1c5b1fe7def4',
|
|
21
|
+
target: '0x4cd00e387622c35bddb9b4c962c136462338bc31',
|
|
22
|
+
inputAmount: '4631313795',
|
|
23
|
+
...overrides,
|
|
24
|
+
});
|
|
25
|
+
const unwrap = (args) => (0, getPortalsTradeContext_1.getPortalsTradeContext)(args).unwrap();
|
|
26
|
+
(0, vitest_1.describe)('getPortalsTradeContext', () => {
|
|
27
|
+
(0, vitest_1.it)('does not gross up a bridge route Portals applied no slippage to', () => {
|
|
28
|
+
const { stepCommon, tradeCommon } = unwrap({
|
|
29
|
+
input: makeInput(),
|
|
30
|
+
deps,
|
|
31
|
+
sellChainId: assets_1.USDC_MAINNET.chainId,
|
|
32
|
+
orderContext: makeOrderContext({
|
|
33
|
+
outputAmount: '4616564490',
|
|
34
|
+
minOutputAmount: '4616564490',
|
|
35
|
+
slippageTolerancePercentage: 0,
|
|
36
|
+
}),
|
|
37
|
+
outputToken: 'arbitrum:0xaf88d065e77c8cc2239327c5edb3a432268e5831',
|
|
38
|
+
tx,
|
|
39
|
+
});
|
|
40
|
+
(0, vitest_1.expect)(stepCommon.buyAmountAfterFeesCryptoBaseUnit).toBe('4616564490');
|
|
41
|
+
(0, vitest_1.expect)(tradeCommon.slippageTolerancePercentageDecimal).toBe('0');
|
|
42
|
+
});
|
|
43
|
+
(0, vitest_1.it)('reverses the applied slippage on an unvalidated order collapsed to its minimum', () => {
|
|
44
|
+
const { stepCommon, tradeCommon } = unwrap({
|
|
45
|
+
input: makeInput(assets_1.USDC_MAINNET),
|
|
46
|
+
deps,
|
|
47
|
+
sellChainId: assets_1.USDC_MAINNET.chainId,
|
|
48
|
+
orderContext: makeOrderContext({
|
|
49
|
+
outputAmount: '2360574345',
|
|
50
|
+
minOutputAmount: '2360574345',
|
|
51
|
+
slippageTolerancePercentage: 2.5,
|
|
52
|
+
}),
|
|
53
|
+
outputToken: 'ethereum:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
54
|
+
tx,
|
|
55
|
+
});
|
|
56
|
+
// Within 0.01% of the 2420957576 the same order returns when validated
|
|
57
|
+
(0, vitest_1.expect)(stepCommon.buyAmountAfterFeesCryptoBaseUnit).toBe('2421101892');
|
|
58
|
+
(0, vitest_1.expect)(tradeCommon.slippageTolerancePercentageDecimal).toBe('0.025');
|
|
59
|
+
});
|
|
60
|
+
(0, vitest_1.it)('keeps the reported output of a validated order and advertises the wider buffer', () => {
|
|
61
|
+
const { stepCommon, tradeCommon } = unwrap({
|
|
62
|
+
input: makeInput(assets_1.USDC_MAINNET),
|
|
63
|
+
deps,
|
|
64
|
+
sellChainId: assets_1.USDC_MAINNET.chainId,
|
|
65
|
+
orderContext: makeOrderContext({
|
|
66
|
+
outputAmount: '2420957576',
|
|
67
|
+
minOutputAmount: '2360574345',
|
|
68
|
+
slippageTolerancePercentage: 2.5,
|
|
69
|
+
}),
|
|
70
|
+
outputToken: 'ethereum:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
71
|
+
tx,
|
|
72
|
+
});
|
|
73
|
+
(0, vitest_1.expect)(stepCommon.buyAmountAfterFeesCryptoBaseUnit).toBe('2420957576');
|
|
74
|
+
(0, vitest_1.expect)(tradeCommon.slippageTolerancePercentageDecimal).toBe('0.025');
|
|
75
|
+
});
|
|
76
|
+
(0, vitest_1.it)('prices against the input amount Portals filled rather than the one requested', () => {
|
|
77
|
+
const { stepCommon } = unwrap({
|
|
78
|
+
input: makeInput(),
|
|
79
|
+
deps,
|
|
80
|
+
sellChainId: assets_1.USDC_MAINNET.chainId,
|
|
81
|
+
orderContext: makeOrderContext({
|
|
82
|
+
// Portals withhold 0.01% of the requested 4631313795 on cross-chain orders
|
|
83
|
+
inputAmount: '4630850664',
|
|
84
|
+
outputAmount: '4616564490',
|
|
85
|
+
minOutputAmount: '4616564490',
|
|
86
|
+
slippageTolerancePercentage: 0,
|
|
87
|
+
}),
|
|
88
|
+
outputToken: 'arbitrum:0xaf88d065e77c8cc2239327c5edb3a432268e5831',
|
|
89
|
+
tx,
|
|
90
|
+
});
|
|
91
|
+
(0, vitest_1.expect)(stepCommon.sellAmountIncludingProtocolFeesCryptoBaseUnit).toBe('4630850664');
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -14,6 +14,7 @@ const getTradeRate_1 = require("./getTradeRate/getTradeRate");
|
|
|
14
14
|
const getLatestRelayStatusMessage_1 = require("./utils/getLatestRelayStatusMessage");
|
|
15
15
|
const notifyTransactionIndexing_1 = require("./utils/notifyTransactionIndexing");
|
|
16
16
|
const relayService_1 = require("./utils/relayService");
|
|
17
|
+
const relayStatus_1 = require("./utils/relayStatus");
|
|
17
18
|
// Keep track of the trades we already notified the relay indexer about
|
|
18
19
|
const txIndexingMap = new Map();
|
|
19
20
|
exports.relayApi = {
|
|
@@ -23,6 +24,12 @@ exports.relayApi = {
|
|
|
23
24
|
getTradeRate: (input, deps) => {
|
|
24
25
|
return (0, getTradeRate_1.getTradeRate)(input, deps, constant_1.chainIdToRelayChainId);
|
|
25
26
|
},
|
|
27
|
+
getExactOutputTradeQuote: (input, deps) => {
|
|
28
|
+
return (0, getTradeQuote_1.getExactOutputTradeQuote)(input, deps, constant_1.chainIdToRelayChainId);
|
|
29
|
+
},
|
|
30
|
+
getExactOutputTradeRate: (input, deps) => {
|
|
31
|
+
return (0, getTradeRate_1.getExactOutputTradeRate)(input, deps, constant_1.chainIdToRelayChainId);
|
|
32
|
+
},
|
|
26
33
|
getEvmTransactionFees: evm_1.getEvmTransactionFees,
|
|
27
34
|
getUnsignedEvmTransaction: evm_1.getUnsignedEvmTransaction,
|
|
28
35
|
getUnsignedUtxoTransaction: utxo_1.getUnsignedUtxoTransaction,
|
|
@@ -63,7 +70,7 @@ exports.relayApi = {
|
|
|
63
70
|
}
|
|
64
71
|
// relay.link tracks the swap by its origin chain transaction
|
|
65
72
|
const swapperTxId = txHash;
|
|
66
|
-
const swapperTxLink =
|
|
73
|
+
const swapperTxLink = (0, relayStatus_1.getRelayTrackingLink)(txHash);
|
|
67
74
|
const maybeStatusResponse = await relayService_1.relayService.get(`${config.VITE_RELAY_API_URL}/intents/status/v3?requestId=${relayMetadata.relayId}`, (0, relayService_1.getRelayRequestConfig)(config));
|
|
68
75
|
if (maybeStatusResponse.isErr()) {
|
|
69
76
|
return {
|
|
@@ -75,23 +82,7 @@ exports.relayApi = {
|
|
|
75
82
|
};
|
|
76
83
|
}
|
|
77
84
|
const { data: statusResponse } = maybeStatusResponse.unwrap();
|
|
78
|
-
const status = (()
|
|
79
|
-
switch (statusResponse.status) {
|
|
80
|
-
case 'success':
|
|
81
|
-
return unchained_client_1.TxStatus.Confirmed;
|
|
82
|
-
case 'waiting':
|
|
83
|
-
case 'delayed':
|
|
84
|
-
case 'pending':
|
|
85
|
-
case 'depositing':
|
|
86
|
-
case 'submitted':
|
|
87
|
-
return unchained_client_1.TxStatus.Pending;
|
|
88
|
-
case 'failure':
|
|
89
|
-
case 'refund':
|
|
90
|
-
return unchained_client_1.TxStatus.Failed;
|
|
91
|
-
default:
|
|
92
|
-
return unchained_client_1.TxStatus.Unknown;
|
|
93
|
-
}
|
|
94
|
-
})();
|
|
85
|
+
const status = (0, relayStatus_1.relayStatusToTxStatus)(statusResponse.status);
|
|
95
86
|
// Relay refers to in Txs as "inTxHashes" but to out Txs as simply "txHashes" when they really mean "outTxHashes"
|
|
96
87
|
// One thing to note is that for same-chain Txs, there is no "out Tx" per se since the in Tx *is* the out Tx
|
|
97
88
|
const outTxHashes = statusResponse.txHashes;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Result } from '@sniptt/monads';
|
|
2
2
|
import type { SwapErrorRight, SwapperDeps, TradeQuote } from '../../../types';
|
|
3
3
|
import type { chainIdToRelayChainId as relayChainMapImplementation } from '../constant';
|
|
4
|
-
import type { RelayTradeQuoteInput } from '../utils/types';
|
|
4
|
+
import type { RelayExactOutputTradeQuoteInput, RelayTradeQuoteInput } from '../utils/types';
|
|
5
5
|
export declare const getTradeQuote: (input: RelayTradeQuoteInput, deps: SwapperDeps, relayChainMap: typeof relayChainMapImplementation) => Promise<Result<TradeQuote[], SwapErrorRight>>;
|
|
6
|
+
export declare const getExactOutputTradeQuote: (input: RelayExactOutputTradeQuoteInput, deps: SwapperDeps, relayChainMap: typeof relayChainMapImplementation) => Promise<Result<TradeQuote[], SwapErrorRight>>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTradeQuote = void 0;
|
|
3
|
+
exports.getExactOutputTradeQuote = exports.getTradeQuote = void 0;
|
|
4
4
|
const monads_1 = require("@sniptt/monads");
|
|
5
5
|
const utils_1 = require("../../../utils");
|
|
6
6
|
const helpers_1 = require("../../../utils/helpers");
|
|
7
7
|
const getRelayStepData_1 = require("../utils/getRelayStepData");
|
|
8
8
|
const getRelayTradeContext_1 = require("../utils/getRelayTradeContext");
|
|
9
|
-
const
|
|
9
|
+
const getQuote = async (input, deps, relayChainMap) => {
|
|
10
10
|
const { accountNumber } = input;
|
|
11
11
|
const addresses = (0, utils_1.assertQuoteAddresses)(input);
|
|
12
12
|
if (addresses.isErr())
|
|
@@ -52,4 +52,7 @@ const getTradeQuote = async (input, deps, relayChainMap) => {
|
|
|
52
52
|
};
|
|
53
53
|
return (0, monads_1.Ok)([tradeQuote]);
|
|
54
54
|
};
|
|
55
|
+
const getTradeQuote = (input, deps, relayChainMap) => getQuote(input, deps, relayChainMap);
|
|
55
56
|
exports.getTradeQuote = getTradeQuote;
|
|
57
|
+
const getExactOutputTradeQuote = (input, deps, relayChainMap) => getQuote(input, deps, relayChainMap);
|
|
58
|
+
exports.getExactOutputTradeQuote = getExactOutputTradeQuote;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Result } from '@sniptt/monads';
|
|
2
2
|
import type { SwapErrorRight, SwapperDeps, TradeRate } from '../../../types';
|
|
3
3
|
import type { chainIdToRelayChainId as relayChainMapImplementation } from '../constant';
|
|
4
|
-
import type { RelayTradeRateInput } from '../utils/types';
|
|
4
|
+
import type { RelayExactOutputTradeRateInput, RelayTradeRateInput } from '../utils/types';
|
|
5
5
|
export declare const getTradeRate: (input: RelayTradeRateInput, deps: SwapperDeps, relayChainMap: typeof relayChainMapImplementation) => Promise<Result<TradeRate[], SwapErrorRight>>;
|
|
6
|
+
export declare const getExactOutputTradeRate: (input: RelayExactOutputTradeRateInput, deps: SwapperDeps, relayChainMap: typeof relayChainMapImplementation) => Promise<Result<TradeRate[], SwapErrorRight>>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTradeRate = void 0;
|
|
3
|
+
exports.getExactOutputTradeRate = exports.getTradeRate = void 0;
|
|
4
4
|
const monads_1 = require("@sniptt/monads");
|
|
5
5
|
const getRelayStepData_1 = require("../utils/getRelayStepData");
|
|
6
6
|
const getRelayTradeContext_1 = require("../utils/getRelayTradeContext");
|
|
7
|
-
const
|
|
7
|
+
const getRate = async (input, deps, relayChainMap) => {
|
|
8
8
|
const maybeContext = await (0, getRelayTradeContext_1.getRelayTradeContext)({ input, deps, relayChainMap });
|
|
9
9
|
if (maybeContext.isErr())
|
|
10
10
|
return (0, monads_1.Err)(maybeContext.unwrapErr());
|
|
@@ -39,4 +39,7 @@ const getTradeRate = async (input, deps, relayChainMap) => {
|
|
|
39
39
|
};
|
|
40
40
|
return (0, monads_1.Ok)([tradeRate]);
|
|
41
41
|
};
|
|
42
|
+
const getTradeRate = (input, deps, relayChainMap) => getRate(input, deps, relayChainMap);
|
|
42
43
|
exports.getTradeRate = getTradeRate;
|
|
44
|
+
const getExactOutputTradeRate = (input, deps, relayChainMap) => getRate(input, deps, relayChainMap);
|
|
45
|
+
exports.getExactOutputTradeRate = getExactOutputTradeRate;
|
|
@@ -2,7 +2,7 @@ import type { Result } from '@sniptt/monads';
|
|
|
2
2
|
import type { QuoteFeeData, SwapErrorRight, SwapperDeps, TradeCommon, TradeStepCommon } from '../../../types';
|
|
3
3
|
import type { chainIdToRelayChainId as relayChainMapImplementation } from '../constant';
|
|
4
4
|
import type { GetRelayStepDataArgs } from './getRelayStepData';
|
|
5
|
-
import type { RelayQuoteItem, RelayTradeQuoteInput, RelayTradeRateInput } from './types';
|
|
5
|
+
import type { RelayExactOutputTradeQuoteInput, RelayExactOutputTradeRateInput, RelayQuoteItem, RelayTradeQuoteInput, RelayTradeRateInput } from './types';
|
|
6
6
|
type RelayTradeContext = {
|
|
7
7
|
tradeCommon: TradeCommon;
|
|
8
8
|
stepCommon: Omit<TradeStepCommon, 'feeData' | 'allowanceContract'>;
|
|
@@ -15,7 +15,7 @@ type RelayTradeContext = {
|
|
|
15
15
|
relayId: string;
|
|
16
16
|
};
|
|
17
17
|
export declare const getRelayTradeContext: ({ input, deps, relayChainMap, }: {
|
|
18
|
-
input: RelayTradeQuoteInput | RelayTradeRateInput;
|
|
18
|
+
input: RelayTradeQuoteInput | RelayTradeRateInput | RelayExactOutputTradeQuoteInput | RelayExactOutputTradeRateInput;
|
|
19
19
|
deps: SwapperDeps;
|
|
20
20
|
relayChainMap: typeof relayChainMapImplementation;
|
|
21
21
|
}) => Promise<Result<RelayTradeContext, SwapErrorRight>>;
|
|
@@ -22,7 +22,9 @@ const fetchRelayTrade_1 = require("./fetchRelayTrade");
|
|
|
22
22
|
const helpers_2 = require("./helpers");
|
|
23
23
|
const types_2 = require("./types");
|
|
24
24
|
const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
25
|
-
const { sellAsset, buyAsset,
|
|
25
|
+
const { sellAsset, buyAsset, affiliateBps } = input;
|
|
26
|
+
const amount = (0, helpers_1.getTradeAmount)(input);
|
|
27
|
+
const isExactOutput = amount.direction === 'exactOut';
|
|
26
28
|
const xpub = 'xpub' in input ? input.xpub : undefined;
|
|
27
29
|
const slippageToleranceBps = input.slippageTolerancePercentageDecimal
|
|
28
30
|
? (0, utils_1.convertDecimalPercentageToBasisPoints)(input.slippageTolerancePercentageDecimal).toFixed()
|
|
@@ -41,8 +43,8 @@ const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
41
43
|
originCurrency: (0, getRelayAssetAddress_1.getRelayAssetAddress)(sellAsset),
|
|
42
44
|
destinationChainId: buyRelayChainId,
|
|
43
45
|
destinationCurrency: (0, getRelayAssetAddress_1.getRelayAssetAddress)(buyAsset),
|
|
44
|
-
tradeType: 'EXACT_INPUT',
|
|
45
|
-
amount:
|
|
46
|
+
tradeType: isExactOutput ? 'EXACT_OUTPUT' : 'EXACT_INPUT',
|
|
47
|
+
amount: amount.cryptoBaseUnit,
|
|
46
48
|
recipient,
|
|
47
49
|
user: sendAddress,
|
|
48
50
|
refundTo,
|
|
@@ -84,10 +86,19 @@ const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
84
86
|
code: types_1.TradeQuoteError.UnknownError,
|
|
85
87
|
}));
|
|
86
88
|
}
|
|
87
|
-
const { slippageTolerance, currencyOut, timeEstimate } = quote.details;
|
|
88
|
-
const
|
|
89
|
+
const { slippageTolerance, currencyIn, currencyOut, timeEstimate } = quote.details;
|
|
90
|
+
const sellAmountCryptoBaseUnit = currencyIn.amount;
|
|
91
|
+
const buyAmountAfterFeesCryptoBaseUnit = isExactOutput
|
|
92
|
+
? currencyOut.minimumAmount
|
|
93
|
+
: currencyOut.amount;
|
|
94
|
+
if (isExactOutput && !(0, utils_1.bnOrZero)(buyAmountAfterFeesCryptoBaseUnit).eq(amount.cryptoBaseUnit)) {
|
|
95
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
96
|
+
message: `Relay guarantees ${buyAmountAfterFeesCryptoBaseUnit} against a requested exact output of ${amount.cryptoBaseUnit}`,
|
|
97
|
+
code: types_1.TradeQuoteError.InvalidResponse,
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
89
100
|
const rate = (0, utils_2.getInputOutputRate)({
|
|
90
|
-
sellAmountCryptoBaseUnit
|
|
101
|
+
sellAmountCryptoBaseUnit,
|
|
91
102
|
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
92
103
|
sellAsset,
|
|
93
104
|
buyAsset,
|
|
@@ -248,7 +259,7 @@ const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
248
259
|
})();
|
|
249
260
|
// Add back relayer service and gas fees (relayer is including both) since they are downsides,
|
|
250
261
|
// and add appFees — these are quote-level and identical across every step
|
|
251
|
-
const buyAmountBeforeFeesCryptoBaseUnit = (0, utils_1.bnOrZero)(
|
|
262
|
+
const buyAmountBeforeFeesCryptoBaseUnit = (0, utils_1.bnOrZero)(buyAmountAfterFeesCryptoBaseUnit)
|
|
252
263
|
.plus(relayerFeesBuyAssetCryptoBaseUnit)
|
|
253
264
|
.plus(appFeesBaseUnit)
|
|
254
265
|
.toFixed();
|
|
@@ -262,6 +273,7 @@ const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
262
273
|
id: relayId,
|
|
263
274
|
rate,
|
|
264
275
|
swapperName: types_1.SwapperName.Relay,
|
|
276
|
+
isExactOutput,
|
|
265
277
|
affiliateBps,
|
|
266
278
|
slippageTolerancePercentageDecimal,
|
|
267
279
|
},
|
|
@@ -269,7 +281,7 @@ const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
269
281
|
rate,
|
|
270
282
|
buyAmountBeforeFeesCryptoBaseUnit,
|
|
271
283
|
buyAmountAfterFeesCryptoBaseUnit,
|
|
272
|
-
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
284
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmountCryptoBaseUnit,
|
|
273
285
|
buyAsset,
|
|
274
286
|
sellAsset,
|
|
275
287
|
source: types_1.SwapperName.Relay,
|
|
@@ -279,7 +291,7 @@ const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
279
291
|
affiliateBps,
|
|
280
292
|
sellAsset,
|
|
281
293
|
buyAsset,
|
|
282
|
-
sellAmountCryptoBaseUnit
|
|
294
|
+
sellAmountCryptoBaseUnit,
|
|
283
295
|
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
284
296
|
fixedAssetId: (0, utils_1.chainIdToFeeAssetId)(caip_1.baseChainId),
|
|
285
297
|
fixedAsset: deps.assetsById[(0, utils_1.chainIdToFeeAssetId)(caip_1.baseChainId)],
|
|
@@ -297,7 +309,7 @@ const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
297
309
|
relayStepInputs,
|
|
298
310
|
stepDataArgs: {
|
|
299
311
|
sellAsset,
|
|
300
|
-
sellAmountCryptoBaseUnit
|
|
312
|
+
sellAmountCryptoBaseUnit,
|
|
301
313
|
orderId,
|
|
302
314
|
from: sendAddress,
|
|
303
315
|
xpub,
|
|
@@ -4,7 +4,7 @@ import type { Result } from '@sniptt/monads';
|
|
|
4
4
|
import type { TransactionInstruction } from '@solana/web3.js';
|
|
5
5
|
import type { SwapErrorRight } from '../../../types';
|
|
6
6
|
import type { chainIdToRelayChainId as relayChainMapImplementation } from '../constant';
|
|
7
|
-
import type { RelayQuoteItem, RelaySolanaInstruction, RelayTradeQuoteInput, RelayTradeRateInput } from './types';
|
|
7
|
+
import type { RelayExactOutputTradeQuoteInput, RelayExactOutputTradeRateInput, RelayQuoteItem, RelaySolanaInstruction, RelayTradeQuoteInput, RelayTradeRateInput } from './types';
|
|
8
8
|
export declare const assertValidTrade: ({ sellAsset, buyAsset, relayChainMap, }: {
|
|
9
9
|
sellAsset: Asset;
|
|
10
10
|
buyAsset: Asset;
|
|
@@ -14,7 +14,7 @@ export declare const assertValidTrade: ({ sellAsset, buyAsset, relayChainMap, }:
|
|
|
14
14
|
buyRelayChainId: number;
|
|
15
15
|
}, SwapErrorRight>;
|
|
16
16
|
export declare const resolveRelayAddresses: ({ input, sellChainId, buyChainId, }: {
|
|
17
|
-
input: RelayTradeQuoteInput | RelayTradeRateInput;
|
|
17
|
+
input: RelayTradeQuoteInput | RelayTradeRateInput | RelayExactOutputTradeQuoteInput | RelayExactOutputTradeRateInput;
|
|
18
18
|
sellChainId: ChainId;
|
|
19
19
|
buyChainId: ChainId;
|
|
20
20
|
}) => {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
2
|
+
import type { Result } from '@sniptt/monads';
|
|
3
|
+
import type { SwapErrorRight, SwapperConfig } from '../../../types';
|
|
4
|
+
import type { RelayRequest, RelayStatus } from './types';
|
|
5
|
+
export declare const getRelayTrackingLink: (txHash: string) => string;
|
|
6
|
+
export declare const relayStatusToTxStatus: (status: RelayStatus['status'] | undefined) => TxStatus;
|
|
7
|
+
export declare const fetchRelayRequestByTxHash: (txHash: string, config: SwapperConfig) => Promise<Result<RelayRequest | undefined, SwapErrorRight>>;
|
|
8
|
+
export declare const getRelayRequestFailureMessage: (request: RelayRequest) => string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRelayRequestFailureMessage = exports.fetchRelayRequestByTxHash = exports.relayStatusToTxStatus = exports.getRelayTrackingLink = void 0;
|
|
4
|
+
const unchained_client_1 = require("@shapeshiftoss/unchained-client");
|
|
5
|
+
const relayService_1 = require("./relayService");
|
|
6
|
+
const getRelayTrackingLink = (txHash) => `https://relay.link/transaction/${txHash}`;
|
|
7
|
+
exports.getRelayTrackingLink = getRelayTrackingLink;
|
|
8
|
+
const relayStatusToTxStatus = (status) => {
|
|
9
|
+
switch (status) {
|
|
10
|
+
case 'success':
|
|
11
|
+
return unchained_client_1.TxStatus.Confirmed;
|
|
12
|
+
case 'waiting':
|
|
13
|
+
case 'delayed':
|
|
14
|
+
case 'pending':
|
|
15
|
+
case 'depositing':
|
|
16
|
+
case 'submitted':
|
|
17
|
+
return unchained_client_1.TxStatus.Pending;
|
|
18
|
+
case 'failure':
|
|
19
|
+
case 'refund':
|
|
20
|
+
return unchained_client_1.TxStatus.Failed;
|
|
21
|
+
default:
|
|
22
|
+
return unchained_client_1.TxStatus.Unknown;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.relayStatusToTxStatus = relayStatusToTxStatus;
|
|
26
|
+
// Relay index requests by origin tx hash, resolving a swap we hold no relayId for
|
|
27
|
+
const fetchRelayRequestByTxHash = async (txHash, config) => {
|
|
28
|
+
const maybeResponse = await relayService_1.relayService.get(`${config.VITE_RELAY_API_URL}/requests/v2?hash=${txHash}`, (0, relayService_1.getRelayRequestConfig)(config));
|
|
29
|
+
// Match the origin tx ourselves rather than trusting the listing to have filtered on it
|
|
30
|
+
return maybeResponse.map(({ data }) => data.requests?.find(({ data: request }) => request?.inTxs?.some(({ hash }) => hash?.toLowerCase() === txHash.toLowerCase())));
|
|
31
|
+
};
|
|
32
|
+
exports.fetchRelayRequestByTxHash = fetchRelayRequestByTxHash;
|
|
33
|
+
const getRelayRequestFailureMessage = (request) => {
|
|
34
|
+
const { failReason, refundFailReason } = request.data ?? {};
|
|
35
|
+
// Relay report 'N/A' rather than omitting the reason when there isn't one
|
|
36
|
+
const reason = [failReason, refundFailReason].find(value => value && value !== 'N/A');
|
|
37
|
+
return reason ?? 'Bridge failed';
|
|
38
|
+
};
|
|
39
|
+
exports.getRelayRequestFailureMessage = getRelayRequestFailureMessage;
|