@shapeshiftoss/swapper 19.0.0 → 20.0.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/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/endpoints.js +2 -0
- 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 +3 -3
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers.js +27 -23
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsStepData.d.ts +1 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsStepData.js +3 -3
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsTradeContext.d.ts +1 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsTradeContext.js +7 -1
- package/dist/cjs/swappers/RelaySwapper/endpoints.js +6 -0
- 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/types.d.ts +4 -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/types.d.ts +19 -2
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils/helpers.d.ts +6 -0
- package/dist/cjs/utils/helpers.js +5 -1
- 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/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/endpoints.js +4 -2
- 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 +3 -3
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers.js +27 -23
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsStepData.d.ts +1 -0
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsStepData.js +3 -3
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsTradeContext.d.ts +1 -0
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsTradeContext.js +7 -1
- package/dist/esm/swappers/RelaySwapper/endpoints.js +8 -2
- 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/types.d.ts +4 -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/types.d.ts +19 -2
- package/dist/esm/types.js +2 -0
- package/dist/esm/utils/helpers.d.ts +6 -0
- package/dist/esm/utils/helpers.js +3 -0
- package/package.json +5 -5
|
@@ -7,7 +7,7 @@ const utils_1 = require("../../../utils");
|
|
|
7
7
|
const evm_1 = require("../../../utils/evm");
|
|
8
8
|
const fetchPortalsTradeOrder_1 = require("./fetchPortalsTradeOrder");
|
|
9
9
|
async function getPortalsStepData(args) {
|
|
10
|
-
const { tx, sellAsset, spenderAddress, input, deps } = args;
|
|
10
|
+
const { tx, sellAsset, sellAmountCryptoBaseUnit, spenderAddress, input, deps } = args;
|
|
11
11
|
const adapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
|
|
12
12
|
const supportsEIP1559 = 'supportsEIP1559' in input ? input.supportsEIP1559 : false;
|
|
13
13
|
if (args.type === 'rate') {
|
|
@@ -18,7 +18,7 @@ async function getPortalsStepData(args) {
|
|
|
18
18
|
try {
|
|
19
19
|
const gasLimit = await (0, evm_1.estimateGasWithStateOverride)({
|
|
20
20
|
sellAsset,
|
|
21
|
-
sellAmountCryptoBaseUnit
|
|
21
|
+
sellAmountCryptoBaseUnit,
|
|
22
22
|
from: tx.from,
|
|
23
23
|
spenderAddress,
|
|
24
24
|
to: tx.to,
|
|
@@ -68,7 +68,7 @@ async function getPortalsStepData(args) {
|
|
|
68
68
|
supportsEIP1559,
|
|
69
69
|
stateOverride: {
|
|
70
70
|
sellAsset,
|
|
71
|
-
sellAmountCryptoBaseUnit
|
|
71
|
+
sellAmountCryptoBaseUnit,
|
|
72
72
|
spenderAddress,
|
|
73
73
|
},
|
|
74
74
|
});
|
|
@@ -77,7 +77,13 @@ const getPortalsTradeContext = ({ input, deps, sellChainId, inputToken, orderCon
|
|
|
77
77
|
}),
|
|
78
78
|
},
|
|
79
79
|
protocolFees,
|
|
80
|
-
stepDataArgs: {
|
|
80
|
+
stepDataArgs: {
|
|
81
|
+
deps,
|
|
82
|
+
sellAsset,
|
|
83
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
84
|
+
spenderAddress: allowanceContract,
|
|
85
|
+
tx,
|
|
86
|
+
},
|
|
81
87
|
});
|
|
82
88
|
};
|
|
83
89
|
exports.getPortalsTradeContext = getPortalsTradeContext;
|
|
@@ -23,6 +23,12 @@ exports.relayApi = {
|
|
|
23
23
|
getTradeRate: (input, deps) => {
|
|
24
24
|
return (0, getTradeRate_1.getTradeRate)(input, deps, constant_1.chainIdToRelayChainId);
|
|
25
25
|
},
|
|
26
|
+
getExactOutputTradeQuote: (input, deps) => {
|
|
27
|
+
return (0, getTradeQuote_1.getExactOutputTradeQuote)(input, deps, constant_1.chainIdToRelayChainId);
|
|
28
|
+
},
|
|
29
|
+
getExactOutputTradeRate: (input, deps) => {
|
|
30
|
+
return (0, getTradeRate_1.getExactOutputTradeRate)(input, deps, constant_1.chainIdToRelayChainId);
|
|
31
|
+
},
|
|
26
32
|
getEvmTransactionFees: evm_1.getEvmTransactionFees,
|
|
27
33
|
getUnsignedEvmTransaction: evm_1.getUnsignedEvmTransaction,
|
|
28
34
|
getUnsignedUtxoTransaction: utxo_1.getUnsignedUtxoTransaction,
|
|
@@ -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
|
}) => {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetSolanaTradeQuoteInput, GetSolanaTradeRateInput, GetTronTradeQuoteInput, GetTronTradeRateInput, GetUtxoTradeQuoteInput, GetUtxoTradeRateInput } from '../../../types';
|
|
1
|
+
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetSolanaTradeQuoteInput, GetSolanaTradeRateInput, GetTronTradeQuoteInput, GetTronTradeRateInput, GetUtxoTradeQuoteInput, GetUtxoTradeRateInput, WithExactBuyAmount } from '../../../types';
|
|
2
2
|
export type RelayTradeQuoteInput = GetEvmTradeQuoteInput | GetUtxoTradeQuoteInput | GetSolanaTradeQuoteInput | GetTronTradeQuoteInput;
|
|
3
3
|
export type RelayTradeRateInput = GetEvmTradeRateInput | GetUtxoTradeRateInput | GetSolanaTradeRateInput | GetTronTradeRateInput;
|
|
4
|
+
export type RelayExactOutputTradeQuoteInput = WithExactBuyAmount<RelayTradeQuoteInput>;
|
|
5
|
+
export type RelayExactOutputTradeRateInput = WithExactBuyAmount<RelayTradeRateInput>;
|
|
4
6
|
export type RelayTransactionMetadata = {
|
|
5
7
|
to?: string;
|
|
6
8
|
data?: string;
|
|
@@ -64,6 +66,7 @@ export type RelayFees = {
|
|
|
64
66
|
app: RelayCurrencyData;
|
|
65
67
|
};
|
|
66
68
|
export type QuoteDetails = {
|
|
69
|
+
currencyIn: RelayCurrencyData;
|
|
67
70
|
currencyOut: RelayCurrencyData;
|
|
68
71
|
rate: string;
|
|
69
72
|
slippageTolerance: {
|
|
@@ -3,6 +3,7 @@ import type { StepDataArgs, SwapErrorRight } from '../../../types';
|
|
|
3
3
|
import type { SunioRoute, SunioTransactionData } from '../types';
|
|
4
4
|
type BaseArgs = {
|
|
5
5
|
route: SunioRoute;
|
|
6
|
+
sellAmountCryptoBaseUnit: string;
|
|
6
7
|
};
|
|
7
8
|
export type GetSunioStepDataArgs = StepDataArgs<BaseArgs>;
|
|
8
9
|
type SunioRateStepData = {
|
|
@@ -6,12 +6,12 @@ const monads_1 = require("@sniptt/monads");
|
|
|
6
6
|
const utils_2 = require("../../../utils");
|
|
7
7
|
const estimateSunioNetworkFee_1 = require("./estimateSunioNetworkFee");
|
|
8
8
|
async function getSunioStepData(args) {
|
|
9
|
-
const { type, route, sellAsset, from, input, deps } = args;
|
|
9
|
+
const { type, route, sellAsset, sellAmountCryptoBaseUnit, from, input, deps } = args;
|
|
10
10
|
const estimateArgs = {
|
|
11
11
|
rpcUrl: deps.config.VITE_TRON_NODE_URL,
|
|
12
12
|
apiKey: deps.config.VITE_TRON_GRID_API_KEY,
|
|
13
13
|
route,
|
|
14
|
-
sellAmountCryptoBaseUnit
|
|
14
|
+
sellAmountCryptoBaseUnit,
|
|
15
15
|
isSellingNativeTrx: !(0, utils_1.contractAddressOrUndefined)(sellAsset.assetId),
|
|
16
16
|
address: from,
|
|
17
17
|
slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal,
|
|
@@ -83,7 +83,12 @@ const getSunioTradeContext = async ({ input, deps, }) => {
|
|
|
83
83
|
}),
|
|
84
84
|
},
|
|
85
85
|
protocolFees,
|
|
86
|
-
stepDataArgs: {
|
|
86
|
+
stepDataArgs: {
|
|
87
|
+
deps,
|
|
88
|
+
sellAsset,
|
|
89
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
90
|
+
route: bestRoute,
|
|
91
|
+
},
|
|
87
92
|
});
|
|
88
93
|
}
|
|
89
94
|
catch (error) {
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -93,6 +93,7 @@ export declare enum TradeQuoteError {
|
|
|
93
93
|
NoRouteFound = "NoRouteFound",
|
|
94
94
|
UnsupportedChain = "UnsupportedChain",
|
|
95
95
|
CrossChainNotSupported = "CrossChainNotSupported",
|
|
96
|
+
ExactOutputNotSupported = "ExactOutputNotSupported",
|
|
96
97
|
NetworkFeeEstimationFailed = "NetworkFeeEstimationFailed",
|
|
97
98
|
TradingHalted = "TradingHalted",
|
|
98
99
|
SellAmountBelowMinimum = "SellAmountBelowMinimum",
|
|
@@ -212,17 +213,30 @@ export type GetUtxoTradeRateInput = CommonTradeRateInput & {
|
|
|
212
213
|
export type GetUtxoTradeQuoteInput = GetUtxoTradeQuoteWithWallet;
|
|
213
214
|
export type GetTradeQuoteInput = GetUtxoTradeQuoteInput | GetEvmTradeQuoteInput | GetCosmosSdkTradeQuoteInput | GetTronTradeQuoteInput | GetNearTradeQuoteInput | GetTonTradeQuoteInput | GetSolanaTradeQuoteInput | GetStarknetTradeQuoteInput | GetSuiTradeQuoteInput;
|
|
214
215
|
export type GetTradeRateInput = GetEvmTradeRateInput | GetCosmosSdkTradeRateInput | GetUtxoTradeRateInput | GetTronTradeRateInput | GetNearTradeRateInput | GetTonTradeRateInput | GetSolanaTradeRateInput | GetStarknetTradeRateInput | GetSuiTradeRateInput;
|
|
216
|
+
export type WithExactBuyAmount<T extends {
|
|
217
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit: string;
|
|
218
|
+
}> = T extends unknown ? Omit<T, 'sellAmountIncludingProtocolFeesCryptoBaseUnit'> & {
|
|
219
|
+
buyAmountCryptoBaseUnit: string;
|
|
220
|
+
} : never;
|
|
221
|
+
export type GetExactOutputTradeQuoteInput = WithExactBuyAmount<GetTradeQuoteInput>;
|
|
222
|
+
export type GetExactOutputTradeRateInput = WithExactBuyAmount<GetTradeRateInput>;
|
|
223
|
+
export type TradeAmount = {
|
|
224
|
+
direction: 'exactIn' | 'exactOut';
|
|
225
|
+
cryptoBaseUnit: string;
|
|
226
|
+
};
|
|
215
227
|
type StepDataBaseArgs = {
|
|
216
228
|
deps: SwapperDeps;
|
|
217
229
|
sellAsset: Asset;
|
|
218
230
|
};
|
|
231
|
+
type StepDataRateInput = GetTradeRateInput | GetExactOutputTradeRateInput;
|
|
232
|
+
type StepDataQuoteInput = GetTradeQuoteInput | GetExactOutputTradeQuoteInput;
|
|
219
233
|
export type StepDataArgs<Base, Rate = unknown, Quote = unknown> = (StepDataBaseArgs & Base & {
|
|
220
234
|
type: 'rate';
|
|
221
|
-
input:
|
|
235
|
+
input: StepDataRateInput;
|
|
222
236
|
from?: string;
|
|
223
237
|
} & Rate) | (StepDataBaseArgs & Base & {
|
|
224
238
|
type: 'quote';
|
|
225
|
-
input:
|
|
239
|
+
input: StepDataQuoteInput;
|
|
226
240
|
from: string;
|
|
227
241
|
} & Quote);
|
|
228
242
|
export type EvmSwapperDeps = {
|
|
@@ -355,6 +369,7 @@ export type TradeCommon = {
|
|
|
355
369
|
slippageTolerancePercentageDecimal: string | undefined;
|
|
356
370
|
isLongtail?: boolean;
|
|
357
371
|
swapperName: SwapperName;
|
|
372
|
+
isExactOutput?: boolean;
|
|
358
373
|
};
|
|
359
374
|
type TradeQuoteBase = TradeCommon & {
|
|
360
375
|
receiveAddress: string | undefined;
|
|
@@ -584,6 +599,8 @@ export type SwapperApi = {
|
|
|
584
599
|
checkTradeStatus: (input: CheckTradeStatusInput) => Promise<TradeStatus>;
|
|
585
600
|
getTradeQuote: (input: GetTradeQuoteInput, deps: SwapperDeps) => Promise<TradeQuoteResult>;
|
|
586
601
|
getTradeRate: (input: GetTradeRateInput, deps: SwapperDeps) => Promise<TradeRateResult>;
|
|
602
|
+
getExactOutputTradeQuote?: (input: GetExactOutputTradeQuoteInput, deps: SwapperDeps) => Promise<TradeQuoteResult>;
|
|
603
|
+
getExactOutputTradeRate?: (input: GetExactOutputTradeRateInput, deps: SwapperDeps) => Promise<TradeRateResult>;
|
|
587
604
|
getUnsignedEvmTransaction?: (input: GetUnsignedEvmTransactionArgs) => Promise<SignTx<EvmChainId>>;
|
|
588
605
|
getUnsignedEvmMessage?: (input: GetUnsignedEvmMessageArgs) => Promise<EvmMessageToSign>;
|
|
589
606
|
getUnsignedUtxoTransaction?: (input: GetUnsignedUtxoTransactionArgs) => Promise<SignTx<UtxoChainId>>;
|
package/dist/cjs/types.js
CHANGED
|
@@ -33,6 +33,8 @@ var TradeQuoteError;
|
|
|
33
33
|
TradeQuoteError["UnsupportedChain"] = "UnsupportedChain";
|
|
34
34
|
// the swapper can't swap across chains
|
|
35
35
|
TradeQuoteError["CrossChainNotSupported"] = "CrossChainNotSupported";
|
|
36
|
+
// the swapper can quote this pair, but can't derive a sell amount from an exact buy amount
|
|
37
|
+
TradeQuoteError["ExactOutputNotSupported"] = "ExactOutputNotSupported";
|
|
36
38
|
// the swapper wasn't able to get a network fee estimate
|
|
37
39
|
TradeQuoteError["NetworkFeeEstimationFailed"] = "NetworkFeeEstimationFailed";
|
|
38
40
|
// trading has been halted upstream
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { AssetId, ChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import type { TradeAmount } from '../types';
|
|
2
3
|
export declare const FALLBACK_QUOTE_DEADLINE_MS = 60000;
|
|
4
|
+
export declare const getTradeAmount: (input: {
|
|
5
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit: string;
|
|
6
|
+
} | {
|
|
7
|
+
buyAmountCryptoBaseUnit: string;
|
|
8
|
+
}) => TradeAmount;
|
|
3
9
|
export declare const normalizeEpochToMs: (value: number) => number;
|
|
4
10
|
export declare const isNativeEvmAsset: (assetId: AssetId) => boolean;
|
|
5
11
|
export declare const getTreasuryAddressFromChainId: (chainId: ChainId) => string;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTreasuryAddressFromChainId = exports.isNativeEvmAsset = exports.normalizeEpochToMs = exports.FALLBACK_QUOTE_DEADLINE_MS = void 0;
|
|
3
|
+
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
7
|
// Deadline for providers without their own expiry - short enough to keep priced amounts honest
|
|
8
8
|
exports.FALLBACK_QUOTE_DEADLINE_MS = 60_000;
|
|
9
|
+
const getTradeAmount = (input) => 'buyAmountCryptoBaseUnit' in input
|
|
10
|
+
? { direction: 'exactOut', cryptoBaseUnit: input.buyAmountCryptoBaseUnit }
|
|
11
|
+
: { direction: 'exactIn', cryptoBaseUnit: input.sellAmountIncludingProtocolFeesCryptoBaseUnit };
|
|
12
|
+
exports.getTradeAmount = getTradeAmount;
|
|
9
13
|
// Bands are unambiguous for any realistic date: unix s land ~2e9, ms ~2e12, µs ~2e15, ns ~2e18
|
|
10
14
|
const normalizeEpochToMs = (value) => {
|
|
11
15
|
if (value < 1e12)
|