@shapeshiftoss/swapper 17.6.5 → 17.6.6-alpha.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/constants.js +17 -8
- package/dist/cjs/swappers/NearIntentsSwapper/NearIntentsSwapper.d.ts +2 -0
- package/dist/cjs/swappers/NearIntentsSwapper/NearIntentsSwapper.js +11 -0
- package/dist/cjs/swappers/NearIntentsSwapper/constants.d.ts +3 -0
- package/dist/cjs/swappers/NearIntentsSwapper/constants.js +6 -0
- package/dist/cjs/swappers/NearIntentsSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/NearIntentsSwapper/endpoints.js +165 -0
- package/dist/cjs/swappers/NearIntentsSwapper/index.d.ts +4 -0
- package/dist/cjs/swappers/NearIntentsSwapper/index.js +20 -0
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.d.ts +3 -0
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +209 -0
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.d.ts +3 -0
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +208 -0
- package/dist/cjs/swappers/NearIntentsSwapper/types.d.ts +6 -0
- package/dist/cjs/swappers/NearIntentsSwapper/types.js +32 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers/helpers.d.ts +12 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers/helpers.js +99 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/oneClickService.d.ts +3 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/oneClickService.js +16 -0
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +55 -12
- package/dist/cjs/swappers/RelaySwapper/constant.js +1 -0
- package/dist/cjs/swappers/RelaySwapper/utils/fetchRelayTrade.d.ts +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayPsbtRelayer.js +2 -2
- package/dist/cjs/swappers/RelaySwapper/utils/getTrade.js +45 -0
- package/dist/cjs/swappers/RelaySwapper/utils/notifyTransactionIndexing.d.ts +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +0 -2
- package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +1 -0
- package/dist/cjs/swappers/RelaySwapper/utils/types.js +1 -0
- package/dist/cjs/swappers/ThorchainSwapper/generated/generatedThorLongtailTokens.json +3153 -3153
- package/dist/cjs/swappers/ThorchainSwapper/generated/generatedTradableAssetMap.json +6 -6
- package/dist/cjs/swappers/ZrxSwapper/utils/helpers/helpers.js +1 -3
- package/dist/cjs/thorchain-utils/getL1RateOrQuote.js +20 -17
- package/dist/cjs/types.d.ts +18 -1
- package/dist/cjs/types.js +1 -0
- package/dist/cjs/utils/tenderly/index.d.ts +3 -0
- package/dist/cjs/utils/tenderly/index.js +19 -0
- package/dist/cjs/utils/tenderly/simulate.d.ts +20 -0
- package/dist/cjs/utils/tenderly/simulate.js +109 -0
- package/dist/cjs/utils/tenderly/storageSlots.d.ts +8 -0
- package/dist/cjs/utils/tenderly/storageSlots.js +94 -0
- package/dist/cjs/utils/tenderly/types.d.ts +56 -0
- package/dist/cjs/utils/tenderly/types.js +2 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/constants.js +9 -0
- package/dist/esm/swappers/NearIntentsSwapper/NearIntentsSwapper.d.ts +2 -0
- package/dist/esm/swappers/NearIntentsSwapper/NearIntentsSwapper.js +8 -0
- package/dist/esm/swappers/NearIntentsSwapper/constants.d.ts +3 -0
- package/dist/esm/swappers/NearIntentsSwapper/constants.js +3 -0
- package/dist/esm/swappers/NearIntentsSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/NearIntentsSwapper/endpoints.js +162 -0
- package/dist/esm/swappers/NearIntentsSwapper/index.d.ts +4 -0
- package/dist/esm/swappers/NearIntentsSwapper/index.js +4 -0
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.d.ts +3 -0
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +205 -0
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.d.ts +3 -0
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +204 -0
- package/dist/esm/swappers/NearIntentsSwapper/types.d.ts +6 -0
- package/dist/esm/swappers/NearIntentsSwapper/types.js +28 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers/helpers.d.ts +12 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers/helpers.js +91 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/oneClickService.d.ts +3 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/oneClickService.js +12 -0
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +59 -16
- package/dist/esm/swappers/RelaySwapper/constant.js +1 -0
- package/dist/esm/swappers/RelaySwapper/utils/fetchRelayTrade.d.ts +1 -1
- package/dist/esm/swappers/RelaySwapper/utils/getRelayPsbtRelayer.js +2 -2
- package/dist/esm/swappers/RelaySwapper/utils/getTrade.js +47 -2
- package/dist/esm/swappers/RelaySwapper/utils/notifyTransactionIndexing.d.ts +1 -1
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +0 -2
- package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +1 -0
- package/dist/esm/swappers/RelaySwapper/utils/types.js +1 -0
- package/dist/esm/swappers/ThorchainSwapper/generated/generatedThorLongtailTokens.json +3153 -3153
- package/dist/esm/swappers/ThorchainSwapper/generated/generatedTradableAssetMap.json +6 -6
- package/dist/esm/swappers/ZrxSwapper/utils/helpers/helpers.js +1 -3
- package/dist/esm/thorchain-utils/getL1RateOrQuote.js +20 -17
- package/dist/esm/types.d.ts +18 -1
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils/tenderly/index.d.ts +3 -0
- package/dist/esm/utils/tenderly/index.js +3 -0
- package/dist/esm/utils/tenderly/simulate.d.ts +20 -0
- package/dist/esm/utils/tenderly/simulate.js +102 -0
- package/dist/esm/utils/tenderly/storageSlots.d.ts +8 -0
- package/dist/esm/utils/tenderly/storageSlots.js +86 -0
- package/dist/esm/utils/tenderly/types.d.ts +56 -0
- package/dist/esm/utils/tenderly/types.js +1 -0
- package/package.json +32 -6
package/dist/cjs/constants.js
CHANGED
|
@@ -16,13 +16,15 @@ const endpoints_6 = require("./swappers/JupiterSwapper/endpoints");
|
|
|
16
16
|
const JupiterSwapper_1 = require("./swappers/JupiterSwapper/JupiterSwapper");
|
|
17
17
|
const endpoints_7 = require("./swappers/MayachainSwapper/endpoints");
|
|
18
18
|
const MayachainSwapper_1 = require("./swappers/MayachainSwapper/MayachainSwapper");
|
|
19
|
-
const endpoints_8 = require("./swappers/
|
|
19
|
+
const endpoints_8 = require("./swappers/NearIntentsSwapper/endpoints");
|
|
20
|
+
const NearIntentsSwapper_1 = require("./swappers/NearIntentsSwapper/NearIntentsSwapper");
|
|
21
|
+
const endpoints_9 = require("./swappers/PortalsSwapper/endpoints");
|
|
20
22
|
const PortalsSwapper_1 = require("./swappers/PortalsSwapper/PortalsSwapper");
|
|
21
23
|
const RelaySwapper_1 = require("./swappers/RelaySwapper");
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
+
const endpoints_10 = require("./swappers/RelaySwapper/endpoints");
|
|
25
|
+
const endpoints_11 = require("./swappers/ThorchainSwapper/endpoints");
|
|
24
26
|
const ThorchainSwapper_1 = require("./swappers/ThorchainSwapper/ThorchainSwapper");
|
|
25
|
-
const
|
|
27
|
+
const endpoints_12 = require("./swappers/ZrxSwapper/endpoints");
|
|
26
28
|
const ZrxSwapper_1 = require("./swappers/ZrxSwapper/ZrxSwapper");
|
|
27
29
|
const types_1 = require("./types");
|
|
28
30
|
const utils_2 = require("./utils");
|
|
@@ -36,7 +38,7 @@ exports.QUOTE_TIMEOUT_ERROR = (0, utils_2.makeSwapErrorRight)({
|
|
|
36
38
|
exports.swappers = {
|
|
37
39
|
[types_1.SwapperName.Thorchain]: {
|
|
38
40
|
...ThorchainSwapper_1.thorchainSwapper,
|
|
39
|
-
...
|
|
41
|
+
...endpoints_11.thorchainApi,
|
|
40
42
|
},
|
|
41
43
|
[types_1.SwapperName.Mayachain]: {
|
|
42
44
|
...MayachainSwapper_1.mayachainSwapper,
|
|
@@ -44,7 +46,7 @@ exports.swappers = {
|
|
|
44
46
|
},
|
|
45
47
|
[types_1.SwapperName.Zrx]: {
|
|
46
48
|
...ZrxSwapper_1.zrxSwapper,
|
|
47
|
-
...
|
|
49
|
+
...endpoints_12.zrxApi,
|
|
48
50
|
},
|
|
49
51
|
[types_1.SwapperName.CowSwap]: {
|
|
50
52
|
...CowSwapper_1.cowSwapper,
|
|
@@ -56,7 +58,7 @@ exports.swappers = {
|
|
|
56
58
|
},
|
|
57
59
|
[types_1.SwapperName.Portals]: {
|
|
58
60
|
...PortalsSwapper_1.portalsSwapper,
|
|
59
|
-
...
|
|
61
|
+
...endpoints_9.portalsApi,
|
|
60
62
|
},
|
|
61
63
|
[types_1.SwapperName.Chainflip]: {
|
|
62
64
|
...ChainflipSwapper_1.chainflipSwapper,
|
|
@@ -68,7 +70,7 @@ exports.swappers = {
|
|
|
68
70
|
},
|
|
69
71
|
[types_1.SwapperName.Relay]: {
|
|
70
72
|
...RelaySwapper_1.relaySwapper,
|
|
71
|
-
...
|
|
73
|
+
...endpoints_10.relayApi,
|
|
72
74
|
},
|
|
73
75
|
[types_1.SwapperName.ButterSwap]: {
|
|
74
76
|
...ButterSwap_1.butterSwap,
|
|
@@ -78,11 +80,16 @@ exports.swappers = {
|
|
|
78
80
|
...BebopSwapper_1.bebopSwapper,
|
|
79
81
|
...endpoints_2.bebopApi,
|
|
80
82
|
},
|
|
83
|
+
[types_1.SwapperName.NearIntents]: {
|
|
84
|
+
...NearIntentsSwapper_1.nearIntentsSwapper,
|
|
85
|
+
...endpoints_8.nearIntentsApi,
|
|
86
|
+
},
|
|
81
87
|
[types_1.SwapperName.Test]: undefined,
|
|
82
88
|
};
|
|
83
89
|
// Slippage defaults. Don't export these to ensure the getDefaultSlippageDecimalPercentageForSwapper helper function is used.
|
|
84
90
|
const DEFAULT_SLIPPAGE_DECIMAL_PERCENTAGE = '0.002'; // .2%
|
|
85
91
|
const DEFAULT_COWSWAP_SLIPPAGE_DECIMAL_PERCENTAGE = '0.005'; // .5%
|
|
92
|
+
const DEFAULT_NEAR_INTENTS_SLIPPAGE_DECIMAL_PERCENTAGE = '0.005'; // .5%
|
|
86
93
|
const DEFAULT_PORTALS_SLIPPAGE_DECIMAL_PERCENTAGE = '0.025'; // 2.5%
|
|
87
94
|
const DEFAULT_THOR_SLIPPAGE_DECIMAL_PERCENTAGE = '0.01'; // 1%
|
|
88
95
|
const DEFAULT_MAYA_SLIPPAGE_DECIMAL_PERCENTAGE = '0.01'; // 1%
|
|
@@ -115,6 +122,8 @@ const getDefaultSlippageDecimalPercentageForSwapper = (swapperName) => {
|
|
|
115
122
|
throw new Error('Default slippage not supported by Relay');
|
|
116
123
|
case types_1.SwapperName.ButterSwap:
|
|
117
124
|
return DEFAULT_BUTTERSWAP_SLIPPAGE_DECIMAL_PERCENTAGE;
|
|
125
|
+
case types_1.SwapperName.NearIntents:
|
|
126
|
+
return DEFAULT_NEAR_INTENTS_SLIPPAGE_DECIMAL_PERCENTAGE;
|
|
118
127
|
default:
|
|
119
128
|
return (0, utils_1.assertUnreachable)(swapperName);
|
|
120
129
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nearIntentsSwapper = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
exports.nearIntentsSwapper = {
|
|
6
|
+
executeEvmTransaction: utils_1.executeEvmTransaction,
|
|
7
|
+
executeSolanaTransaction: utils_1.executeSolanaTransaction,
|
|
8
|
+
executeUtxoTransaction: (txToSign, { signAndBroadcastTransaction }) => {
|
|
9
|
+
return signAndBroadcastTransaction(txToSign);
|
|
10
|
+
},
|
|
11
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_QUOTE_DEADLINE_MS = exports.DEFAULT_SLIPPAGE_BPS = exports.ONE_CLICK_BASE_URL = void 0;
|
|
4
|
+
exports.ONE_CLICK_BASE_URL = 'https://1click.chaindefuser.com';
|
|
5
|
+
exports.DEFAULT_SLIPPAGE_BPS = 50;
|
|
6
|
+
exports.DEFAULT_QUOTE_DEADLINE_MS = 30 * 60 * 1000;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nearIntentsApi = void 0;
|
|
4
|
+
const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
5
|
+
const utils_1 = require("@shapeshiftoss/utils");
|
|
6
|
+
const utils_2 = require("../../utils");
|
|
7
|
+
const helpers_1 = require("../utils/helpers/helpers");
|
|
8
|
+
const getTradeQuote_1 = require("./swapperApi/getTradeQuote");
|
|
9
|
+
const getTradeRate_1 = require("./swapperApi/getTradeRate");
|
|
10
|
+
const helpers_2 = require("./utils/helpers/helpers");
|
|
11
|
+
const oneClickService_1 = require("./utils/oneClickService");
|
|
12
|
+
exports.nearIntentsApi = {
|
|
13
|
+
getTradeQuote: getTradeQuote_1.getTradeQuote,
|
|
14
|
+
getTradeRate: (input, deps) => {
|
|
15
|
+
return (0, getTradeRate_1.getTradeRate)(input, deps);
|
|
16
|
+
},
|
|
17
|
+
getUnsignedEvmTransaction: async ({ from, stepIndex, tradeQuote, supportsEIP1559, assertGetEvmChainAdapter, }) => {
|
|
18
|
+
if (!(0, utils_2.isExecutableTradeQuote)(tradeQuote))
|
|
19
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
20
|
+
const step = (0, utils_2.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
21
|
+
const { accountNumber, sellAsset, nearIntentsSpecific } = step;
|
|
22
|
+
if (!nearIntentsSpecific)
|
|
23
|
+
throw new Error('nearIntentsSpecific is required');
|
|
24
|
+
const adapter = assertGetEvmChainAdapter(sellAsset.chainId);
|
|
25
|
+
const to = nearIntentsSpecific.depositAddress;
|
|
26
|
+
const value = step.sellAmountIncludingProtocolFeesCryptoBaseUnit;
|
|
27
|
+
const contractAddress = (0, utils_1.contractAddressOrUndefined)(sellAsset.assetId);
|
|
28
|
+
const data = chain_adapters_1.evm.getErc20Data(to, value, contractAddress);
|
|
29
|
+
const feeData = await chain_adapters_1.evm.getFees({
|
|
30
|
+
adapter,
|
|
31
|
+
data: data || '0x',
|
|
32
|
+
to: contractAddress ?? to,
|
|
33
|
+
value: (0, helpers_1.isNativeEvmAsset)(sellAsset.assetId) ? value : '0',
|
|
34
|
+
from,
|
|
35
|
+
supportsEIP1559,
|
|
36
|
+
});
|
|
37
|
+
return adapter.buildSendApiTransaction({
|
|
38
|
+
accountNumber,
|
|
39
|
+
from,
|
|
40
|
+
to,
|
|
41
|
+
value,
|
|
42
|
+
chainSpecific: { contractAddress, ...feeData },
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
getEvmTransactionFees: async ({ from, stepIndex, tradeQuote, supportsEIP1559, assertGetEvmChainAdapter, }) => {
|
|
46
|
+
if (!(0, utils_2.isExecutableTradeQuote)(tradeQuote))
|
|
47
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
48
|
+
const step = (0, utils_2.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
49
|
+
const { sellAsset, nearIntentsSpecific } = step;
|
|
50
|
+
if (!nearIntentsSpecific)
|
|
51
|
+
throw new Error('nearIntentsSpecific is required');
|
|
52
|
+
const adapter = assertGetEvmChainAdapter(sellAsset.chainId);
|
|
53
|
+
const to = nearIntentsSpecific.depositAddress;
|
|
54
|
+
const value = step.sellAmountIncludingProtocolFeesCryptoBaseUnit;
|
|
55
|
+
const contractAddress = (0, utils_1.contractAddressOrUndefined)(sellAsset.assetId);
|
|
56
|
+
const data = chain_adapters_1.evm.getErc20Data(to, value, contractAddress);
|
|
57
|
+
const feeData = await chain_adapters_1.evm.getFees({
|
|
58
|
+
adapter,
|
|
59
|
+
data: data || '0x',
|
|
60
|
+
to: contractAddress ?? to,
|
|
61
|
+
value: (0, helpers_1.isNativeEvmAsset)(sellAsset.assetId) ? value : '0',
|
|
62
|
+
from,
|
|
63
|
+
supportsEIP1559,
|
|
64
|
+
});
|
|
65
|
+
return feeData.networkFeeCryptoBaseUnit;
|
|
66
|
+
},
|
|
67
|
+
getUnsignedUtxoTransaction: ({ stepIndex, tradeQuote, assertGetUtxoChainAdapter, xpub, accountType, }) => {
|
|
68
|
+
if (!(0, utils_2.isExecutableTradeQuote)(tradeQuote))
|
|
69
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
70
|
+
const step = (0, utils_2.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
71
|
+
const { sellAsset, accountNumber, nearIntentsSpecific, feeData } = step;
|
|
72
|
+
if (!nearIntentsSpecific)
|
|
73
|
+
throw new Error('nearIntentsSpecific is required');
|
|
74
|
+
if (!xpub)
|
|
75
|
+
throw new Error('xpub is required for UTXO transactions');
|
|
76
|
+
const adapter = assertGetUtxoChainAdapter(sellAsset.chainId);
|
|
77
|
+
const satoshiPerByte = feeData.chainSpecific?.satsPerByte ?? '0';
|
|
78
|
+
return adapter.buildSendApiTransaction({
|
|
79
|
+
accountNumber,
|
|
80
|
+
to: nearIntentsSpecific.depositAddress,
|
|
81
|
+
value: step.sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
82
|
+
sendMax: false,
|
|
83
|
+
chainSpecific: {
|
|
84
|
+
satoshiPerByte,
|
|
85
|
+
accountType,
|
|
86
|
+
},
|
|
87
|
+
xpub,
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
getUtxoTransactionFees: ({ tradeQuote, stepIndex }) => {
|
|
91
|
+
if (!(0, utils_2.isExecutableTradeQuote)(tradeQuote))
|
|
92
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
93
|
+
const step = (0, utils_2.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
94
|
+
if (!step.feeData.networkFeeCryptoBaseUnit) {
|
|
95
|
+
throw new Error('Missing network fee in quote');
|
|
96
|
+
}
|
|
97
|
+
return Promise.resolve(step.feeData.networkFeeCryptoBaseUnit);
|
|
98
|
+
},
|
|
99
|
+
getUnsignedSolanaTransaction: async ({ stepIndex, tradeQuote, from, assertGetSolanaChainAdapter, }) => {
|
|
100
|
+
if (!(0, utils_2.isExecutableTradeQuote)(tradeQuote))
|
|
101
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
102
|
+
const step = (0, utils_2.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
103
|
+
const { accountNumber, sellAsset, nearIntentsSpecific } = step;
|
|
104
|
+
if (!nearIntentsSpecific)
|
|
105
|
+
throw new Error('nearIntentsSpecific is required');
|
|
106
|
+
const adapter = assertGetSolanaChainAdapter(sellAsset.chainId);
|
|
107
|
+
const to = nearIntentsSpecific.depositAddress;
|
|
108
|
+
const value = step.sellAmountIncludingProtocolFeesCryptoBaseUnit;
|
|
109
|
+
const tokenId = (0, utils_1.contractAddressOrUndefined)(sellAsset.assetId);
|
|
110
|
+
const { fast } = await adapter.getFeeData({
|
|
111
|
+
to,
|
|
112
|
+
value,
|
|
113
|
+
chainSpecific: { from, tokenId },
|
|
114
|
+
});
|
|
115
|
+
return adapter.buildSendApiTransaction({
|
|
116
|
+
to,
|
|
117
|
+
from,
|
|
118
|
+
value,
|
|
119
|
+
accountNumber,
|
|
120
|
+
chainSpecific: tokenId
|
|
121
|
+
? {
|
|
122
|
+
// For SPL tokens: include compute budget parameters
|
|
123
|
+
tokenId,
|
|
124
|
+
computeUnitLimit: fast.chainSpecific.computeUnits,
|
|
125
|
+
computeUnitPrice: fast.chainSpecific.priorityFee,
|
|
126
|
+
}
|
|
127
|
+
: {
|
|
128
|
+
// For native SOL: no compute budget needed for simple transfers
|
|
129
|
+
tokenId,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
getSolanaTransactionFees: ({ tradeQuote, stepIndex }) => {
|
|
134
|
+
if (!(0, utils_2.isExecutableTradeQuote)(tradeQuote))
|
|
135
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
136
|
+
const step = (0, utils_2.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
137
|
+
if (!step.feeData.networkFeeCryptoBaseUnit) {
|
|
138
|
+
throw new Error('Missing network fee in quote');
|
|
139
|
+
}
|
|
140
|
+
return Promise.resolve(step.feeData.networkFeeCryptoBaseUnit);
|
|
141
|
+
},
|
|
142
|
+
checkTradeStatus: async ({ config, swap }) => {
|
|
143
|
+
const { nearIntentsSpecific } = swap?.metadata ?? {};
|
|
144
|
+
if (!nearIntentsSpecific?.depositAddress) {
|
|
145
|
+
return (0, utils_2.createDefaultStatusResponse)(swap?.buyTxHash);
|
|
146
|
+
}
|
|
147
|
+
(0, oneClickService_1.initializeOneClickService)(config.VITE_NEAR_INTENTS_API_KEY);
|
|
148
|
+
try {
|
|
149
|
+
// TODO(gomes): SDK doesn't support depositMemo yet in getExecutionStatus
|
|
150
|
+
const statusResponse = await oneClickService_1.OneClickService.getExecutionStatus(nearIntentsSpecific.depositAddress);
|
|
151
|
+
const txStatus = (0, helpers_2.mapNearIntentsStatus)(statusResponse.status);
|
|
152
|
+
const message = (0, helpers_2.getNearIntentsStatusMessage)(statusResponse.status);
|
|
153
|
+
// Extract buyTxHash from destination chain transactions
|
|
154
|
+
const buyTxHash = statusResponse.swapDetails?.destinationChainTxHashes?.[0]?.hash;
|
|
155
|
+
return {
|
|
156
|
+
status: txStatus,
|
|
157
|
+
buyTxHash,
|
|
158
|
+
message,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
return (0, utils_2.createDefaultStatusResponse)(undefined);
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./NearIntentsSwapper"), exports);
|
|
18
|
+
__exportStar(require("./endpoints"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
__exportStar(require("./constants"), exports);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { CommonTradeQuoteInput, SwapErrorRight, SwapperDeps, TradeQuote } from '../../../types';
|
|
3
|
+
export declare const getTradeQuote: (input: CommonTradeQuoteInput, deps: SwapperDeps) => Promise<Result<TradeQuote[], SwapErrorRight>>;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTradeQuote = void 0;
|
|
4
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
+
const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
6
|
+
const utils_1 = require("@shapeshiftoss/utils");
|
|
7
|
+
const monads_1 = require("@sniptt/monads");
|
|
8
|
+
const uuid_1 = require("uuid");
|
|
9
|
+
const constants_1 = require("../../../constants");
|
|
10
|
+
const types_1 = require("../../../types");
|
|
11
|
+
const utils_2 = require("../../../utils");
|
|
12
|
+
const helpers_1 = require("../../utils/helpers/helpers");
|
|
13
|
+
const constants_2 = require("../constants");
|
|
14
|
+
const types_2 = require("../types");
|
|
15
|
+
const helpers_2 = require("../utils/helpers/helpers");
|
|
16
|
+
const oneClickService_1 = require("../utils/oneClickService");
|
|
17
|
+
const getTradeQuote = async (input, deps) => {
|
|
18
|
+
const { sellAsset, buyAsset, accountNumber, sendAddress, receiveAddress, sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount, slippageTolerancePercentageDecimal, affiliateBps, } = input;
|
|
19
|
+
if (accountNumber === undefined) {
|
|
20
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
21
|
+
message: `accountNumber is required`,
|
|
22
|
+
code: types_1.TradeQuoteError.UnknownError,
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
if (sendAddress === undefined) {
|
|
26
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
27
|
+
message: `sendAddress is required`,
|
|
28
|
+
code: types_1.TradeQuoteError.UnknownError,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
if (receiveAddress === undefined) {
|
|
32
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
33
|
+
message: `receiveAddress is required`,
|
|
34
|
+
code: types_1.TradeQuoteError.UnknownError,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
const from = sendAddress;
|
|
38
|
+
try {
|
|
39
|
+
(0, oneClickService_1.initializeOneClickService)(deps.config.VITE_NEAR_INTENTS_API_KEY);
|
|
40
|
+
const originAsset = await (0, helpers_2.assetToNearIntentsAsset)(sellAsset);
|
|
41
|
+
const destinationAsset = await (0, helpers_2.assetToNearIntentsAsset)(buyAsset);
|
|
42
|
+
// This shouldn't be the case since we already got a rate and know these exist, but...
|
|
43
|
+
if (!(originAsset && destinationAsset)) {
|
|
44
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
45
|
+
code: types_1.TradeQuoteError.UnsupportedTradePair,
|
|
46
|
+
message: 'Unsupported asset',
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
const quoteRequest = {
|
|
50
|
+
dry: false,
|
|
51
|
+
swapType: types_2.QuoteRequest.swapType.EXACT_INPUT,
|
|
52
|
+
slippageTolerance: slippageTolerancePercentageDecimal
|
|
53
|
+
? (0, utils_1.bnOrZero)(slippageTolerancePercentageDecimal).times(10000).toNumber()
|
|
54
|
+
: constants_2.DEFAULT_SLIPPAGE_BPS,
|
|
55
|
+
originAsset,
|
|
56
|
+
destinationAsset,
|
|
57
|
+
amount: sellAmount,
|
|
58
|
+
depositType: types_2.QuoteRequest.depositType.ORIGIN_CHAIN,
|
|
59
|
+
refundTo: sendAddress,
|
|
60
|
+
refundType: types_2.QuoteRequest.refundType.ORIGIN_CHAIN,
|
|
61
|
+
recipient: receiveAddress,
|
|
62
|
+
recipientType: types_2.QuoteRequest.recipientType.DESTINATION_CHAIN,
|
|
63
|
+
deadline: new Date(Date.now() + constants_2.DEFAULT_QUOTE_DEADLINE_MS).toISOString(),
|
|
64
|
+
referral: 'shapeshift',
|
|
65
|
+
appFees: [
|
|
66
|
+
{
|
|
67
|
+
recipient: utils_1.DAO_TREASURY_NEAR,
|
|
68
|
+
fee: Number(affiliateBps),
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
const quoteResponse = await oneClickService_1.OneClickService.getQuote(quoteRequest);
|
|
73
|
+
const { quote } = quoteResponse;
|
|
74
|
+
if (!quote.depositAddress) {
|
|
75
|
+
throw new Error('Missing deposit address in quote response');
|
|
76
|
+
}
|
|
77
|
+
const { chainNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
78
|
+
const depositAddress = quote.depositAddress;
|
|
79
|
+
const getFeeData = async () => {
|
|
80
|
+
switch (chainNamespace) {
|
|
81
|
+
case caip_1.CHAIN_NAMESPACE.Evm: {
|
|
82
|
+
const sellAdapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
|
|
83
|
+
const contractAddress = (0, utils_1.contractAddressOrUndefined)(sellAsset.assetId);
|
|
84
|
+
const data = chain_adapters_1.evm.getErc20Data(depositAddress, sellAmount, contractAddress);
|
|
85
|
+
const feeData = await sellAdapter.getFeeData({
|
|
86
|
+
to: contractAddress ?? depositAddress,
|
|
87
|
+
value: (0, helpers_1.isNativeEvmAsset)(sellAsset.assetId) ? sellAmount : '0',
|
|
88
|
+
chainSpecific: {
|
|
89
|
+
from,
|
|
90
|
+
contractAddress,
|
|
91
|
+
data: data || '0x',
|
|
92
|
+
},
|
|
93
|
+
sendMax: false,
|
|
94
|
+
});
|
|
95
|
+
return { networkFeeCryptoBaseUnit: feeData.fast.txFee };
|
|
96
|
+
}
|
|
97
|
+
case caip_1.CHAIN_NAMESPACE.Utxo: {
|
|
98
|
+
const sellAdapter = deps.assertGetUtxoChainAdapter(sellAsset.chainId);
|
|
99
|
+
const pubkey = input.xpub;
|
|
100
|
+
if (!pubkey) {
|
|
101
|
+
return {
|
|
102
|
+
networkFeeCryptoBaseUnit: undefined,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const feeData = await sellAdapter.getFeeData({
|
|
106
|
+
to: depositAddress,
|
|
107
|
+
value: sellAmount,
|
|
108
|
+
chainSpecific: { pubkey },
|
|
109
|
+
sendMax: false,
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
networkFeeCryptoBaseUnit: feeData.fast.txFee,
|
|
113
|
+
chainSpecific: {
|
|
114
|
+
satsPerByte: feeData.fast.chainSpecific.satoshiPerByte,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
case caip_1.CHAIN_NAMESPACE.Solana: {
|
|
119
|
+
const sellAdapter = deps.assertGetSolanaChainAdapter(sellAsset.chainId);
|
|
120
|
+
const tokenId = (0, utils_1.isToken)(sellAsset.assetId)
|
|
121
|
+
? (0, caip_1.fromAssetId)(sellAsset.assetId).assetReference
|
|
122
|
+
: undefined;
|
|
123
|
+
const instructions = await sellAdapter.buildEstimationInstructions({
|
|
124
|
+
from,
|
|
125
|
+
to: depositAddress,
|
|
126
|
+
tokenId,
|
|
127
|
+
value: sellAmount,
|
|
128
|
+
});
|
|
129
|
+
const feeData = await sellAdapter.getFeeData({
|
|
130
|
+
to: depositAddress,
|
|
131
|
+
value: sellAmount,
|
|
132
|
+
chainSpecific: {
|
|
133
|
+
from,
|
|
134
|
+
tokenId,
|
|
135
|
+
instructions,
|
|
136
|
+
},
|
|
137
|
+
sendMax: false,
|
|
138
|
+
});
|
|
139
|
+
const txFee = feeData.fast.txFee;
|
|
140
|
+
const ataCreationCost = (0, helpers_2.calculateAccountCreationCosts)(instructions);
|
|
141
|
+
const totalFee = (0, utils_1.bn)(txFee).plus(ataCreationCost).toString();
|
|
142
|
+
return { networkFeeCryptoBaseUnit: totalFee };
|
|
143
|
+
}
|
|
144
|
+
default:
|
|
145
|
+
throw new Error(`Unsupported chain namespace: ${chainNamespace}`);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const { networkFeeCryptoBaseUnit, chainSpecific } = await getFeeData();
|
|
149
|
+
const rate = (0, utils_2.getInputOutputRate)({
|
|
150
|
+
sellAmountCryptoBaseUnit: quote.amountIn,
|
|
151
|
+
buyAmountCryptoBaseUnit: quote.amountOut,
|
|
152
|
+
sellAsset,
|
|
153
|
+
buyAsset,
|
|
154
|
+
});
|
|
155
|
+
const tradeQuote = {
|
|
156
|
+
id: (0, uuid_1.v4)(),
|
|
157
|
+
receiveAddress,
|
|
158
|
+
affiliateBps,
|
|
159
|
+
rate,
|
|
160
|
+
slippageTolerancePercentageDecimal: slippageTolerancePercentageDecimal ??
|
|
161
|
+
(0, constants_1.getDefaultSlippageDecimalPercentageForSwapper)(types_1.SwapperName.NearIntents),
|
|
162
|
+
quoteOrRate: 'quote',
|
|
163
|
+
swapperName: types_1.SwapperName.NearIntents,
|
|
164
|
+
steps: [
|
|
165
|
+
{
|
|
166
|
+
accountNumber,
|
|
167
|
+
allowanceContract: quote.depositAddress,
|
|
168
|
+
buyAmountBeforeFeesCryptoBaseUnit: quote.amountOut,
|
|
169
|
+
buyAmountAfterFeesCryptoBaseUnit: quote.amountOut,
|
|
170
|
+
buyAsset,
|
|
171
|
+
feeData: {
|
|
172
|
+
protocolFees: {},
|
|
173
|
+
networkFeeCryptoBaseUnit,
|
|
174
|
+
...(chainSpecific && { chainSpecific }),
|
|
175
|
+
},
|
|
176
|
+
rate,
|
|
177
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit: quote.amountIn,
|
|
178
|
+
sellAsset,
|
|
179
|
+
source: types_1.SwapperName.NearIntents,
|
|
180
|
+
estimatedExecutionTimeMs: quote.timeEstimate ? quote.timeEstimate * 1000 : undefined,
|
|
181
|
+
nearIntentsSpecific: {
|
|
182
|
+
depositAddress: quote.depositAddress ?? '',
|
|
183
|
+
depositMemo: quote.depositMemo,
|
|
184
|
+
timeEstimate: quote.timeEstimate,
|
|
185
|
+
deadline: quote.deadline ?? '',
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
};
|
|
190
|
+
return (0, monads_1.Ok)([tradeQuote]);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
console.error('[NEAR Intents] getTradeQuote error:', error);
|
|
194
|
+
if (error instanceof oneClickService_1.ApiError &&
|
|
195
|
+
(error.body?.message === 'tokenIn is not valid' ||
|
|
196
|
+
error.body?.message === 'tokenOut is not valid')) {
|
|
197
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
198
|
+
code: types_1.TradeQuoteError.UnsupportedTradePair,
|
|
199
|
+
message: 'Unsupported asset',
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
203
|
+
message: error instanceof Error ? error.message : 'Unknown error getting NEAR Intents quote',
|
|
204
|
+
code: types_1.TradeQuoteError.QueryFailed,
|
|
205
|
+
cause: error,
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
exports.getTradeQuote = getTradeQuote;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { GetTradeRateInput, SwapErrorRight, SwapperDeps, TradeRate } from '../../../types';
|
|
3
|
+
export declare const getTradeRate: (input: GetTradeRateInput, deps: SwapperDeps) => Promise<Result<TradeRate[], SwapErrorRight>>;
|