@shapeshiftoss/swapper 18.1.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/constant.js +2 -1
- package/dist/cjs/swappers/AcrossSwapper/endpoints.js +1 -1
- package/dist/cjs/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.js +2 -1
- package/dist/cjs/swappers/AcrossSwapper/utils/acrossService.d.ts +6 -3
- package/dist/cjs/swappers/AcrossSwapper/utils/acrossService.js +5 -1
- package/dist/cjs/swappers/AcrossSwapper/utils/fetchAcrossTrade.js +1 -1
- 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.d.ts +1 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossTradeContext.js +2 -0
- package/dist/cjs/swappers/ArbitrumBridgeSwapper/getTradeQuote/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +3 -1
- package/dist/cjs/swappers/AvnuSwapper/utils/getAvnuTradeContext.d.ts +1 -0
- package/dist/cjs/swappers/AvnuSwapper/utils/getAvnuTradeContext.js +1 -0
- package/dist/cjs/swappers/BebopSwapper/getBebopSolanaTradeQuote/getBebopSolanaTradeQuote.js +5 -2
- package/dist/cjs/swappers/BebopSwapper/getBebopTradeQuote/getBebopTradeQuote.js +2 -1
- package/dist/cjs/swappers/BebopSwapper/types.d.ts +2 -2
- package/dist/cjs/swappers/BebopSwapper/types.js +2 -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.d.ts +1 -0
- package/dist/cjs/swappers/BebopSwapper/utils/getBebopTradeContext.js +2 -0
- package/dist/cjs/swappers/BebopSwapper/utils/helpers.d.ts +1 -1
- package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/ButterSwap/utils/helpers.js +10 -8
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/ChainflipSwapper/constants.d.ts +1 -0
- package/dist/cjs/swappers/ChainflipSwapper/constants.js +3 -1
- package/dist/cjs/swappers/ChainflipSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +1 -0
- package/dist/cjs/swappers/DebridgeSwapper/constant.js +10 -8
- package/dist/cjs/swappers/DebridgeSwapper/getTradeQuote/getTradeQuote.js +2 -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 +5 -1
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.d.ts +2 -1
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +21 -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/getPortalsTradeQuote/getPortalsTradeQuote.js +11 -0
- 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/constant.js +4 -3
- package/dist/cjs/swappers/RelaySwapper/endpoints.js +12 -2
- package/dist/cjs/swappers/RelaySwapper/getTradeQuote/getTradeQuote.d.ts +2 -1
- package/dist/cjs/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +7 -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/fetchRelayTrade.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getLatestRelayStatusMessage.js +3 -1
- 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/notifyTransactionIndexing.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/relayService.d.ts +6 -3
- package/dist/cjs/swappers/RelaySwapper/utils/relayService.js +3 -1
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +5 -0
- package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +6 -3
- package/dist/cjs/swappers/StonfiSwapper/endpoints.js +40 -14
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +2 -0
- 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/getTradeQuote/getTradeQuote.test.js +2 -0
- package/dist/cjs/swappers/ThorchainSwapper/utils/getLongtailQuote.js +2 -0
- package/dist/cjs/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.js +1 -0
- package/dist/cjs/swappers/ZrxSwapper/types.d.ts +1 -1
- package/dist/cjs/swappers/ZrxSwapper/types.js +1 -0
- package/dist/cjs/swappers/ZrxSwapper/utils/constants.js +1 -0
- package/dist/cjs/swappers/ZrxSwapper/utils/helpers.d.ts +1 -1
- package/dist/cjs/swappers/ZrxSwapper/utils/helpers.js +5 -0
- package/dist/cjs/types.d.ts +22 -2
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils/helpers.d.ts +8 -0
- package/dist/cjs/utils/helpers.js +18 -1
- package/dist/cjs/utils/helpers.test.js +17 -0
- package/dist/cjs/utils/test-data/setupSwapQuote.js +1 -0
- package/dist/cjs/utils/thorchain/getThorL1TradeQuote.js +3 -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/constant.js +4 -3
- package/dist/esm/swappers/AcrossSwapper/endpoints.js +2 -2
- package/dist/esm/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.js +2 -1
- package/dist/esm/swappers/AcrossSwapper/utils/acrossService.d.ts +6 -3
- package/dist/esm/swappers/AcrossSwapper/utils/acrossService.js +3 -0
- package/dist/esm/swappers/AcrossSwapper/utils/fetchAcrossTrade.js +2 -2
- 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.d.ts +1 -0
- package/dist/esm/swappers/AcrossSwapper/utils/getAcrossTradeContext.js +3 -1
- package/dist/esm/swappers/ArbitrumBridgeSwapper/getTradeQuote/getTradeQuote.js +2 -0
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +3 -1
- package/dist/esm/swappers/AvnuSwapper/utils/getAvnuTradeContext.d.ts +1 -0
- package/dist/esm/swappers/AvnuSwapper/utils/getAvnuTradeContext.js +2 -1
- package/dist/esm/swappers/BebopSwapper/getBebopSolanaTradeQuote/getBebopSolanaTradeQuote.js +3 -0
- package/dist/esm/swappers/BebopSwapper/getBebopTradeQuote/getBebopTradeQuote.js +2 -1
- package/dist/esm/swappers/BebopSwapper/types.d.ts +2 -2
- package/dist/esm/swappers/BebopSwapper/types.js +2 -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.d.ts +1 -0
- package/dist/esm/swappers/BebopSwapper/utils/getBebopTradeContext.js +3 -1
- package/dist/esm/swappers/BebopSwapper/utils/helpers.d.ts +1 -1
- package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.js +2 -0
- package/dist/esm/swappers/ButterSwap/utils/helpers.js +10 -8
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/esm/swappers/ChainflipSwapper/constants.d.ts +1 -0
- package/dist/esm/swappers/ChainflipSwapper/constants.js +2 -0
- package/dist/esm/swappers/ChainflipSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +1 -0
- package/dist/esm/swappers/DebridgeSwapper/constant.js +11 -9
- package/dist/esm/swappers/DebridgeSwapper/getTradeQuote/getTradeQuote.js +2 -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 +7 -3
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.d.ts +2 -1
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +14 -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/getPortalsTradeQuote/getPortalsTradeQuote.js +12 -1
- 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/constant.js +6 -5
- package/dist/esm/swappers/RelaySwapper/endpoints.js +15 -5
- package/dist/esm/swappers/RelaySwapper/getTradeQuote/getTradeQuote.d.ts +2 -1
- package/dist/esm/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +5 -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/fetchRelayTrade.js +2 -2
- package/dist/esm/swappers/RelaySwapper/utils/getLatestRelayStatusMessage.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/notifyTransactionIndexing.js +2 -2
- package/dist/esm/swappers/RelaySwapper/utils/relayService.d.ts +6 -3
- package/dist/esm/swappers/RelaySwapper/utils/relayService.js +1 -0
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +5 -0
- package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +6 -3
- package/dist/esm/swappers/StonfiSwapper/endpoints.js +41 -15
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/esm/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +2 -0
- 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/getTradeQuote/getTradeQuote.test.js +2 -0
- package/dist/esm/swappers/ThorchainSwapper/utils/getLongtailQuote.js +2 -0
- package/dist/esm/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.js +2 -1
- package/dist/esm/swappers/ZrxSwapper/types.d.ts +1 -1
- package/dist/esm/swappers/ZrxSwapper/types.js +1 -0
- package/dist/esm/swappers/ZrxSwapper/utils/constants.js +1 -0
- package/dist/esm/swappers/ZrxSwapper/utils/helpers.d.ts +1 -1
- package/dist/esm/swappers/ZrxSwapper/utils/helpers.js +5 -0
- package/dist/esm/types.d.ts +22 -2
- package/dist/esm/types.js +2 -0
- package/dist/esm/utils/helpers.d.ts +8 -0
- package/dist/esm/utils/helpers.js +15 -0
- package/dist/esm/utils/helpers.test.js +18 -1
- package/dist/esm/utils/test-data/setupSwapQuote.js +1 -0
- package/dist/esm/utils/thorchain/getThorL1TradeQuote.js +3 -0
- package/package.json +7 -7
|
@@ -7,28 +7,30 @@ exports.DEFAULT_DEBRIDGE_USER_ADDRESS = exports.DEFAULT_DEBRIDGE_TOKEN_ADDRESS =
|
|
|
7
7
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
8
8
|
const invert_1 = __importDefault(require("lodash/invert"));
|
|
9
9
|
const viem_1 = require("viem");
|
|
10
|
+
const chains_1 = require("viem/chains");
|
|
10
11
|
exports.chainIdToDebridgeChainId = {
|
|
11
|
-
[caip_1.ethChainId]:
|
|
12
|
-
[caip_1.optimismChainId]:
|
|
13
|
-
[caip_1.bscChainId]:
|
|
12
|
+
[caip_1.ethChainId]: chains_1.mainnet.id,
|
|
13
|
+
[caip_1.optimismChainId]: chains_1.optimism.id,
|
|
14
|
+
[caip_1.bscChainId]: chains_1.bsc.id,
|
|
14
15
|
[caip_1.gnosisChainId]: 100000002,
|
|
15
|
-
[caip_1.polygonChainId]:
|
|
16
|
+
[caip_1.polygonChainId]: chains_1.polygon.id,
|
|
16
17
|
[caip_1.monadChainId]: 100000030,
|
|
17
18
|
[caip_1.hyperEvmChainId]: 100000022,
|
|
18
19
|
[caip_1.seiChainId]: 100000027,
|
|
19
|
-
[caip_1.baseChainId]:
|
|
20
|
+
[caip_1.baseChainId]: chains_1.base.id,
|
|
20
21
|
[caip_1.plasmaChainId]: 100000028,
|
|
21
|
-
[caip_1.arbitrumChainId]:
|
|
22
|
-
[caip_1.avalancheChainId]:
|
|
22
|
+
[caip_1.arbitrumChainId]: chains_1.arbitrum.id,
|
|
23
|
+
[caip_1.avalancheChainId]: chains_1.avalanche.id,
|
|
23
24
|
[caip_1.mantleChainId]: 100000023,
|
|
24
25
|
[caip_1.cronosChainId]: 100000019,
|
|
25
26
|
[caip_1.berachainChainId]: 100000020,
|
|
26
|
-
[caip_1.lineaChainId]:
|
|
27
|
+
[caip_1.lineaChainId]: chains_1.linea.id,
|
|
27
28
|
[caip_1.bobChainId]: 100000021,
|
|
28
29
|
[caip_1.sonicChainId]: 100000014,
|
|
29
30
|
[caip_1.storyChainId]: 100000013,
|
|
30
31
|
[caip_1.flowEvmChainId]: 100000009,
|
|
31
32
|
[caip_1.megaethChainId]: 100000031,
|
|
33
|
+
[caip_1.robinhoodChainId]: chains_1.robinhood.id,
|
|
32
34
|
};
|
|
33
35
|
exports.debridgeChainIdToChainId = (0, invert_1.default)(exports.chainIdToDebridgeChainId);
|
|
34
36
|
exports.DEBRIDGE_SUPPORTED_CHAIN_IDS = Object.keys(exports.chainIdToDebridgeChainId);
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getTradeQuote = void 0;
|
|
4
4
|
const monads_1 = require("@sniptt/monads");
|
|
5
5
|
const utils_1 = require("../../../utils");
|
|
6
|
+
const helpers_1 = require("../../../utils/helpers");
|
|
6
7
|
const getDebridgeStepData_1 = require("../utils/getDebridgeStepData");
|
|
7
8
|
const getDebridgeTradeContext_1 = require("../utils/getDebridgeTradeContext");
|
|
8
9
|
const getTradeQuote = async (input, deps) => {
|
|
@@ -26,6 +27,7 @@ const getTradeQuote = async (input, deps) => {
|
|
|
26
27
|
const tradeQuote = {
|
|
27
28
|
...tradeCommon,
|
|
28
29
|
quoteOrRate: 'quote',
|
|
30
|
+
deadline: Date.now() + helpers_1.FALLBACK_QUOTE_DEADLINE_MS,
|
|
29
31
|
receiveAddress,
|
|
30
32
|
steps: [
|
|
31
33
|
{
|
|
@@ -3,6 +3,7 @@ import type { StepDataArgs, SwapErrorRight, TxBuildData } from '../../../types';
|
|
|
3
3
|
import type { DebridgeTx } from './types';
|
|
4
4
|
type BaseArgs = {
|
|
5
5
|
tx: DebridgeTx;
|
|
6
|
+
sellAmountCryptoBaseUnit: string;
|
|
6
7
|
gasLimit: string | undefined;
|
|
7
8
|
spenderAddress: string;
|
|
8
9
|
fallbackNetworkFeeCryptoBaseUnit: string | undefined;
|
|
@@ -6,7 +6,7 @@ const monads_1 = require("@sniptt/monads");
|
|
|
6
6
|
const utils_1 = require("../../../utils");
|
|
7
7
|
const evm_1 = require("../../../utils/evm");
|
|
8
8
|
async function getDebridgeStepData(args) {
|
|
9
|
-
const { tx, gasLimit, spenderAddress, fallbackNetworkFeeCryptoBaseUnit, sellAsset, from, type, input, deps, } = args;
|
|
9
|
+
const { tx, sellAmountCryptoBaseUnit, gasLimit, spenderAddress, fallbackNetworkFeeCryptoBaseUnit, sellAsset, from, type, input, deps, } = args;
|
|
10
10
|
const adapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
|
|
11
11
|
const supportsEIP1559 = 'supportsEIP1559' in input ? input.supportsEIP1559 : false;
|
|
12
12
|
const transactionData = {
|
|
@@ -19,7 +19,7 @@ async function getDebridgeStepData(args) {
|
|
|
19
19
|
};
|
|
20
20
|
const stateOverride = {
|
|
21
21
|
sellAsset,
|
|
22
|
-
sellAmountCryptoBaseUnit
|
|
22
|
+
sellAmountCryptoBaseUnit,
|
|
23
23
|
spenderAddress,
|
|
24
24
|
};
|
|
25
25
|
if (type === 'rate') {
|
|
@@ -84,6 +84,7 @@ const getDebridgeTradeContext = async ({ input, deps, senderAddress, recipientAd
|
|
|
84
84
|
protocolFees: quote.protocolFees,
|
|
85
85
|
stepDataArgs: {
|
|
86
86
|
tx: quote.tx,
|
|
87
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
87
88
|
gasLimit: quote.gasLimit,
|
|
88
89
|
fallbackNetworkFeeCryptoBaseUnit: quote.fallbackNetworkFeeCryptoBaseUnit,
|
|
89
90
|
sellAsset,
|
|
@@ -14,6 +14,8 @@ const oneClickService_1 = require("./utils/oneClickService");
|
|
|
14
14
|
exports.nearIntentsApi = {
|
|
15
15
|
getTradeQuote: (input, deps) => (0, getTradeQuote_1.getTradeQuote)(input, deps),
|
|
16
16
|
getTradeRate: (input, deps) => (0, getTradeRate_1.getTradeRate)(input, deps),
|
|
17
|
+
getExactOutputTradeQuote: (input, deps) => (0, getTradeQuote_1.getExactOutputTradeQuote)(input, deps),
|
|
18
|
+
getExactOutputTradeRate: (input, deps) => (0, getTradeRate_1.getExactOutputTradeRate)(input, deps),
|
|
17
19
|
getUnsignedEvmTransaction: evm_1.getUnsignedEvmTransaction,
|
|
18
20
|
getEvmTransactionFees: evm_1.getEvmTransactionFees,
|
|
19
21
|
getUnsignedUtxoTransaction: utxo_1.getUnsignedUtxoTransaction,
|
|
@@ -166,7 +168,9 @@ exports.nearIntentsApi = {
|
|
|
166
168
|
const message = (0, helpers_1.getNearIntentsStatusMessage)(statusResponse.status);
|
|
167
169
|
// Extract buyTxHash from destination chain transactions
|
|
168
170
|
const buyTxHash = statusResponse.swapDetails?.destinationChainTxHashes?.[0]?.hash;
|
|
169
|
-
|
|
171
|
+
// amountOut is only meaningful destination-denominated on terminal success - in-flight and
|
|
172
|
+
// refund states may carry settlement-internal or refund values
|
|
173
|
+
const actualBuyAmountCryptoBaseUnit = statusResponse.status === 'SUCCESS' ? statusResponse.swapDetails?.amountOut : undefined;
|
|
170
174
|
return {
|
|
171
175
|
status: txStatus,
|
|
172
176
|
buyTxHash,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Result } from '@sniptt/monads';
|
|
2
2
|
import type { SwapErrorRight, SwapperDeps, TradeQuote } from '../../../types';
|
|
3
|
-
import type { NearIntentsTradeQuoteInput } from '../types';
|
|
3
|
+
import type { NearIntentsExactOutputTradeQuoteInput, NearIntentsTradeQuoteInput } from '../types';
|
|
4
4
|
export declare const getTradeQuote: (input: NearIntentsTradeQuoteInput, deps: SwapperDeps) => Promise<Result<TradeQuote[], SwapErrorRight>>;
|
|
5
|
+
export declare const getExactOutputTradeQuote: (input: NearIntentsExactOutputTradeQuoteInput, deps: SwapperDeps) => Promise<Result<TradeQuote[], SwapErrorRight>>;
|
|
@@ -1,37 +1,39 @@
|
|
|
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
|
+
const helpers_1 = require("../../../utils/helpers");
|
|
6
7
|
const types_1 = require("../types");
|
|
7
8
|
const getNearIntentsStepData_1 = require("../utils/getNearIntentsStepData");
|
|
8
9
|
const getNearIntentsTradeContext_1 = require("../utils/getNearIntentsTradeContext");
|
|
9
|
-
const
|
|
10
|
+
const helpers_2 = require("../utils/helpers");
|
|
10
11
|
const oneClickService_1 = require("../utils/oneClickService");
|
|
11
|
-
const
|
|
12
|
-
const { sellAsset, buyAsset, accountNumber, affiliateBps
|
|
12
|
+
const getQuote = async (input, deps) => {
|
|
13
|
+
const { sellAsset, buyAsset, accountNumber, affiliateBps } = input;
|
|
13
14
|
const addresses = (0, utils_1.assertQuoteAddresses)(input);
|
|
14
15
|
if (addresses.isErr())
|
|
15
16
|
return (0, monads_1.Err)(addresses.unwrapErr());
|
|
16
17
|
const { sendAddress, receiveAddress } = addresses.unwrap();
|
|
17
18
|
(0, oneClickService_1.initializeOneClickService)(deps.config.VITE_NEAR_INTENTS_API_KEY);
|
|
18
|
-
const
|
|
19
|
+
const amount = (0, helpers_1.getTradeAmount)(input);
|
|
20
|
+
const maybeAssets = await (0, helpers_2.resolveNearIntentsAssets)({ sellAsset, buyAsset });
|
|
19
21
|
if (maybeAssets.isErr())
|
|
20
22
|
return (0, monads_1.Err)(maybeAssets.unwrapErr());
|
|
21
23
|
const { originAsset, destinationAsset } = maybeAssets.unwrap();
|
|
22
|
-
const quoteRequest = (0,
|
|
24
|
+
const quoteRequest = (0, helpers_2.buildNearIntentsQuoteRequest)({
|
|
23
25
|
originAsset,
|
|
24
26
|
destinationAsset,
|
|
25
|
-
|
|
27
|
+
amount,
|
|
26
28
|
slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal,
|
|
27
29
|
affiliateBps,
|
|
28
30
|
refundTo: sendAddress,
|
|
29
31
|
recipient: receiveAddress,
|
|
30
32
|
refundType: types_1.QuoteRequest.refundType.ORIGIN_CHAIN,
|
|
31
33
|
recipientType: types_1.QuoteRequest.recipientType.DESTINATION_CHAIN,
|
|
32
|
-
deadline: (0,
|
|
34
|
+
deadline: (0, helpers_2.getNearIntentsQuoteDeadline)({ sellAsset, buyAsset }),
|
|
33
35
|
});
|
|
34
|
-
const maybeQuoteResponse = await (0,
|
|
36
|
+
const maybeQuoteResponse = await (0, helpers_2.fetchNearIntentsQuote)({ quoteRequest, sellAsset });
|
|
35
37
|
if (maybeQuoteResponse.isErr())
|
|
36
38
|
return (0, monads_1.Err)(maybeQuoteResponse.unwrapErr());
|
|
37
39
|
const { quote } = maybeQuoteResponse.unwrap();
|
|
@@ -48,9 +50,16 @@ const getTradeQuote = async (input, deps) => {
|
|
|
48
50
|
if (maybeStepData.isErr())
|
|
49
51
|
return (0, monads_1.Err)(maybeStepData.unwrapErr());
|
|
50
52
|
const { transactionData, networkFeeCryptoBaseUnit } = maybeStepData.unwrap();
|
|
53
|
+
const requestDeadlineMs = Date.parse(quoteRequest.deadline);
|
|
54
|
+
const responseDeadlineMs = Date.parse(quote.deadline ?? '');
|
|
51
55
|
const tradeQuote = {
|
|
52
56
|
...tradeCommon,
|
|
53
57
|
quoteOrRate: 'quote',
|
|
58
|
+
// Deposits mined after our requested refund deadline refund instead of executing as quoted;
|
|
59
|
+
// the response deadline (when the deposit address goes inactive, ~72h) only binds if tighter
|
|
60
|
+
deadline: Number.isFinite(responseDeadlineMs)
|
|
61
|
+
? Math.min(requestDeadlineMs, responseDeadlineMs)
|
|
62
|
+
: requestDeadlineMs,
|
|
54
63
|
receiveAddress,
|
|
55
64
|
steps: [
|
|
56
65
|
{
|
|
@@ -68,4 +77,7 @@ const getTradeQuote = async (input, deps) => {
|
|
|
68
77
|
};
|
|
69
78
|
return (0, monads_1.Ok)([tradeQuote]);
|
|
70
79
|
};
|
|
80
|
+
const getTradeQuote = (input, deps) => getQuote(input, deps);
|
|
71
81
|
exports.getTradeQuote = getTradeQuote;
|
|
82
|
+
const getExactOutputTradeQuote = (input, deps) => getQuote(input, deps);
|
|
83
|
+
exports.getExactOutputTradeQuote = getExactOutputTradeQuote;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Result } from '@sniptt/monads';
|
|
2
2
|
import type { SwapErrorRight, SwapperDeps, TradeRate } from '../../../types';
|
|
3
|
-
import type { NearIntentsTradeRateInput } from '../types';
|
|
3
|
+
import type { NearIntentsExactOutputTradeRateInput, NearIntentsTradeRateInput } from '../types';
|
|
4
4
|
export declare const getTradeRate: (input: NearIntentsTradeRateInput, deps: SwapperDeps) => Promise<Result<TradeRate[], SwapErrorRight>>;
|
|
5
|
+
export declare const getExactOutputTradeRate: (input: NearIntentsExactOutputTradeRateInput, deps: SwapperDeps) => Promise<Result<TradeRate[], SwapErrorRight>>;
|
|
@@ -1,23 +1,25 @@
|
|
|
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
|
+
const helpers_1 = require("../../../utils/helpers");
|
|
5
6
|
const types_1 = require("../types");
|
|
6
7
|
const getNearIntentsStepData_1 = require("../utils/getNearIntentsStepData");
|
|
7
8
|
const getNearIntentsTradeContext_1 = require("../utils/getNearIntentsTradeContext");
|
|
8
|
-
const
|
|
9
|
+
const helpers_2 = require("../utils/helpers");
|
|
9
10
|
const oneClickService_1 = require("../utils/oneClickService");
|
|
10
|
-
const
|
|
11
|
-
const { accountNumber, sellAsset, buyAsset, affiliateBps,
|
|
11
|
+
const getRate = async (input, deps) => {
|
|
12
|
+
const { accountNumber, sellAsset, buyAsset, affiliateBps, receiveAddress, sendAddress } = input;
|
|
12
13
|
(0, oneClickService_1.initializeOneClickService)(deps.config.VITE_NEAR_INTENTS_API_KEY);
|
|
13
|
-
const
|
|
14
|
+
const amount = (0, helpers_1.getTradeAmount)(input);
|
|
15
|
+
const maybeAssets = await (0, helpers_2.resolveNearIntentsAssets)({ sellAsset, buyAsset });
|
|
14
16
|
if (maybeAssets.isErr())
|
|
15
17
|
return (0, monads_1.Err)(maybeAssets.unwrapErr());
|
|
16
18
|
const { originAsset, destinationAsset } = maybeAssets.unwrap();
|
|
17
|
-
const quoteRequest = (0,
|
|
19
|
+
const quoteRequest = (0, helpers_2.buildNearIntentsQuoteRequest)({
|
|
18
20
|
originAsset,
|
|
19
21
|
destinationAsset,
|
|
20
|
-
|
|
22
|
+
amount,
|
|
21
23
|
slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal,
|
|
22
24
|
affiliateBps,
|
|
23
25
|
refundTo: sendAddress ?? 'check-price',
|
|
@@ -28,9 +30,9 @@ const getTradeRate = async (input, deps) => {
|
|
|
28
30
|
recipientType: sendAddress
|
|
29
31
|
? types_1.QuoteRequest.recipientType.DESTINATION_CHAIN
|
|
30
32
|
: types_1.QuoteRequest.recipientType.INTENTS,
|
|
31
|
-
deadline: (0,
|
|
33
|
+
deadline: (0, helpers_2.getNearIntentsQuoteDeadline)({ sellAsset, buyAsset }),
|
|
32
34
|
});
|
|
33
|
-
const maybeQuoteResponse = await (0,
|
|
35
|
+
const maybeQuoteResponse = await (0, helpers_2.fetchNearIntentsQuote)({ quoteRequest, sellAsset });
|
|
34
36
|
if (maybeQuoteResponse.isErr())
|
|
35
37
|
return (0, monads_1.Err)(maybeQuoteResponse.unwrapErr());
|
|
36
38
|
const { quote } = maybeQuoteResponse.unwrap();
|
|
@@ -61,4 +63,7 @@ const getTradeRate = async (input, deps) => {
|
|
|
61
63
|
};
|
|
62
64
|
return (0, monads_1.Ok)([tradeRate]);
|
|
63
65
|
};
|
|
66
|
+
const getTradeRate = (input, deps) => getRate(input, deps);
|
|
64
67
|
exports.getTradeRate = getTradeRate;
|
|
68
|
+
const getExactOutputTradeRate = (input, deps) => getRate(input, deps);
|
|
69
|
+
exports.getExactOutputTradeRate = getExactOutputTradeRate;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
2
|
-
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetNearTradeQuoteInput, GetNearTradeRateInput, GetSolanaTradeQuoteInput, GetSolanaTradeRateInput, GetStarknetTradeQuoteInput, GetStarknetTradeRateInput, GetSuiTradeQuoteInput, GetSuiTradeRateInput, GetTonTradeQuoteInput, GetTonTradeRateInput, GetTronTradeQuoteInput, GetTronTradeRateInput, GetUtxoTradeQuoteInput, GetUtxoTradeRateInput } from '../../types';
|
|
2
|
+
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetNearTradeQuoteInput, GetNearTradeRateInput, GetSolanaTradeQuoteInput, GetSolanaTradeRateInput, GetStarknetTradeQuoteInput, GetStarknetTradeRateInput, GetSuiTradeQuoteInput, GetSuiTradeRateInput, GetTonTradeQuoteInput, GetTonTradeRateInput, GetTronTradeQuoteInput, GetTronTradeRateInput, GetUtxoTradeQuoteInput, GetUtxoTradeRateInput, WithExactBuyAmount } from '../../types';
|
|
3
3
|
export type NearIntentsTradeQuoteInput = GetEvmTradeQuoteInput | GetUtxoTradeQuoteInput | GetSolanaTradeQuoteInput | GetTronTradeQuoteInput | GetSuiTradeQuoteInput | GetStarknetTradeQuoteInput | GetNearTradeQuoteInput | GetTonTradeQuoteInput;
|
|
4
4
|
export type NearIntentsTradeRateInput = GetEvmTradeRateInput | GetUtxoTradeRateInput | GetSolanaTradeRateInput | GetTronTradeRateInput | GetSuiTradeRateInput | GetStarknetTradeRateInput | GetNearTradeRateInput | GetTonTradeRateInput;
|
|
5
|
+
export type NearIntentsExactOutputTradeQuoteInput = WithExactBuyAmount<NearIntentsTradeQuoteInput>;
|
|
6
|
+
export type NearIntentsExactOutputTradeRateInput = WithExactBuyAmount<NearIntentsTradeRateInput>;
|
|
5
7
|
export type NearIntentsMetadata = {
|
|
6
8
|
name: 'nearIntents';
|
|
7
9
|
depositAddress: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
const BASE_ARGS = {
|
|
7
|
+
originAsset: 'nep141:base-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913.omft.near',
|
|
8
|
+
destinationAsset: 'nep141:btc.omft.near',
|
|
9
|
+
amount: { direction: 'exactIn', cryptoBaseUnit: '65000000' },
|
|
10
|
+
slippageTolerancePercentageDecimal: '0.01',
|
|
11
|
+
affiliateBps: '10',
|
|
12
|
+
refundTo: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
|
|
13
|
+
recipient: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
|
|
14
|
+
refundType: types_1.QuoteRequest.refundType.ORIGIN_CHAIN,
|
|
15
|
+
recipientType: types_1.QuoteRequest.recipientType.DESTINATION_CHAIN,
|
|
16
|
+
deadline: '2026-08-10T23:59:00.000Z',
|
|
17
|
+
};
|
|
18
|
+
const EXACT_OUTPUT_AMOUNT = {
|
|
19
|
+
direction: 'exactOut',
|
|
20
|
+
cryptoBaseUnit: '100000',
|
|
21
|
+
};
|
|
22
|
+
(0, vitest_1.describe)('buildNearIntentsQuoteRequest', () => {
|
|
23
|
+
(0, vitest_1.describe)('exact input', () => {
|
|
24
|
+
(0, vitest_1.it)('requests EXACT_INPUT with the sell amount', () => {
|
|
25
|
+
const request = (0, helpers_1.buildNearIntentsQuoteRequest)(BASE_ARGS);
|
|
26
|
+
(0, vitest_1.expect)(request.swapType).toEqual(types_1.QuoteRequest.swapType.EXACT_INPUT);
|
|
27
|
+
(0, vitest_1.expect)(request.amount).toEqual('65000000');
|
|
28
|
+
});
|
|
29
|
+
(0, vitest_1.it)('passes the requested slippage through untouched', () => {
|
|
30
|
+
const request = (0, helpers_1.buildNearIntentsQuoteRequest)({
|
|
31
|
+
...BASE_ARGS,
|
|
32
|
+
slippageTolerancePercentageDecimal: '0',
|
|
33
|
+
});
|
|
34
|
+
(0, vitest_1.expect)(request.slippageTolerance).toEqual(0);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
(0, vitest_1.describe)('exact output', () => {
|
|
38
|
+
(0, vitest_1.it)('requests EXACT_OUTPUT with the buy amount', () => {
|
|
39
|
+
const request = (0, helpers_1.buildNearIntentsQuoteRequest)({ ...BASE_ARGS, amount: EXACT_OUTPUT_AMOUNT });
|
|
40
|
+
(0, vitest_1.expect)(request.swapType).toEqual(types_1.QuoteRequest.swapType.EXACT_OUTPUT);
|
|
41
|
+
(0, vitest_1.expect)(request.amount).toEqual('100000');
|
|
42
|
+
});
|
|
43
|
+
// A tighter band is the user's call - the failure mode is a refund, not a loss
|
|
44
|
+
(0, vitest_1.it)('passes a requested zero slippage through untouched, as exact input does', () => {
|
|
45
|
+
const request = (0, helpers_1.buildNearIntentsQuoteRequest)({
|
|
46
|
+
...BASE_ARGS,
|
|
47
|
+
amount: EXACT_OUTPUT_AMOUNT,
|
|
48
|
+
slippageTolerancePercentageDecimal: '0',
|
|
49
|
+
});
|
|
50
|
+
(0, vitest_1.expect)(request.slippageTolerance).toEqual(0);
|
|
51
|
+
});
|
|
52
|
+
(0, vitest_1.it)('honours a requested slippage', () => {
|
|
53
|
+
const request = (0, helpers_1.buildNearIntentsQuoteRequest)({
|
|
54
|
+
...BASE_ARGS,
|
|
55
|
+
amount: EXACT_OUTPUT_AMOUNT,
|
|
56
|
+
slippageTolerancePercentageDecimal: '0.05',
|
|
57
|
+
});
|
|
58
|
+
(0, vitest_1.expect)(request.slippageTolerance).toEqual(500);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Asset } from '@shapeshiftoss/types';
|
|
2
2
|
import type { Result } from '@sniptt/monads';
|
|
3
3
|
import type { QuoteFeeData, SwapErrorRight, SwapperDeps, TradeCommon, TradeStepCommon } from '../../../types';
|
|
4
|
-
import type { NearIntentsTradeQuoteInput, NearIntentsTradeRateInput, QuoteResponse } from '../types';
|
|
4
|
+
import type { NearIntentsExactOutputTradeQuoteInput, NearIntentsExactOutputTradeRateInput, NearIntentsTradeQuoteInput, NearIntentsTradeRateInput, QuoteResponse } from '../types';
|
|
5
5
|
type NearIntentsTradeContext = {
|
|
6
6
|
tradeCommon: TradeCommon;
|
|
7
7
|
stepCommon: Omit<TradeStepCommon, 'feeData'>;
|
|
@@ -14,7 +14,7 @@ type NearIntentsTradeContext = {
|
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
16
|
export declare const getNearIntentsTradeContext: ({ input, deps, quote, }: {
|
|
17
|
-
input: NearIntentsTradeQuoteInput | NearIntentsTradeRateInput;
|
|
17
|
+
input: NearIntentsTradeQuoteInput | NearIntentsTradeRateInput | NearIntentsExactOutputTradeQuoteInput | NearIntentsExactOutputTradeRateInput;
|
|
18
18
|
deps: SwapperDeps;
|
|
19
19
|
quote: QuoteResponse['quote'];
|
|
20
20
|
}) => Result<NearIntentsTradeContext, SwapErrorRight>;
|
|
@@ -10,7 +10,7 @@ const types_1 = require("../../../types");
|
|
|
10
10
|
const utils_2 = require("../../../utils");
|
|
11
11
|
const affiliateFee_1 = require("../../../utils/affiliateFee");
|
|
12
12
|
const getNearIntentsTradeContext = ({ input, deps, quote, }) => {
|
|
13
|
-
const { sellAsset, buyAsset, affiliateBps,
|
|
13
|
+
const { sellAsset, buyAsset, affiliateBps, slippageTolerancePercentageDecimal } = input;
|
|
14
14
|
if (!quote.depositAddress)
|
|
15
15
|
return (0, monads_1.Err)((0, utils_2.makeTradeStepBuildFailedErr)('getNearIntentsTradeContext'));
|
|
16
16
|
const rate = (0, utils_2.getInputOutputRate)({
|
|
@@ -19,11 +19,13 @@ const getNearIntentsTradeContext = ({ input, deps, quote, }) => {
|
|
|
19
19
|
sellAsset,
|
|
20
20
|
buyAsset,
|
|
21
21
|
});
|
|
22
|
+
const isExactOutput = 'buyAmountCryptoBaseUnit' in input;
|
|
22
23
|
return (0, monads_1.Ok)({
|
|
23
24
|
tradeCommon: {
|
|
24
25
|
id: (0, uuid_1.v4)(),
|
|
25
26
|
rate,
|
|
26
27
|
swapperName: types_1.SwapperName.NearIntents,
|
|
28
|
+
isExactOutput,
|
|
27
29
|
affiliateBps,
|
|
28
30
|
slippageTolerancePercentageDecimal: slippageTolerancePercentageDecimal ??
|
|
29
31
|
(0, constants_1.getDefaultSlippageDecimalPercentageForSwapper)(types_1.SwapperName.NearIntents),
|
|
@@ -54,7 +56,7 @@ const getNearIntentsTradeContext = ({ input, deps, quote, }) => {
|
|
|
54
56
|
stepDataArgs: {
|
|
55
57
|
deps,
|
|
56
58
|
sellAsset,
|
|
57
|
-
sellAmountCryptoBaseUnit:
|
|
59
|
+
sellAmountCryptoBaseUnit: quote.amountIn,
|
|
58
60
|
depositAddress: quote.depositAddress,
|
|
59
61
|
},
|
|
60
62
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Asset } from '@shapeshiftoss/types';
|
|
2
2
|
import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
3
3
|
import type { Result } from '@sniptt/monads';
|
|
4
|
-
import type { SwapErrorRight } from '../../../types';
|
|
4
|
+
import type { SwapErrorRight, TradeAmount } from '../../../types';
|
|
5
5
|
import type { GetExecutionStatusResponse, QuoteResponse } from '../types';
|
|
6
6
|
import { QuoteRequest } from '../types';
|
|
7
7
|
export declare const getNearIntentsAsset: ({ nearNetwork, contractAddress, }: {
|
|
@@ -20,10 +20,10 @@ export declare const getNearIntentsQuoteDeadline: ({ sellAsset, buyAsset, }: {
|
|
|
20
20
|
sellAsset: Asset;
|
|
21
21
|
buyAsset: Asset;
|
|
22
22
|
}) => string;
|
|
23
|
-
export declare const buildNearIntentsQuoteRequest: ({ originAsset, destinationAsset,
|
|
23
|
+
export declare const buildNearIntentsQuoteRequest: ({ originAsset, destinationAsset, amount, slippageTolerancePercentageDecimal, affiliateBps, refundTo, recipient, refundType, recipientType, deadline, }: {
|
|
24
24
|
originAsset: string;
|
|
25
25
|
destinationAsset: string;
|
|
26
|
-
|
|
26
|
+
amount: TradeAmount;
|
|
27
27
|
slippageTolerancePercentageDecimal: string | undefined;
|
|
28
28
|
affiliateBps: string;
|
|
29
29
|
refundTo: string;
|
|
@@ -134,29 +134,33 @@ const getNearIntentsQuoteDeadline = ({ sellAsset, buyAsset, }) => {
|
|
|
134
134
|
return new Date(Date.now() + deadlineMs).toISOString();
|
|
135
135
|
};
|
|
136
136
|
exports.getNearIntentsQuoteDeadline = getNearIntentsQuoteDeadline;
|
|
137
|
-
const buildNearIntentsQuoteRequest = ({ originAsset, destinationAsset,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
137
|
+
const buildNearIntentsQuoteRequest = ({ originAsset, destinationAsset, amount, slippageTolerancePercentageDecimal, affiliateBps, refundTo, recipient, refundType, recipientType, deadline, }) => {
|
|
138
|
+
return {
|
|
139
|
+
dry: false,
|
|
140
|
+
swapType: amount.direction === 'exactOut'
|
|
141
|
+
? types_2.QuoteRequest.swapType.EXACT_OUTPUT
|
|
142
|
+
: types_2.QuoteRequest.swapType.EXACT_INPUT,
|
|
143
|
+
slippageTolerance: slippageTolerancePercentageDecimal
|
|
144
|
+
? (0, utils_1.bnOrZero)(slippageTolerancePercentageDecimal).times(10000).toNumber()
|
|
145
|
+
: constants_1.DEFAULT_SLIPPAGE_BPS,
|
|
146
|
+
originAsset,
|
|
147
|
+
destinationAsset,
|
|
148
|
+
amount: amount.cryptoBaseUnit,
|
|
149
|
+
depositType: types_2.QuoteRequest.depositType.ORIGIN_CHAIN,
|
|
150
|
+
refundTo,
|
|
151
|
+
refundType,
|
|
152
|
+
recipient,
|
|
153
|
+
recipientType,
|
|
154
|
+
deadline,
|
|
155
|
+
referral: 'shapeshift',
|
|
156
|
+
appFees: [
|
|
157
|
+
{
|
|
158
|
+
recipient: utils_1.DAO_TREASURY_NEAR,
|
|
159
|
+
fee: Number(affiliateBps),
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
};
|
|
163
|
+
};
|
|
160
164
|
exports.buildNearIntentsQuoteRequest = buildNearIntentsQuoteRequest;
|
|
161
165
|
// One retry loop for the SDK's flaky WebSocket transport; maps provider errors to swap errors
|
|
162
166
|
const fetchNearIntentsQuote = async ({ quoteRequest, sellAsset, }) => {
|
|
@@ -128,9 +128,20 @@ const getPortalsTradeQuote = async (input, deps) => {
|
|
|
128
128
|
if (maybeStepData.isErr())
|
|
129
129
|
return (0, monads_1.Err)(maybeStepData.unwrapErr());
|
|
130
130
|
const { transactionData, networkFeeCryptoBaseUnit } = maybeStepData.unwrap();
|
|
131
|
+
// Nullable in practice (live validated orders return null) - numeric or ISO when supplied
|
|
132
|
+
const expiryMs = (() => {
|
|
133
|
+
if (!orderContext.expiry)
|
|
134
|
+
return undefined;
|
|
135
|
+
const numeric = Number(orderContext.expiry);
|
|
136
|
+
if (Number.isFinite(numeric))
|
|
137
|
+
return (0, helpers_1.normalizeEpochToMs)(numeric);
|
|
138
|
+
const parsed = Date.parse(orderContext.expiry);
|
|
139
|
+
return Number.isNaN(parsed) ? undefined : parsed;
|
|
140
|
+
})();
|
|
131
141
|
const tradeQuote = {
|
|
132
142
|
...tradeCommon,
|
|
133
143
|
quoteOrRate: 'quote',
|
|
144
|
+
deadline: expiryMs ?? Date.now() + helpers_1.FALLBACK_QUOTE_DEADLINE_MS,
|
|
134
145
|
receiveAddress,
|
|
135
146
|
steps: [
|
|
136
147
|
{
|
|
@@ -3,6 +3,7 @@ import type { StepDataArgs, SwapErrorRight, TxBuildData } from '../../../types';
|
|
|
3
3
|
import type { PortalsTx } from './fetchPortalsTradeOrder';
|
|
4
4
|
type BaseArgs = {
|
|
5
5
|
tx: PortalsTx;
|
|
6
|
+
sellAmountCryptoBaseUnit: string;
|
|
6
7
|
spenderAddress: string;
|
|
7
8
|
};
|
|
8
9
|
export type GetPortalsStepDataArgs = StepDataArgs<BaseArgs, {
|
|
@@ -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;
|
|
@@ -22,12 +22,12 @@ exports.chainIdToRelayChainId = {
|
|
|
22
22
|
[caip_1.gnosisChainId]: chains_1.gnosis.id,
|
|
23
23
|
[caip_1.avalancheChainId]: chains_1.avalanche.id,
|
|
24
24
|
[caip_1.bscChainId]: chains_1.bsc.id,
|
|
25
|
-
[caip_1.tronChainId]:
|
|
25
|
+
[caip_1.tronChainId]: chains_1.tron.id,
|
|
26
26
|
[caip_1.monadChainId]: chains_1.monad.id,
|
|
27
27
|
[caip_1.hyperEvmChainId]: chains_1.hyperEvm.id,
|
|
28
28
|
[caip_1.mantleChainId]: chains_1.mantle.id,
|
|
29
29
|
[caip_1.inkChainId]: chains_1.ink.id,
|
|
30
|
-
[caip_1.megaethChainId]:
|
|
30
|
+
[caip_1.megaethChainId]: chains_1.megaeth.id,
|
|
31
31
|
[caip_1.plasmaChainId]: chains_1.plasma.id,
|
|
32
32
|
[caip_1.katanaChainId]: chains_1.katana.id,
|
|
33
33
|
[caip_1.etherealChainId]: 5064014,
|
|
@@ -49,7 +49,8 @@ exports.chainIdToRelayChainId = {
|
|
|
49
49
|
[caip_1.modeChainId]: chains_1.mode.id,
|
|
50
50
|
[caip_1.soneiumChainId]: chains_1.soneium.id,
|
|
51
51
|
[caip_1.seiChainId]: chains_1.sei.id,
|
|
52
|
-
[caip_1.abstractChainId]:
|
|
52
|
+
[caip_1.abstractChainId]: chains_1.abstract.id,
|
|
53
|
+
[caip_1.robinhoodChainId]: chains_1.robinhood.id,
|
|
53
54
|
};
|
|
54
55
|
var RelayStatusMessage;
|
|
55
56
|
(function (RelayStatusMessage) {
|
|
@@ -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,
|
|
@@ -64,7 +70,7 @@ exports.relayApi = {
|
|
|
64
70
|
// relay.link tracks the swap by its origin chain transaction
|
|
65
71
|
const swapperTxId = txHash;
|
|
66
72
|
const swapperTxLink = `https://relay.link/transaction/${txHash}`;
|
|
67
|
-
const maybeStatusResponse = await relayService_1.relayService.get(`${config.VITE_RELAY_API_URL}/intents/status/
|
|
73
|
+
const maybeStatusResponse = await relayService_1.relayService.get(`${config.VITE_RELAY_API_URL}/intents/status/v3?requestId=${relayMetadata.relayId}`, (0, relayService_1.getRelayRequestConfig)(config));
|
|
68
74
|
if (maybeStatusResponse.isErr()) {
|
|
69
75
|
return {
|
|
70
76
|
buyTxHash: undefined,
|
|
@@ -79,9 +85,13 @@ exports.relayApi = {
|
|
|
79
85
|
switch (statusResponse.status) {
|
|
80
86
|
case 'success':
|
|
81
87
|
return unchained_client_1.TxStatus.Confirmed;
|
|
88
|
+
case 'waiting':
|
|
89
|
+
case 'delayed':
|
|
82
90
|
case 'pending':
|
|
91
|
+
case 'depositing':
|
|
92
|
+
case 'submitted':
|
|
83
93
|
return unchained_client_1.TxStatus.Pending;
|
|
84
|
-
case '
|
|
94
|
+
case 'failure':
|
|
85
95
|
case 'refund':
|
|
86
96
|
return unchained_client_1.TxStatus.Failed;
|
|
87
97
|
default:
|
|
@@ -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>>;
|