@shapeshiftoss/swapper 17.6.8 → 17.6.10
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 +61 -43
- package/dist/cjs/swappers/AcrossSwapper/AcrossSwapper.d.ts +2 -0
- package/dist/cjs/swappers/AcrossSwapper/AcrossSwapper.js +8 -0
- package/dist/cjs/swappers/AcrossSwapper/constant.d.ts +9 -0
- package/dist/cjs/swappers/AcrossSwapper/constant.js +48 -0
- package/dist/cjs/swappers/AcrossSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/AcrossSwapper/endpoints.js +113 -0
- package/dist/cjs/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.d.ts +3 -0
- package/dist/cjs/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.js +31 -0
- package/dist/cjs/swappers/AcrossSwapper/getTradeRate/getTradeRate.d.ts +3 -0
- package/dist/cjs/swappers/AcrossSwapper/getTradeRate/getTradeRate.js +19 -0
- package/dist/cjs/swappers/AcrossSwapper/index.d.ts +1 -0
- package/dist/cjs/swappers/AcrossSwapper/index.js +5 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/acrossService.d.ts +5 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/acrossService.js +17 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/fetchAcrossTrade.d.ts +19 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/fetchAcrossTrade.js +27 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/getTrade.d.ts +11 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/getTrade.js +335 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/types.d.ts +177 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/types.js +17 -0
- package/dist/cjs/swappers/AvnuSwapper/endpoints.js +42 -14
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +10 -5
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeRate.js +8 -4
- package/dist/cjs/swappers/BebopSwapper/utils/helpers/helpers.d.ts +1 -1
- package/dist/cjs/swappers/ButterSwap/ButterSwap.js +1 -0
- package/dist/cjs/swappers/ButterSwap/endpoints.js +56 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/checkTradeStatus.js +19 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.js +27 -14
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.test.js +1 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeRate.js +23 -16
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeRate.test.js +2 -0
- package/dist/cjs/swappers/ButterSwap/types.d.ts +1 -0
- package/dist/cjs/swappers/ButterSwap/utils/helpers.js +1 -0
- package/dist/cjs/swappers/ButterSwap/xhr.d.ts +2 -2
- package/dist/cjs/swappers/ButterSwap/xhr.js +7 -2
- package/dist/cjs/swappers/CetusSwapper/endpoints.js +3 -8
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeQuote.js +1 -1
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeRate.js +1 -1
- package/dist/cjs/swappers/ChainflipSwapper/utils/getQuoteOrRate.js +11 -5
- package/dist/cjs/swappers/ChainflipSwapper/utils/helpers.js +8 -2
- package/dist/cjs/swappers/CowSwapper/CowSwapper.js +1 -1
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +1 -1
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.test.js +5 -5
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeRate/getCowSwapTradeRate.js +1 -1
- package/dist/cjs/swappers/CowSwapper/utils/helpers/helpers.js +8 -2
- package/dist/cjs/swappers/NearIntentsSwapper/NearIntentsSwapper.js +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/endpoints.js +31 -0
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +36 -1
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +61 -1
- package/dist/cjs/swappers/NearIntentsSwapper/types.d.ts +1 -1
- package/dist/cjs/swappers/NearIntentsSwapper/types.js +6 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers/helpers.js +23 -4
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +8 -3
- package/dist/cjs/swappers/RelaySwapper/constant.js +26 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayDefaultUserAddress.d.ts +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getTrade.js +13 -2
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +100 -0
- package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +15 -0
- package/dist/cjs/swappers/StonfiSwapper/StonfiSwapper.d.ts +2 -0
- package/dist/cjs/swappers/StonfiSwapper/StonfiSwapper.js +8 -0
- package/dist/cjs/swappers/StonfiSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/StonfiSwapper/endpoints.js +227 -0
- package/dist/cjs/swappers/StonfiSwapper/index.d.ts +4 -0
- package/dist/cjs/swappers/StonfiSwapper/index.js +25 -0
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeQuote.d.ts +2 -0
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +119 -0
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeRate.d.ts +2 -0
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeRate.js +105 -0
- package/dist/cjs/swappers/StonfiSwapper/types.d.ts +60 -0
- package/dist/cjs/swappers/StonfiSwapper/types.js +5 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/constants.d.ts +5 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/constants.js +8 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/helpers.d.ts +11 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/helpers.js +135 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/omnistonManager.d.ts +5 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/omnistonManager.js +20 -0
- package/dist/cjs/swappers/SunioSwapper/endpoints.js +1 -1
- package/dist/cjs/swappers/SunioSwapper/utils/getQuoteOrRate.js +4 -3
- package/dist/cjs/swappers/ZrxSwapper/utils/helpers/helpers.d.ts +1 -1
- package/dist/cjs/swappers/utils/filterBuyAssetsBySellAssetId/filterBuyAssetsBySellAssetId.js +2 -5
- package/dist/cjs/swappers/utils/helpers/helpers.js +3 -0
- package/dist/cjs/thorchain-utils/getCallDataFromQuote.d.ts +1 -1
- package/dist/cjs/thorchain-utils/getL1RateOrQuote.js +30 -5
- package/dist/cjs/thorchain-utils/getQuote.js +8 -2
- package/dist/cjs/tron-utils/getUnsignedTronTransaction.js +22 -2
- package/dist/cjs/types.d.ts +79 -8
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils.d.ts +4 -3
- package/dist/cjs/utils.js +35 -7
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/constants.js +31 -13
- package/dist/esm/swappers/AcrossSwapper/AcrossSwapper.d.ts +2 -0
- package/dist/esm/swappers/AcrossSwapper/AcrossSwapper.js +5 -0
- package/dist/esm/swappers/AcrossSwapper/constant.d.ts +9 -0
- package/dist/esm/swappers/AcrossSwapper/constant.js +42 -0
- package/dist/esm/swappers/AcrossSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/AcrossSwapper/endpoints.js +107 -0
- package/dist/esm/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.d.ts +3 -0
- package/dist/esm/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.js +27 -0
- package/dist/esm/swappers/AcrossSwapper/getTradeRate/getTradeRate.d.ts +3 -0
- package/dist/esm/swappers/AcrossSwapper/getTradeRate/getTradeRate.js +15 -0
- package/dist/esm/swappers/AcrossSwapper/index.d.ts +1 -0
- package/dist/esm/swappers/AcrossSwapper/index.js +1 -0
- package/dist/esm/swappers/AcrossSwapper/utils/acrossService.d.ts +5 -0
- package/dist/esm/swappers/AcrossSwapper/utils/acrossService.js +11 -0
- package/dist/esm/swappers/AcrossSwapper/utils/fetchAcrossTrade.d.ts +19 -0
- package/dist/esm/swappers/AcrossSwapper/utils/fetchAcrossTrade.js +23 -0
- package/dist/esm/swappers/AcrossSwapper/utils/getTrade.d.ts +11 -0
- package/dist/esm/swappers/AcrossSwapper/utils/getTrade.js +328 -0
- package/dist/esm/swappers/AcrossSwapper/utils/types.d.ts +177 -0
- package/dist/esm/swappers/AcrossSwapper/utils/types.js +13 -0
- package/dist/esm/swappers/AvnuSwapper/endpoints.js +43 -15
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +10 -5
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeRate.js +8 -4
- package/dist/esm/swappers/BebopSwapper/utils/helpers/helpers.d.ts +1 -1
- package/dist/esm/swappers/ButterSwap/ButterSwap.js +2 -1
- package/dist/esm/swappers/ButterSwap/endpoints.js +56 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/checkTradeStatus.js +20 -1
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.js +29 -16
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.test.js +1 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeRate.js +25 -18
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeRate.test.js +2 -0
- package/dist/esm/swappers/ButterSwap/types.d.ts +1 -0
- package/dist/esm/swappers/ButterSwap/utils/helpers.js +1 -0
- package/dist/esm/swappers/ButterSwap/xhr.d.ts +2 -2
- package/dist/esm/swappers/ButterSwap/xhr.js +8 -3
- package/dist/esm/swappers/CetusSwapper/endpoints.js +3 -8
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeQuote.js +1 -1
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeRate.js +1 -1
- package/dist/esm/swappers/ChainflipSwapper/utils/getQuoteOrRate.js +12 -6
- package/dist/esm/swappers/ChainflipSwapper/utils/helpers.js +9 -3
- package/dist/esm/swappers/CowSwapper/CowSwapper.js +1 -1
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +1 -1
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.test.js +5 -5
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeRate/getCowSwapTradeRate.js +1 -1
- package/dist/esm/swappers/CowSwapper/utils/helpers/helpers.js +9 -3
- package/dist/esm/swappers/NearIntentsSwapper/NearIntentsSwapper.js +2 -1
- package/dist/esm/swappers/NearIntentsSwapper/endpoints.js +31 -0
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +36 -1
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +61 -1
- package/dist/esm/swappers/NearIntentsSwapper/types.d.ts +1 -1
- package/dist/esm/swappers/NearIntentsSwapper/types.js +6 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers/helpers.js +23 -4
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +8 -3
- package/dist/esm/swappers/RelaySwapper/constant.js +28 -3
- package/dist/esm/swappers/RelaySwapper/utils/getRelayDefaultUserAddress.d.ts +1 -1
- package/dist/esm/swappers/RelaySwapper/utils/getTrade.js +13 -2
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +100 -0
- package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +15 -0
- package/dist/esm/swappers/StonfiSwapper/StonfiSwapper.d.ts +2 -0
- package/dist/esm/swappers/StonfiSwapper/StonfiSwapper.js +5 -0
- package/dist/esm/swappers/StonfiSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/StonfiSwapper/endpoints.js +224 -0
- package/dist/esm/swappers/StonfiSwapper/index.d.ts +4 -0
- package/dist/esm/swappers/StonfiSwapper/index.js +4 -0
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeQuote.d.ts +2 -0
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +115 -0
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeRate.d.ts +2 -0
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeRate.js +101 -0
- package/dist/esm/swappers/StonfiSwapper/types.d.ts +60 -0
- package/dist/esm/swappers/StonfiSwapper/types.js +2 -0
- package/dist/esm/swappers/StonfiSwapper/utils/constants.d.ts +5 -0
- package/dist/esm/swappers/StonfiSwapper/utils/constants.js +5 -0
- package/dist/esm/swappers/StonfiSwapper/utils/helpers.d.ts +11 -0
- package/dist/esm/swappers/StonfiSwapper/utils/helpers.js +124 -0
- package/dist/esm/swappers/StonfiSwapper/utils/omnistonManager.d.ts +5 -0
- package/dist/esm/swappers/StonfiSwapper/utils/omnistonManager.js +17 -0
- package/dist/esm/swappers/SunioSwapper/endpoints.js +1 -1
- package/dist/esm/swappers/SunioSwapper/utils/getQuoteOrRate.js +5 -4
- package/dist/esm/swappers/ZrxSwapper/utils/helpers/helpers.d.ts +1 -1
- package/dist/esm/swappers/utils/filterBuyAssetsBySellAssetId/filterBuyAssetsBySellAssetId.js +2 -5
- package/dist/esm/swappers/utils/helpers/helpers.js +4 -1
- package/dist/esm/thorchain-utils/getCallDataFromQuote.d.ts +1 -1
- package/dist/esm/thorchain-utils/getL1RateOrQuote.js +31 -6
- package/dist/esm/thorchain-utils/getQuote.js +9 -3
- package/dist/esm/tron-utils/getUnsignedTronTransaction.js +22 -2
- package/dist/esm/types.d.ts +79 -8
- package/dist/esm/types.js +2 -0
- package/dist/esm/utils.d.ts +4 -3
- package/dist/esm/utils.js +34 -7
- package/package.json +17 -15
|
@@ -383,7 +383,7 @@ describe('getCowSwapTradeQuote', () => {
|
|
|
383
383
|
const maybeTradeQuote = await getCowSwapTradeQuote(input, MOCK_COWSWAP_CONFIG);
|
|
384
384
|
expect(maybeTradeQuote.isOk()).toBe(true);
|
|
385
385
|
expect(maybeTradeQuote.unwrap()).toEqual(expectedTradeQuoteWethToFox);
|
|
386
|
-
expect(cowService.post).toHaveBeenCalledWith('https://api.cow.fi/mainnet/api/v1/quote
|
|
386
|
+
expect(cowService.post).toHaveBeenCalledWith('https://api.cow.fi/mainnet/api/v1/quote', expectedApiInputWethToFox);
|
|
387
387
|
});
|
|
388
388
|
it('should call cowService with correct parameters, handle the fees and return the correct trade quote when buying ETH', async () => {
|
|
389
389
|
const input = {
|
|
@@ -416,7 +416,7 @@ describe('getCowSwapTradeQuote', () => {
|
|
|
416
416
|
const maybeTradeQuote = await getCowSwapTradeQuote(input, MOCK_COWSWAP_CONFIG);
|
|
417
417
|
expect(maybeTradeQuote.isOk()).toBe(true);
|
|
418
418
|
expect(maybeTradeQuote.unwrap()).toEqual(expectedTradeQuoteFoxToEth);
|
|
419
|
-
expect(cowService.post).toHaveBeenCalledWith('https://api.cow.fi/mainnet/api/v1/quote
|
|
419
|
+
expect(cowService.post).toHaveBeenCalledWith('https://api.cow.fi/mainnet/api/v1/quote', expectedApiInputFoxToEth);
|
|
420
420
|
});
|
|
421
421
|
it('should call cowService with correct parameters, handle the fees and return the correct trade quote when buying XDAI', async () => {
|
|
422
422
|
const input = {
|
|
@@ -449,7 +449,7 @@ describe('getCowSwapTradeQuote', () => {
|
|
|
449
449
|
const maybeTradeQuote = await getCowSwapTradeQuote(input, MOCK_COWSWAP_CONFIG);
|
|
450
450
|
expect(maybeTradeQuote.isOk()).toBe(true);
|
|
451
451
|
expect(maybeTradeQuote.unwrap()).toEqual(expectedTradeQuoteUsdcToXdai);
|
|
452
|
-
expect(cowService.post).toHaveBeenCalledWith('https://api.cow.fi/xdai/api/v1/quote
|
|
452
|
+
expect(cowService.post).toHaveBeenCalledWith('https://api.cow.fi/xdai/api/v1/quote', expectedApiInputUsdcGnosisToXdai);
|
|
453
453
|
});
|
|
454
454
|
it('should call cowService with correct parameters, handle the fees and return the correct trade quote when buying ETH on Arbitrum', async () => {
|
|
455
455
|
const input = {
|
|
@@ -482,7 +482,7 @@ describe('getCowSwapTradeQuote', () => {
|
|
|
482
482
|
const maybeTradeQuote = await getCowSwapTradeQuote(input, MOCK_COWSWAP_CONFIG);
|
|
483
483
|
expect(maybeTradeQuote.isOk()).toBe(true);
|
|
484
484
|
expect(maybeTradeQuote.unwrap()).toEqual(expectedTradeQuoteUsdcToEthArbitrum);
|
|
485
|
-
expect(cowService.post).toHaveBeenCalledWith('https://api.cow.fi/arbitrum_one/api/v1/quote
|
|
485
|
+
expect(cowService.post).toHaveBeenCalledWith('https://api.cow.fi/arbitrum_one/api/v1/quote', expectedApiInputUsdcToEthArbitrum);
|
|
486
486
|
});
|
|
487
487
|
it('should call cowService with correct parameters and return quote with original sellAmount when selling a very small amount of WETH', async () => {
|
|
488
488
|
const input = {
|
|
@@ -515,6 +515,6 @@ describe('getCowSwapTradeQuote', () => {
|
|
|
515
515
|
const maybeTradeQuote = await getCowSwapTradeQuote(input, MOCK_COWSWAP_CONFIG);
|
|
516
516
|
expect(maybeTradeQuote.isErr()).toBe(false);
|
|
517
517
|
expect(maybeTradeQuote.unwrap()).toEqual(expectedTradeQuoteSmallAmountWethToFox);
|
|
518
|
-
expect(cowService.post).toHaveBeenCalledWith('https://api.cow.fi/mainnet/api/v1/quote
|
|
518
|
+
expect(cowService.post).toHaveBeenCalledWith('https://api.cow.fi/mainnet/api/v1/quote', expectedApiInputSmallAmountWethToFox);
|
|
519
519
|
});
|
|
520
520
|
});
|
|
@@ -39,7 +39,7 @@ export async function getCowSwapTradeRate(input, config) {
|
|
|
39
39
|
});
|
|
40
40
|
const { appData, appDataHash } = await getFullAppData(slippageTolerancePercentageDecimal, affiliateAppDataFragment, 'market');
|
|
41
41
|
// https://api.cow.fi/docs/#/default/post_api_v1_quote
|
|
42
|
-
const maybeQuoteResponse = await cowService.post(`${config.VITE_COWSWAP_BASE_URL}/${network}/api/v1/quote
|
|
42
|
+
const maybeQuoteResponse = await cowService.post(`${config.VITE_COWSWAP_BASE_URL}/${network}/api/v1/quote`, {
|
|
43
43
|
sellToken: fromAssetId(sellAsset.assetId).assetReference,
|
|
44
44
|
buyToken,
|
|
45
45
|
receiver: receiveAddress,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fromAssetId } from '@shapeshiftoss/caip';
|
|
2
|
-
import { bn, bnOrZero, convertBasisPointsToDecimalPercentage, convertPrecision,
|
|
2
|
+
import { BigAmount, bn, bnOrZero, convertBasisPointsToDecimalPercentage, convertPrecision, } from '@shapeshiftoss/utils';
|
|
3
3
|
import { Err, Ok } from '@sniptt/monads';
|
|
4
4
|
import { TradeQuoteError } from '../../../../types.js';
|
|
5
5
|
import { makeSwapErrorRight } from '../../../../utils.js';
|
|
@@ -56,8 +56,14 @@ export const getValuesFromQuoteResponse = ({ buyAsset, sellAsset, response, affi
|
|
|
56
56
|
amount: buyAmountAfterAffiliateFeesCryptoBaseUnit,
|
|
57
57
|
slippageTolerancePercentageDecimal,
|
|
58
58
|
});
|
|
59
|
-
const buyAmountAfterAffiliateFeesCryptoPrecision = fromBaseUnit(
|
|
60
|
-
|
|
59
|
+
const buyAmountAfterAffiliateFeesCryptoPrecision = BigAmount.fromBaseUnit({
|
|
60
|
+
value: buyAmountAfterAffiliateFeesCryptoBaseUnit,
|
|
61
|
+
precision: buyAsset.precision,
|
|
62
|
+
}).toPrecision();
|
|
63
|
+
const sellAmountCryptoPrecision = BigAmount.fromBaseUnit({
|
|
64
|
+
value: sellAmountAfterFeesCryptoBaseUnit,
|
|
65
|
+
precision: sellAsset.precision,
|
|
66
|
+
}).toPrecision();
|
|
61
67
|
const rate = bnOrZero(buyAmountAfterAffiliateFeesCryptoPrecision)
|
|
62
68
|
.div(sellAmountCryptoPrecision)
|
|
63
69
|
.toString();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { executeEvmTransaction, executeNearTransaction, executeSolanaTransaction, executeStarknetTransaction, executeSuiTransaction, executeTronTransaction, } from '../../utils.js';
|
|
1
|
+
import { executeEvmTransaction, executeNearTransaction, executeSolanaTransaction, executeStarknetTransaction, executeSuiTransaction, executeTonTransaction, executeTronTransaction, } from '../../utils.js';
|
|
2
2
|
export const nearIntentsSwapper = {
|
|
3
3
|
executeEvmTransaction,
|
|
4
4
|
executeSolanaTransaction,
|
|
@@ -6,6 +6,7 @@ export const nearIntentsSwapper = {
|
|
|
6
6
|
executeTronTransaction,
|
|
7
7
|
executeSuiTransaction,
|
|
8
8
|
executeNearTransaction,
|
|
9
|
+
executeTonTransaction,
|
|
9
10
|
executeUtxoTransaction: (txToSign, { signAndBroadcastTransaction }) => {
|
|
10
11
|
return signAndBroadcastTransaction(txToSign);
|
|
11
12
|
},
|
|
@@ -245,6 +245,37 @@ export const nearIntentsApi = {
|
|
|
245
245
|
}
|
|
246
246
|
return Promise.resolve(step.feeData.networkFeeCryptoBaseUnit);
|
|
247
247
|
},
|
|
248
|
+
getUnsignedTonTransaction: ({ stepIndex, tradeQuote, from, assertGetTonChainAdapter, }) => {
|
|
249
|
+
if (!isExecutableTradeQuote(tradeQuote))
|
|
250
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
251
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
252
|
+
const { accountNumber, sellAsset, nearIntentsSpecific } = step;
|
|
253
|
+
if (!nearIntentsSpecific)
|
|
254
|
+
throw new Error('nearIntentsSpecific is required');
|
|
255
|
+
const adapter = assertGetTonChainAdapter(sellAsset.chainId);
|
|
256
|
+
const to = nearIntentsSpecific.depositAddress;
|
|
257
|
+
const value = step.sellAmountIncludingProtocolFeesCryptoBaseUnit;
|
|
258
|
+
const contractAddress = contractAddressOrUndefined(sellAsset.assetId);
|
|
259
|
+
return adapter.buildSendApiTransaction({
|
|
260
|
+
to,
|
|
261
|
+
from,
|
|
262
|
+
value,
|
|
263
|
+
accountNumber,
|
|
264
|
+
chainSpecific: {
|
|
265
|
+
contractAddress,
|
|
266
|
+
memo: nearIntentsSpecific.depositMemo,
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
getTonTransactionFees: ({ tradeQuote, stepIndex }) => {
|
|
271
|
+
if (!isExecutableTradeQuote(tradeQuote))
|
|
272
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
273
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
274
|
+
if (!step.feeData.networkFeeCryptoBaseUnit) {
|
|
275
|
+
throw new Error('Missing network fee in quote');
|
|
276
|
+
}
|
|
277
|
+
return Promise.resolve(step.feeData.networkFeeCryptoBaseUnit);
|
|
278
|
+
},
|
|
248
279
|
checkTradeStatus: async ({ config, swap }) => {
|
|
249
280
|
const { nearIntentsSpecific } = swap?.metadata ?? {};
|
|
250
281
|
if (!nearIntentsSpecific?.depositAddress) {
|
|
@@ -71,7 +71,27 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
71
71
|
},
|
|
72
72
|
],
|
|
73
73
|
};
|
|
74
|
-
const
|
|
74
|
+
const maxRetries = 3;
|
|
75
|
+
let quoteResponse = null;
|
|
76
|
+
let lastError = null;
|
|
77
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
78
|
+
try {
|
|
79
|
+
quoteResponse = await OneClickService.getQuote(quoteRequest);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
84
|
+
const isWebSocketError = lastError.message.includes('WebSocket is not ready');
|
|
85
|
+
if (isWebSocketError && attempt < maxRetries) {
|
|
86
|
+
await new Promise(resolve => setTimeout(resolve, 1000 * attempt));
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
throw lastError;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!quoteResponse) {
|
|
93
|
+
throw lastError ?? new Error('Failed to get quote after retries');
|
|
94
|
+
}
|
|
75
95
|
const { quote } = quoteResponse;
|
|
76
96
|
if (!quote.depositAddress) {
|
|
77
97
|
throw new Error('Missing deposit address in quote response');
|
|
@@ -197,6 +217,21 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
197
217
|
});
|
|
198
218
|
return { networkFeeCryptoBaseUnit: feeData.fast.txFee };
|
|
199
219
|
}
|
|
220
|
+
case CHAIN_NAMESPACE.Ton: {
|
|
221
|
+
const sellAdapter = deps.assertGetTonChainAdapter(sellAsset.chainId);
|
|
222
|
+
const contractAddress = isToken(sellAsset.assetId)
|
|
223
|
+
? fromAssetId(sellAsset.assetId).assetReference
|
|
224
|
+
: undefined;
|
|
225
|
+
const feeData = await sellAdapter.getFeeData({
|
|
226
|
+
to: depositAddress,
|
|
227
|
+
value: sellAmount,
|
|
228
|
+
chainSpecific: {
|
|
229
|
+
from,
|
|
230
|
+
contractAddress,
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
return { networkFeeCryptoBaseUnit: feeData.fast.txFee };
|
|
234
|
+
}
|
|
200
235
|
default:
|
|
201
236
|
throw new Error(`Unsupported chain namespace: ${chainNamespace}`);
|
|
202
237
|
}
|
|
@@ -61,7 +61,27 @@ export const getTradeRate = async (input, deps) => {
|
|
|
61
61
|
},
|
|
62
62
|
],
|
|
63
63
|
};
|
|
64
|
-
const
|
|
64
|
+
const maxRetries = 3;
|
|
65
|
+
let quoteResponse = null;
|
|
66
|
+
let lastError = null;
|
|
67
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
68
|
+
try {
|
|
69
|
+
quoteResponse = await OneClickService.getQuote(quoteRequest);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
74
|
+
const isWebSocketError = lastError.message.includes('WebSocket is not ready');
|
|
75
|
+
if (isWebSocketError && attempt < maxRetries) {
|
|
76
|
+
await new Promise(resolve => setTimeout(resolve, 1000 * attempt));
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
throw lastError;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (!quoteResponse) {
|
|
83
|
+
throw lastError ?? new Error('Failed to get quote after retries');
|
|
84
|
+
}
|
|
65
85
|
const { quote } = quoteResponse;
|
|
66
86
|
if (!quote.depositAddress) {
|
|
67
87
|
throw new Error('Missing deposit address in quote response');
|
|
@@ -238,6 +258,46 @@ export const getTradeRate = async (input, deps) => {
|
|
|
238
258
|
return '0';
|
|
239
259
|
}
|
|
240
260
|
}
|
|
261
|
+
case CHAIN_NAMESPACE.Near: {
|
|
262
|
+
try {
|
|
263
|
+
const sellAdapter = deps.assertGetNearChainAdapter(sellAsset.chainId);
|
|
264
|
+
if (!sendAddress) {
|
|
265
|
+
return '0';
|
|
266
|
+
}
|
|
267
|
+
const feeData = await sellAdapter.getFeeData({
|
|
268
|
+
to: depositAddress,
|
|
269
|
+
value: sellAmount,
|
|
270
|
+
chainSpecific: { from: sendAddress },
|
|
271
|
+
});
|
|
272
|
+
return feeData.fast.txFee;
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
return '0';
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
case CHAIN_NAMESPACE.Ton: {
|
|
279
|
+
try {
|
|
280
|
+
const sellAdapter = deps.assertGetTonChainAdapter(sellAsset.chainId);
|
|
281
|
+
const contractAddress = isToken(sellAsset.assetId)
|
|
282
|
+
? fromAssetId(sellAsset.assetId).assetReference
|
|
283
|
+
: undefined;
|
|
284
|
+
if (!sendAddress) {
|
|
285
|
+
return '0';
|
|
286
|
+
}
|
|
287
|
+
const feeData = await sellAdapter.getFeeData({
|
|
288
|
+
to: depositAddress,
|
|
289
|
+
value: sellAmount,
|
|
290
|
+
chainSpecific: {
|
|
291
|
+
from: sendAddress,
|
|
292
|
+
contractAddress,
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
return feeData.fast.txFee;
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
return '0';
|
|
299
|
+
}
|
|
300
|
+
}
|
|
241
301
|
default:
|
|
242
302
|
return undefined;
|
|
243
303
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
2
2
|
export { QuoteRequest } from '@defuse-protocol/one-click-sdk-typescript';
|
|
3
3
|
export type { GetExecutionStatusResponse, QuoteResponse, TokenResponse, } from '@defuse-protocol/one-click-sdk-typescript';
|
|
4
|
-
export declare const nearIntentsSupportedChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.GnosisMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BitcoinMainnet, KnownChainIds.DogecoinMainnet, KnownChainIds.ZcashMainnet, KnownChainIds.SolanaMainnet, KnownChainIds.TronMainnet, KnownChainIds.SuiMainnet, KnownChainIds.StarknetMainnet, KnownChainIds.MonadMainnet, KnownChainIds.NearMainnet];
|
|
4
|
+
export declare const nearIntentsSupportedChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.GnosisMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BitcoinMainnet, KnownChainIds.BitcoinCashMainnet, KnownChainIds.DogecoinMainnet, KnownChainIds.ZcashMainnet, KnownChainIds.SolanaMainnet, KnownChainIds.TronMainnet, KnownChainIds.SuiMainnet, KnownChainIds.StarknetMainnet, KnownChainIds.MonadMainnet, KnownChainIds.NearMainnet, KnownChainIds.PlasmaMainnet, KnownChainIds.TonMainnet];
|
|
5
5
|
export type NearIntentsSupportedChainId = (typeof nearIntentsSupportedChainIds)[number];
|
|
6
6
|
export declare const chainIdToNearIntentsChain: Record<NearIntentsSupportedChainId, string>;
|
|
@@ -10,6 +10,7 @@ export const nearIntentsSupportedChainIds = [
|
|
|
10
10
|
KnownChainIds.AvalancheMainnet,
|
|
11
11
|
KnownChainIds.OptimismMainnet,
|
|
12
12
|
KnownChainIds.BitcoinMainnet,
|
|
13
|
+
KnownChainIds.BitcoinCashMainnet,
|
|
13
14
|
KnownChainIds.DogecoinMainnet,
|
|
14
15
|
KnownChainIds.ZcashMainnet,
|
|
15
16
|
KnownChainIds.SolanaMainnet,
|
|
@@ -18,6 +19,8 @@ export const nearIntentsSupportedChainIds = [
|
|
|
18
19
|
KnownChainIds.StarknetMainnet,
|
|
19
20
|
KnownChainIds.MonadMainnet,
|
|
20
21
|
KnownChainIds.NearMainnet,
|
|
22
|
+
KnownChainIds.PlasmaMainnet,
|
|
23
|
+
KnownChainIds.TonMainnet,
|
|
21
24
|
];
|
|
22
25
|
export const chainIdToNearIntentsChain = {
|
|
23
26
|
[KnownChainIds.EthereumMainnet]: 'eth',
|
|
@@ -29,12 +32,15 @@ export const chainIdToNearIntentsChain = {
|
|
|
29
32
|
[KnownChainIds.AvalancheMainnet]: 'avax',
|
|
30
33
|
[KnownChainIds.OptimismMainnet]: 'op',
|
|
31
34
|
[KnownChainIds.BitcoinMainnet]: 'btc',
|
|
35
|
+
[KnownChainIds.BitcoinCashMainnet]: 'bch',
|
|
32
36
|
[KnownChainIds.DogecoinMainnet]: 'doge',
|
|
33
37
|
[KnownChainIds.ZcashMainnet]: 'zec',
|
|
38
|
+
[KnownChainIds.PlasmaMainnet]: 'plasma',
|
|
34
39
|
[KnownChainIds.SolanaMainnet]: 'sol',
|
|
35
40
|
[KnownChainIds.TronMainnet]: 'tron',
|
|
36
41
|
[KnownChainIds.SuiMainnet]: 'sui',
|
|
37
42
|
[KnownChainIds.StarknetMainnet]: 'starknet',
|
|
38
43
|
[KnownChainIds.MonadMainnet]: 'monad',
|
|
39
44
|
[KnownChainIds.NearMainnet]: 'near',
|
|
45
|
+
[KnownChainIds.TonMainnet]: 'ton',
|
|
40
46
|
};
|
|
@@ -5,6 +5,25 @@ import { bnOrZero, isToken } from '@shapeshiftoss/utils';
|
|
|
5
5
|
import { zeroAddress } from 'viem';
|
|
6
6
|
import { chainIdToNearIntentsChain } from '../../types.js';
|
|
7
7
|
import { OneClickService } from '../oneClickService.js';
|
|
8
|
+
const getTokensWithRetry = async () => {
|
|
9
|
+
const maxRetries = 3;
|
|
10
|
+
let lastError = null;
|
|
11
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
12
|
+
try {
|
|
13
|
+
return await OneClickService.getTokens();
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
17
|
+
const isWebSocketError = lastError.message.includes('WebSocket is not ready');
|
|
18
|
+
if (isWebSocketError && attempt < maxRetries) {
|
|
19
|
+
await new Promise(resolve => setTimeout(resolve, 1000 * attempt));
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
throw lastError;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
throw lastError ?? new Error('Failed to get tokens after retries');
|
|
26
|
+
};
|
|
8
27
|
const ATA_RENT_LAMPORTS = 2040000;
|
|
9
28
|
export const calculateAccountCreationCosts = (instructions) => {
|
|
10
29
|
let totalCost = bnOrZero(0);
|
|
@@ -23,8 +42,8 @@ export const getNearIntentsAsset = ({ nearNetwork, contractAddress, }) => {
|
|
|
23
42
|
// ERC20 tokens: "nep141:eth-0x{address}.omft.near"
|
|
24
43
|
return `nep141:${nearNetwork}-${contractAddress.toLowerCase()}.omft.near`;
|
|
25
44
|
};
|
|
26
|
-
const NEP245_CHAINS = ['bsc', 'pol', 'avax', 'op', 'tron', 'monad'];
|
|
27
|
-
const TOKEN_LOOKUP_CHAINS = ['sui', 'starknet'];
|
|
45
|
+
const NEP245_CHAINS = ['bsc', 'pol', 'avax', 'op', 'tron', 'monad', 'plasma'];
|
|
46
|
+
const TOKEN_LOOKUP_CHAINS = ['sui', 'starknet', 'ton'];
|
|
28
47
|
const NEAR_CHAIN = 'near';
|
|
29
48
|
const WNEAR_CONTRACT_ADDRESS = 'wrap.near';
|
|
30
49
|
const isNep245Chain = (chain) => {
|
|
@@ -40,7 +59,7 @@ export const assetToNearIntentsAsset = async (asset) => {
|
|
|
40
59
|
// NEAR chain requires special handling
|
|
41
60
|
// Native NEAR maps to wNEAR (wrap.near)
|
|
42
61
|
if (nearNetwork === NEAR_CHAIN) {
|
|
43
|
-
const tokens = await
|
|
62
|
+
const tokens = await getTokensWithRetry();
|
|
44
63
|
const { assetNamespace, assetReference } = fromAssetId(asset.assetId);
|
|
45
64
|
const isNativeAsset = assetNamespace === 'slip44';
|
|
46
65
|
// Native NEAR maps to wNEAR, tokens use their contract address directly
|
|
@@ -56,7 +75,7 @@ export const assetToNearIntentsAsset = async (asset) => {
|
|
|
56
75
|
// Asset IDs use hashed format that can't be generated from contract addresses
|
|
57
76
|
const requiresLookup = isNep245Chain(nearNetwork) || isTokenLookupChain(nearNetwork) || asset.chainId === solanaChainId;
|
|
58
77
|
if (requiresLookup) {
|
|
59
|
-
const tokens = await
|
|
78
|
+
const tokens = await getTokensWithRetry();
|
|
60
79
|
const { assetNamespace, assetReference } = fromAssetId(asset.assetId);
|
|
61
80
|
const isNativeAsset = assetNamespace === 'slip44';
|
|
62
81
|
const contractAddress = !isNativeAsset ? assetReference.toLowerCase() : null;
|
|
@@ -14,7 +14,6 @@ import { fetchPortalsTradeEstimate, fetchPortalsTradeOrder } from '../utils/fetc
|
|
|
14
14
|
import { getPortalsRouterAddressByChainId, isSupportedChainId } from '../utils/helpers.js';
|
|
15
15
|
export async function getPortalsTradeRate(input, assertGetEvmChainAdapter, swapperConfig) {
|
|
16
16
|
const { sellAsset, buyAsset, accountNumber, affiliateBps, chainId, sellAmountIncludingProtocolFeesCryptoBaseUnit, receiveAddress, supportsEIP1559, } = input;
|
|
17
|
-
const adapter = assertGetEvmChainAdapter(chainId);
|
|
18
17
|
const sellAssetChainId = sellAsset.chainId;
|
|
19
18
|
const buyAssetChainId = buyAsset.chainId;
|
|
20
19
|
if (!isSupportedChainId(sellAssetChainId)) {
|
|
@@ -31,10 +30,16 @@ export async function getPortalsTradeRate(input, assertGetEvmChainAdapter, swapp
|
|
|
31
30
|
details: { chainId: sellAsset.chainId },
|
|
32
31
|
}));
|
|
33
32
|
}
|
|
33
|
+
if (!isSupportedChainId(chainId)) {
|
|
34
|
+
return Err(makeSwapErrorRight({
|
|
35
|
+
message: `unsupported chainId`,
|
|
36
|
+
code: TradeQuoteError.UnsupportedChain,
|
|
37
|
+
details: { chainId },
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
const adapter = assertGetEvmChainAdapter(chainId);
|
|
34
41
|
const isCrossChain = sellAssetChainId !== buyAssetChainId;
|
|
35
42
|
try {
|
|
36
|
-
if (!isSupportedChainId(chainId))
|
|
37
|
-
throw new Error(`Unsupported chainId ${sellAsset.chainId}`);
|
|
38
43
|
const sellPortalsNetwork = chainIdToPortalsNetwork[sellAssetChainId];
|
|
39
44
|
const buyPortalsNetwork = chainIdToPortalsNetwork[buyAssetChainId];
|
|
40
45
|
if (!sellPortalsNetwork) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { arbitrumChainId, avalancheChainId, baseChainId, bscChainId, btcChainId, ethChainId, gnosisChainId, hyperEvmChainId, katanaChainId, monadChainId, optimismChainId, plasmaChainId, polygonChainId, solanaChainId,
|
|
1
|
+
import { arbitrumChainId, avalancheChainId, baseChainId, berachainChainId, blastChainId, bobChainId, bscChainId, btcChainId, celoChainId, cronosChainId, ethChainId, flowEvmChainId, gnosisChainId, hemiChainId, hyperEvmChainId, inkChainId, katanaChainId, lineaChainId, mantleChainId, megaethChainId, modeChainId, monadChainId, optimismChainId, plasmaChainId, plumeChainId, polygonChainId, scrollChainId, solanaChainId, soneiumChainId, sonicChainId, storyChainId, unichainChainId, worldChainChainId, zkSyncEraChainId, } from '@shapeshiftoss/caip';
|
|
2
|
+
import { flowEvmChain } from '@shapeshiftoss/contracts';
|
|
2
3
|
import invert from 'lodash/invert';
|
|
3
4
|
import { zeroAddress } from 'viem';
|
|
4
|
-
import { arbitrum, avalanche, base, bsc, gnosis, hyperEvm, katana, mainnet as ethereum, monad, optimism, plasma, polygon, } from 'viem/chains';
|
|
5
|
+
import { arbitrum, avalanche, base, berachain, blast, bob, bsc, celo, cronos, gnosis, hemi, hyperEvm, ink, katana, linea, mainnet as ethereum, mantle, mode, monad, optimism, plasma, plumeMainnet, polygon, scroll, soneium, sonic, story, unichain, worldchain, zksync, } from 'viem/chains';
|
|
5
6
|
import { TradeQuoteError } from '../../types.js';
|
|
6
7
|
import { RelayErrorCode } from './utils/types.js';
|
|
7
8
|
export const chainIdToRelayChainId = {
|
|
@@ -17,11 +18,35 @@ export const chainIdToRelayChainId = {
|
|
|
17
18
|
[gnosisChainId]: gnosis.id,
|
|
18
19
|
[avalancheChainId]: avalanche.id,
|
|
19
20
|
[bscChainId]: bsc.id,
|
|
20
|
-
|
|
21
|
+
// DISABLED: Tron deposits are built as simple TRC20 transfers instead of depositErc20() vault calls,
|
|
22
|
+
// and the Relay indexer notification is never sent for non-EVM chains. This causes deposits to be
|
|
23
|
+
// untracked by Relay, resulting in stuck/lost funds. Re-enable once the Tron transaction building
|
|
24
|
+
// is verified to use the Relay quote calldata (depositErc20) correctly.
|
|
25
|
+
// [tronChainId]: 728126428,
|
|
21
26
|
[monadChainId]: monad.id,
|
|
22
27
|
[hyperEvmChainId]: hyperEvm.id,
|
|
28
|
+
[mantleChainId]: mantle.id,
|
|
29
|
+
[inkChainId]: ink.id,
|
|
30
|
+
[megaethChainId]: 4326,
|
|
23
31
|
[plasmaChainId]: plasma.id,
|
|
32
|
+
[plumeChainId]: plumeMainnet.id,
|
|
24
33
|
[katanaChainId]: katana.id,
|
|
34
|
+
[flowEvmChainId]: flowEvmChain.id,
|
|
35
|
+
[celoChainId]: celo.id,
|
|
36
|
+
[storyChainId]: story.id,
|
|
37
|
+
[zkSyncEraChainId]: zksync.id,
|
|
38
|
+
[blastChainId]: blast.id,
|
|
39
|
+
[worldChainChainId]: worldchain.id,
|
|
40
|
+
[hemiChainId]: hemi.id,
|
|
41
|
+
[lineaChainId]: linea.id,
|
|
42
|
+
[berachainChainId]: berachain.id,
|
|
43
|
+
[scrollChainId]: scroll.id,
|
|
44
|
+
[cronosChainId]: cronos.id,
|
|
45
|
+
[sonicChainId]: sonic.id,
|
|
46
|
+
[unichainChainId]: unichain.id,
|
|
47
|
+
[bobChainId]: bob.id,
|
|
48
|
+
[modeChainId]: mode.id,
|
|
49
|
+
[soneiumChainId]: soneium.id,
|
|
25
50
|
};
|
|
26
51
|
export var RelayStatusMessage;
|
|
27
52
|
(function (RelayStatusMessage) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ChainId } from '@shapeshiftoss/caip';
|
|
2
|
-
export declare const getRelayDefaultUserAddress: (chainId: ChainId) => "0x000000000000000000000000000000000000dead" | "
|
|
2
|
+
export declare const getRelayDefaultUserAddress: (chainId: ChainId) => "0x000000000000000000000000000000000000dead" | "CbKGgVKLJFb8bBrf58DnAkdryX6ubewVytn7X957YwNr" | "bc1q4vxn43l44h30nkluqfxd9eckf45vr2awz38lwa" | "TLsV52sRDL79HXGGm9yzwKibb6BeruhUzy";
|
|
@@ -136,6 +136,13 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
136
136
|
}));
|
|
137
137
|
}
|
|
138
138
|
const { data: quote } = maybeQuote.unwrap();
|
|
139
|
+
const orderId = quote.protocol?.v2?.orderId;
|
|
140
|
+
if (!orderId && sellAsset.chainId === btcChainId) {
|
|
141
|
+
return Err(makeSwapErrorRight({
|
|
142
|
+
message: 'Relay quote missing protocol.v2.orderId',
|
|
143
|
+
code: TradeQuoteError.UnknownError,
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
139
146
|
const { slippageTolerance, currencyOut, timeEstimate } = quote.details;
|
|
140
147
|
const buyAmountAfterFeesCryptoBaseUnit = currencyOut.amount;
|
|
141
148
|
const rate = getInputOutputRate({
|
|
@@ -330,7 +337,7 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
330
337
|
value: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
331
338
|
chainSpecific: {
|
|
332
339
|
pubkey: xpub ?? getRelayDefaultUserAddress(sellAsset.chainId),
|
|
333
|
-
opReturnData:
|
|
340
|
+
opReturnData: orderId,
|
|
334
341
|
},
|
|
335
342
|
sendMax: false,
|
|
336
343
|
};
|
|
@@ -405,9 +412,10 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
405
412
|
relayTransactionMetadata: {
|
|
406
413
|
from: sendAddress,
|
|
407
414
|
psbt: selectedItem.data.psbt,
|
|
408
|
-
opReturnData:
|
|
415
|
+
opReturnData: orderId,
|
|
409
416
|
to: relayer,
|
|
410
417
|
relayId: quote.steps[0].requestId,
|
|
418
|
+
orderId,
|
|
411
419
|
},
|
|
412
420
|
solanaTransactionMetadata: undefined,
|
|
413
421
|
};
|
|
@@ -425,6 +433,7 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
425
433
|
gasLimit: selectedItem.data?.gas,
|
|
426
434
|
chainId: Number(fromChainId(sellAsset.chainId).chainReference),
|
|
427
435
|
relayId: quote.steps[0].requestId,
|
|
436
|
+
orderId,
|
|
428
437
|
},
|
|
429
438
|
solanaTransactionMetadata: undefined,
|
|
430
439
|
};
|
|
@@ -438,6 +447,7 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
438
447
|
},
|
|
439
448
|
relayTransactionMetadata: {
|
|
440
449
|
relayId: quote.steps[0].requestId,
|
|
450
|
+
orderId,
|
|
441
451
|
},
|
|
442
452
|
};
|
|
443
453
|
}
|
|
@@ -447,6 +457,7 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
447
457
|
solanaTransactionMetadata: undefined,
|
|
448
458
|
relayTransactionMetadata: {
|
|
449
459
|
relayId: quote.steps[0].requestId,
|
|
460
|
+
orderId,
|
|
450
461
|
to: selectedItem.data?.parameter?.contract_address,
|
|
451
462
|
},
|
|
452
463
|
};
|
|
@@ -109,11 +109,111 @@ export const relayTokenToAssetId = (relayToken) => {
|
|
|
109
109
|
assetReference: ASSET_REFERENCE.Plasma,
|
|
110
110
|
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
111
111
|
};
|
|
112
|
+
case CHAIN_REFERENCE.PlumeMainnet:
|
|
113
|
+
return {
|
|
114
|
+
assetReference: ASSET_REFERENCE.Plume,
|
|
115
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
116
|
+
};
|
|
117
|
+
case CHAIN_REFERENCE.MantleMainnet:
|
|
118
|
+
return {
|
|
119
|
+
assetReference: ASSET_REFERENCE.Mantle,
|
|
120
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
121
|
+
};
|
|
122
|
+
case CHAIN_REFERENCE.InkMainnet:
|
|
123
|
+
return {
|
|
124
|
+
assetReference: ASSET_REFERENCE.Ink,
|
|
125
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
126
|
+
};
|
|
127
|
+
case CHAIN_REFERENCE.MegaEthMainnet:
|
|
128
|
+
return {
|
|
129
|
+
assetReference: ASSET_REFERENCE.MegaEth,
|
|
130
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
131
|
+
};
|
|
132
|
+
case CHAIN_REFERENCE.BerachainMainnet:
|
|
133
|
+
return {
|
|
134
|
+
assetReference: ASSET_REFERENCE.Berachain,
|
|
135
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
136
|
+
};
|
|
112
137
|
case CHAIN_REFERENCE.KatanaMainnet:
|
|
113
138
|
return {
|
|
114
139
|
assetReference: ASSET_REFERENCE.Katana,
|
|
115
140
|
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
116
141
|
};
|
|
142
|
+
case CHAIN_REFERENCE.FlowEvmMainnet:
|
|
143
|
+
return {
|
|
144
|
+
assetReference: ASSET_REFERENCE.FlowEvm,
|
|
145
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
146
|
+
};
|
|
147
|
+
case CHAIN_REFERENCE.CeloMainnet:
|
|
148
|
+
return {
|
|
149
|
+
assetReference: ASSET_REFERENCE.Celo,
|
|
150
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
151
|
+
};
|
|
152
|
+
case CHAIN_REFERENCE.StoryMainnet:
|
|
153
|
+
return {
|
|
154
|
+
assetReference: ASSET_REFERENCE.Story,
|
|
155
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
156
|
+
};
|
|
157
|
+
case CHAIN_REFERENCE.ZkSyncEraMainnet:
|
|
158
|
+
return {
|
|
159
|
+
assetReference: ASSET_REFERENCE.ZkSyncEra,
|
|
160
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
161
|
+
};
|
|
162
|
+
case CHAIN_REFERENCE.BlastMainnet:
|
|
163
|
+
return {
|
|
164
|
+
assetReference: ASSET_REFERENCE.Blast,
|
|
165
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
166
|
+
};
|
|
167
|
+
case CHAIN_REFERENCE.WorldChainMainnet:
|
|
168
|
+
return {
|
|
169
|
+
assetReference: ASSET_REFERENCE.WorldChain,
|
|
170
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
171
|
+
};
|
|
172
|
+
case CHAIN_REFERENCE.HemiMainnet:
|
|
173
|
+
return {
|
|
174
|
+
assetReference: ASSET_REFERENCE.Hemi,
|
|
175
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
176
|
+
};
|
|
177
|
+
case CHAIN_REFERENCE.LineaMainnet:
|
|
178
|
+
return {
|
|
179
|
+
assetReference: ASSET_REFERENCE.Linea,
|
|
180
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
181
|
+
};
|
|
182
|
+
case CHAIN_REFERENCE.ScrollMainnet:
|
|
183
|
+
return {
|
|
184
|
+
assetReference: ASSET_REFERENCE.Scroll,
|
|
185
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
186
|
+
};
|
|
187
|
+
case CHAIN_REFERENCE.CronosMainnet:
|
|
188
|
+
return {
|
|
189
|
+
assetReference: ASSET_REFERENCE.Cronos,
|
|
190
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
191
|
+
};
|
|
192
|
+
case CHAIN_REFERENCE.SonicMainnet:
|
|
193
|
+
return {
|
|
194
|
+
assetReference: ASSET_REFERENCE.Sonic,
|
|
195
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
196
|
+
};
|
|
197
|
+
case CHAIN_REFERENCE.UnichainMainnet:
|
|
198
|
+
return {
|
|
199
|
+
assetReference: ASSET_REFERENCE.Unichain,
|
|
200
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
201
|
+
};
|
|
202
|
+
case CHAIN_REFERENCE.BobMainnet:
|
|
203
|
+
return {
|
|
204
|
+
assetReference: ASSET_REFERENCE.Bob,
|
|
205
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
206
|
+
};
|
|
207
|
+
case CHAIN_REFERENCE.ModeMainnet:
|
|
208
|
+
return {
|
|
209
|
+
assetReference: ASSET_REFERENCE.Mode,
|
|
210
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
211
|
+
};
|
|
212
|
+
case CHAIN_REFERENCE.SoneiumMainnet:
|
|
213
|
+
return {
|
|
214
|
+
assetReference: ASSET_REFERENCE.Soneium,
|
|
215
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
216
|
+
};
|
|
117
217
|
default:
|
|
118
218
|
throw Error(`chainId '${relayToken.chainId}' not supported`);
|
|
119
219
|
}
|
|
@@ -22,6 +22,7 @@ export type RelayTransactionMetadata = {
|
|
|
22
22
|
psbt?: string;
|
|
23
23
|
opReturnData?: string;
|
|
24
24
|
relayId: string;
|
|
25
|
+
orderId: string | undefined;
|
|
25
26
|
};
|
|
26
27
|
export type RelayStatus = {
|
|
27
28
|
status: 'success' | 'failed' | 'pending' | 'refund' | 'delayed' | 'waiting';
|
|
@@ -120,10 +121,24 @@ export type RelayQuoteStep = {
|
|
|
120
121
|
requestId: string;
|
|
121
122
|
items?: RelayQuoteItem[];
|
|
122
123
|
};
|
|
124
|
+
export type RelayProtocolV2 = {
|
|
125
|
+
orderId: string | undefined;
|
|
126
|
+
orderData?: unknown;
|
|
127
|
+
paymentDetails?: {
|
|
128
|
+
chainId: string;
|
|
129
|
+
depository: string;
|
|
130
|
+
currency: string;
|
|
131
|
+
amount: string;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
export type RelayProtocol = {
|
|
135
|
+
v2?: RelayProtocolV2;
|
|
136
|
+
};
|
|
123
137
|
export type RelayQuote = {
|
|
124
138
|
fees: RelayFees;
|
|
125
139
|
details: QuoteDetails;
|
|
126
140
|
steps: RelayQuoteStep[];
|
|
141
|
+
protocol?: RelayProtocol;
|
|
127
142
|
};
|
|
128
143
|
export declare const isRelayQuoteUtxoItemData: (item: RelayQuoteUtxoItemData | RelayQuoteEvmItemData | RelayQuoteSolanaItemData | RelayQuoteTronItemData) => item is RelayQuoteUtxoItemData;
|
|
129
144
|
export declare const isRelayQuoteEvmItemData: (item: RelayQuoteUtxoItemData | RelayQuoteEvmItemData | RelayQuoteSolanaItemData | RelayQuoteTronItemData) => item is RelayQuoteEvmItemData;
|