@shapeshiftoss/swapper 20.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/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/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 +2 -1
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers.d.ts +2 -2
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers.js +3 -3
- 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.js +13 -5
- 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 +2 -2
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsTradeContext.js +27 -15
- 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 +3 -18
- 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 +14 -0
- package/dist/cjs/swappers/ThorchainSwapper/generated/generatedThorLongtailTokens.json +1 -0
- package/dist/cjs/types.d.ts +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 +4 -1
- package/dist/cjs/utils/helpers.js +19 -1
- package/dist/cjs/utils/helpers.test.js +41 -0
- package/dist/esm/.tsbuildinfo +1 -1
- 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/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 +2 -1
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers.d.ts +2 -2
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers.js +5 -5
- 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.js +10 -2
- 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 +2 -2
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsTradeContext.js +28 -16
- 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 +3 -18
- 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 +14 -0
- package/dist/esm/swappers/ThorchainSwapper/generated/generatedThorLongtailTokens.json +1 -0
- package/dist/esm/types.d.ts +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 +4 -1
- package/dist/esm/utils/helpers.js +17 -0
- package/dist/esm/utils/helpers.test.js +42 -1
- package/package.json +7 -7
|
@@ -2,8 +2,9 @@
|
|
|
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) {
|
|
@@ -13,7 +14,7 @@ async function getPortalsStepData(args) {
|
|
|
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)({
|
|
@@ -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 = {
|
|
@@ -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
|
+
});
|
|
@@ -15,12 +15,12 @@ type PortalsTradeContext = {
|
|
|
15
15
|
tx: PortalsTx;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
-
export declare const getPortalsTradeContext: ({ input, deps, sellChainId,
|
|
18
|
+
export declare const getPortalsTradeContext: ({ input, deps, sellChainId, orderContext, outputToken, tx, }: {
|
|
19
19
|
input: PortalsTradeQuoteInput | PortalsTradeRateInput;
|
|
20
20
|
deps: SwapperDeps;
|
|
21
21
|
sellChainId: PortalsSupportedChainId;
|
|
22
|
-
inputToken: string;
|
|
23
22
|
orderContext: PortalsTradeOrderResponse['context'];
|
|
23
|
+
outputToken: string;
|
|
24
24
|
tx: PortalsTx;
|
|
25
25
|
}) => Result<PortalsTradeContext, SwapErrorRight>;
|
|
26
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,
|
|
@@ -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 = {
|
|
@@ -69,7 +70,7 @@ exports.relayApi = {
|
|
|
69
70
|
}
|
|
70
71
|
// relay.link tracks the swap by its origin chain transaction
|
|
71
72
|
const swapperTxId = txHash;
|
|
72
|
-
const swapperTxLink =
|
|
73
|
+
const swapperTxLink = (0, relayStatus_1.getRelayTrackingLink)(txHash);
|
|
73
74
|
const maybeStatusResponse = await relayService_1.relayService.get(`${config.VITE_RELAY_API_URL}/intents/status/v3?requestId=${relayMetadata.relayId}`, (0, relayService_1.getRelayRequestConfig)(config));
|
|
74
75
|
if (maybeStatusResponse.isErr()) {
|
|
75
76
|
return {
|
|
@@ -81,23 +82,7 @@ exports.relayApi = {
|
|
|
81
82
|
};
|
|
82
83
|
}
|
|
83
84
|
const { data: statusResponse } = maybeStatusResponse.unwrap();
|
|
84
|
-
const status = (()
|
|
85
|
-
switch (statusResponse.status) {
|
|
86
|
-
case 'success':
|
|
87
|
-
return unchained_client_1.TxStatus.Confirmed;
|
|
88
|
-
case 'waiting':
|
|
89
|
-
case 'delayed':
|
|
90
|
-
case 'pending':
|
|
91
|
-
case 'depositing':
|
|
92
|
-
case 'submitted':
|
|
93
|
-
return unchained_client_1.TxStatus.Pending;
|
|
94
|
-
case 'failure':
|
|
95
|
-
case 'refund':
|
|
96
|
-
return unchained_client_1.TxStatus.Failed;
|
|
97
|
-
default:
|
|
98
|
-
return unchained_client_1.TxStatus.Unknown;
|
|
99
|
-
}
|
|
100
|
-
})();
|
|
85
|
+
const status = (0, relayStatus_1.relayStatusToTxStatus)(statusResponse.status);
|
|
101
86
|
// Relay refers to in Txs as "inTxHashes" but to out Txs as simply "txHashes" when they really mean "outTxHashes"
|
|
102
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
|
|
103
88
|
const outTxHashes = statusResponse.txHashes;
|
|
@@ -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;
|
|
@@ -12,6 +12,20 @@ export type RelayMetadata = {
|
|
|
12
12
|
relayId: string;
|
|
13
13
|
data?: string;
|
|
14
14
|
};
|
|
15
|
+
export type RelayRequestTransaction = {
|
|
16
|
+
hash?: string;
|
|
17
|
+
chainId?: number;
|
|
18
|
+
};
|
|
19
|
+
export type RelayRequestData = {
|
|
20
|
+
failReason?: string;
|
|
21
|
+
refundFailReason?: string;
|
|
22
|
+
inTxs?: RelayRequestTransaction[];
|
|
23
|
+
outTxs?: RelayRequestTransaction[];
|
|
24
|
+
};
|
|
25
|
+
export type RelayRequest = {
|
|
26
|
+
status?: RelayStatus['status'];
|
|
27
|
+
data?: RelayRequestData;
|
|
28
|
+
};
|
|
15
29
|
export type RelayStatus = {
|
|
16
30
|
status: 'success' | 'failure' | 'pending' | 'submitted' | 'depositing' | 'refund' | 'delayed' | 'waiting';
|
|
17
31
|
details?: string;
|
|
@@ -1016,6 +1016,7 @@
|
|
|
1016
1016
|
"eip155:1/erc20:0x826180541412d574cf1336d22c0c0a287822678a",
|
|
1017
1017
|
"eip155:1/erc20:0x2c06ba9e7f0daccbc1f6a33ea67e85bb68fbee3a",
|
|
1018
1018
|
"eip155:1/erc20:0xcbb8f1bda10b9696c57e13bc128fe674769dcec0",
|
|
1019
|
+
"eip155:1/erc20:0x72dfb2e44f59c5ad2bafe84314e5b99a7cd5075e",
|
|
1019
1020
|
"eip155:43114/erc20:0xc891eb4cbdeff6e073e859e987815ed1505c2acd",
|
|
1020
1021
|
"eip155:43114/erc20:0xd24c2ad096400b6fbcd2ad8b24e7acbc21a1da64",
|
|
1021
1022
|
"eip155:43114/erc20:0x47c3118ad183712acd42648e9e522e13690f29a0",
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -574,6 +574,7 @@ export type CheckTradeStatusInput = {
|
|
|
574
574
|
export type TradeStatus = {
|
|
575
575
|
status: TxStatus;
|
|
576
576
|
buyTxHash: string | undefined;
|
|
577
|
+
sellTxHash?: string | undefined;
|
|
577
578
|
swapperTxId?: string | undefined;
|
|
578
579
|
swapperTxLink?: string | undefined;
|
|
579
580
|
message: string | [string, InterpolationOptions] | undefined;
|
|
@@ -583,6 +584,7 @@ export type TradeQuoteResult = Result<TradeQuote[], SwapErrorRight>;
|
|
|
583
584
|
export type TradeRateResult = Result<TradeRate[], SwapErrorRight>;
|
|
584
585
|
export type EvmMessageToSign = CowMessageToSign;
|
|
585
586
|
export type Swapper = {
|
|
587
|
+
supportsExternalPayment?: boolean;
|
|
586
588
|
executeEvmTransaction?: (txToSign: SignTx<EvmChainId>, callbacks: EvmTransactionExecutionProps) => Promise<string>;
|
|
587
589
|
executeEvmMessage?: (txMetaToSign: EvmMessageToSign, callbacks: EvmMessageExecutionProps, config: SwapperConfig) => Promise<string>;
|
|
588
590
|
executeUtxoTransaction?: (txToSign: SignTx<UtxoChainId>, callbacks: UtxoTransactionExecutionProps) => Promise<string>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AppDataRootSchema as AppDataRootSchemaLegacy } from '@cowprotocol/app-data/dist/generatedTypes/v0.4.0';
|
|
2
|
+
import type { AppDataRootSchema as AppDataRootSchemaLatest, OrderClass1 } from '@cowprotocol/app-data/dist/generatedTypes/v1.3.0';
|
|
2
3
|
import type { ChainId } from '@shapeshiftoss/caip';
|
|
3
4
|
import type { EvmChainAdapter } from '@shapeshiftoss/chain-adapters';
|
|
4
5
|
import type { HDWallet } from '@shapeshiftoss/hdwallet-core';
|
|
@@ -22,3 +23,5 @@ export declare const getFullAppData: (slippageTolerancePercentage: string, affil
|
|
|
22
23
|
appDataHash: string;
|
|
23
24
|
appData: string;
|
|
24
25
|
}>;
|
|
26
|
+
export type ParsedAppData = AppDataRootSchemaLatest | AppDataRootSchemaLegacy;
|
|
27
|
+
export declare const isLegacyAppData: (appData: ParsedAppData) => appData is AppDataRootSchemaLegacy;
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getFullAppData = exports.getAffiliateAppDataFragmentByChainId = exports.cowSwapTokenToAssetId = exports.signCowOrderCancellation = exports.signCowOrder = exports.signCowMessage = exports.assertGetCowNetwork = exports.getCowNetwork = void 0;
|
|
17
|
+
exports.isLegacyAppData = exports.getFullAppData = exports.getAffiliateAppDataFragmentByChainId = exports.cowSwapTokenToAssetId = exports.signCowOrderCancellation = exports.signCowOrder = exports.signCowMessage = exports.assertGetCowNetwork = exports.getCowNetwork = void 0;
|
|
18
18
|
const app_data_1 = require("@cowprotocol/app-data");
|
|
19
19
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
20
20
|
const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
@@ -183,3 +183,7 @@ const getFullAppData = async (slippageTolerancePercentage, affiliateAppDataFragm
|
|
|
183
183
|
return { appDataHash: appDataKeccak256, appData: fullAppData };
|
|
184
184
|
};
|
|
185
185
|
exports.getFullAppData = getFullAppData;
|
|
186
|
+
const isLegacyAppData = (appData) => {
|
|
187
|
+
return appData.version === '0.4.0';
|
|
188
|
+
};
|
|
189
|
+
exports.isLegacyAppData = isLegacyAppData;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AssetId, ChainId } from '@shapeshiftoss/caip';
|
|
2
|
-
import type { TradeAmount } from '../types';
|
|
2
|
+
import type { TradeAmount, TradeStepCommon } from '../types';
|
|
3
|
+
import { SwapperName } from '../types';
|
|
3
4
|
export declare const FALLBACK_QUOTE_DEADLINE_MS = 60000;
|
|
4
5
|
export declare const getTradeAmount: (input: {
|
|
5
6
|
sellAmountIncludingProtocolFeesCryptoBaseUnit: string;
|
|
@@ -9,3 +10,5 @@ export declare const getTradeAmount: (input: {
|
|
|
9
10
|
export declare const normalizeEpochToMs: (value: number) => number;
|
|
10
11
|
export declare const isNativeEvmAsset: (assetId: AssetId) => boolean;
|
|
11
12
|
export declare const getTreasuryAddressFromChainId: (chainId: ChainId) => string;
|
|
13
|
+
export type DepositAddressStep = Pick<TradeStepCommon, 'chainflipSpecific' | 'swapperMetadata'>;
|
|
14
|
+
export declare const getDepositAddress: (step: DepositAddressStep, swapperName: SwapperName) => string | undefined;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTreasuryAddressFromChainId = exports.isNativeEvmAsset = exports.normalizeEpochToMs = exports.getTradeAmount = exports.FALLBACK_QUOTE_DEADLINE_MS = void 0;
|
|
3
|
+
exports.getDepositAddress = exports.getTreasuryAddressFromChainId = exports.isNativeEvmAsset = exports.normalizeEpochToMs = exports.getTradeAmount = exports.FALLBACK_QUOTE_DEADLINE_MS = void 0;
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
5
|
const types_1 = require("@shapeshiftoss/types");
|
|
6
6
|
const utils_1 = require("@shapeshiftoss/utils");
|
|
7
|
+
const types_2 = require("../types");
|
|
7
8
|
// Deadline for providers without their own expiry - short enough to keep priced amounts honest
|
|
8
9
|
exports.FALLBACK_QUOTE_DEADLINE_MS = 60_000;
|
|
9
10
|
const getTradeAmount = (input) => 'buyAmountCryptoBaseUnit' in input
|
|
@@ -78,3 +79,20 @@ const getTreasuryAddressFromChainId = (chainId) => {
|
|
|
78
79
|
return treasuryAddress;
|
|
79
80
|
};
|
|
80
81
|
exports.getTreasuryAddressFromChainId = getTreasuryAddressFromChainId;
|
|
82
|
+
const getDepositAddress = (step, swapperName) => {
|
|
83
|
+
switch (swapperName) {
|
|
84
|
+
case types_2.SwapperName.Chainflip:
|
|
85
|
+
return step.chainflipSpecific?.depositAddress || undefined;
|
|
86
|
+
case types_2.SwapperName.NearIntents: {
|
|
87
|
+
if (step.swapperMetadata?.name !== 'nearIntents')
|
|
88
|
+
return;
|
|
89
|
+
const { depositAddress, depositMemo } = step.swapperMetadata;
|
|
90
|
+
if (depositMemo)
|
|
91
|
+
return;
|
|
92
|
+
return depositAddress || undefined;
|
|
93
|
+
}
|
|
94
|
+
default:
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
exports.getDepositAddress = getDepositAddress;
|
|
@@ -4,6 +4,8 @@ const caip_1 = require("@shapeshiftoss/caip");
|
|
|
4
4
|
const types_1 = require("@shapeshiftoss/types");
|
|
5
5
|
const utils_1 = require("@shapeshiftoss/utils");
|
|
6
6
|
const vitest_1 = require("vitest");
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const types_2 = require("../types");
|
|
7
9
|
const helpers_1 = require("./helpers");
|
|
8
10
|
(0, vitest_1.describe)('getTreasuryAddressFromChainId', () => {
|
|
9
11
|
// Affiliate and fee recipient addresses for every swapper flow through here, so pin the values
|
|
@@ -49,3 +51,42 @@ const helpers_1 = require("./helpers");
|
|
|
49
51
|
(0, vitest_1.expect)((0, helpers_1.normalizeEpochToMs)(epochMs * 1e6)).toBe(epochMs);
|
|
50
52
|
});
|
|
51
53
|
});
|
|
54
|
+
const makeStep = (step) => step;
|
|
55
|
+
(0, vitest_1.describe)('getDepositAddress', () => {
|
|
56
|
+
(0, vitest_1.it)('reads the chainflip deposit address', () => {
|
|
57
|
+
const step = makeStep({ chainflipSpecific: { depositAddress: 'bc1qdeposit' } });
|
|
58
|
+
(0, vitest_1.expect)((0, helpers_1.getDepositAddress)(step, types_2.SwapperName.Chainflip)).toBe('bc1qdeposit');
|
|
59
|
+
});
|
|
60
|
+
(0, vitest_1.it)('returns undefined when chainflip has no deposit address', () => {
|
|
61
|
+
(0, vitest_1.expect)((0, helpers_1.getDepositAddress)(makeStep({}), types_2.SwapperName.Chainflip)).toBeUndefined();
|
|
62
|
+
});
|
|
63
|
+
(0, vitest_1.it)('reads the near intents deposit address', () => {
|
|
64
|
+
const step = makeStep({
|
|
65
|
+
swapperMetadata: { name: 'nearIntents', depositAddress: '0xdeposit' },
|
|
66
|
+
});
|
|
67
|
+
(0, vitest_1.expect)((0, helpers_1.getDepositAddress)(step, types_2.SwapperName.NearIntents)).toBe('0xdeposit');
|
|
68
|
+
});
|
|
69
|
+
(0, vitest_1.it)('rejects a memo-bound near intents deposit address', () => {
|
|
70
|
+
const step = makeStep({
|
|
71
|
+
swapperMetadata: { name: 'nearIntents', depositAddress: 'EQdeposit', depositMemo: '12345' },
|
|
72
|
+
});
|
|
73
|
+
(0, vitest_1.expect)((0, helpers_1.getDepositAddress)(step, types_2.SwapperName.NearIntents)).toBeUndefined();
|
|
74
|
+
});
|
|
75
|
+
(0, vitest_1.it)('rejects an empty near intents deposit address', () => {
|
|
76
|
+
const step = makeStep({ swapperMetadata: { name: 'nearIntents', depositAddress: '' } });
|
|
77
|
+
(0, vitest_1.expect)((0, helpers_1.getDepositAddress)(step, types_2.SwapperName.NearIntents)).toBeUndefined();
|
|
78
|
+
});
|
|
79
|
+
(0, vitest_1.it)('returns undefined for swappers that do not use deposit addresses', () => {
|
|
80
|
+
const step = makeStep({ chainflipSpecific: { depositAddress: 'bc1qdeposit' } });
|
|
81
|
+
(0, vitest_1.expect)((0, helpers_1.getDepositAddress)(step, types_2.SwapperName.Relay)).toBeUndefined();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
(0, vitest_1.describe)('supportsExternalPayment', () => {
|
|
85
|
+
(0, vitest_1.it)('is flagged on exactly the externally paid swappers', () => {
|
|
86
|
+
const flagged = Object.entries(constants_1.swappers)
|
|
87
|
+
.filter(([, swapper]) => swapper?.supportsExternalPayment)
|
|
88
|
+
.map(([name]) => name)
|
|
89
|
+
.sort();
|
|
90
|
+
(0, vitest_1.expect)(flagged).toEqual([types_2.SwapperName.Chainflip, types_2.SwapperName.NearIntents].sort());
|
|
91
|
+
});
|
|
92
|
+
});
|