@shapeshiftoss/swapper 17.7.3 → 17.8.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.
Files changed (124) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/constants.js +35 -26
  3. package/dist/cjs/index.d.ts +1 -0
  4. package/dist/cjs/index.js +1 -0
  5. package/dist/cjs/swappers/ArbitrumBridgeSwapper/getTradeQuote/getTradeQuote.test.js +12 -4
  6. package/dist/cjs/swappers/BebopSwapper/getBebopSolanaTradeRate/getBebopSolanaTradeRate.js +9 -5
  7. package/dist/cjs/swappers/BebopSwapper/getBebopTradeQuote/getBebopTradeQuote.js +1 -9
  8. package/dist/cjs/swappers/BebopSwapper/getBebopTradeRate/getBebopTradeRate.js +9 -13
  9. package/dist/cjs/swappers/BebopSwapper/types.d.ts +64 -78
  10. package/dist/cjs/swappers/BebopSwapper/utils/fetchFromBebop.d.ts +0 -16
  11. package/dist/cjs/swappers/BebopSwapper/utils/fetchFromBebop.js +49 -82
  12. package/dist/cjs/swappers/BobGatewaySwapper/BobGatewaySwapper.d.ts +2 -0
  13. package/dist/cjs/swappers/BobGatewaySwapper/BobGatewaySwapper.js +8 -0
  14. package/dist/cjs/swappers/BobGatewaySwapper/endpoints.d.ts +2 -0
  15. package/dist/cjs/swappers/BobGatewaySwapper/endpoints.js +143 -0
  16. package/dist/cjs/swappers/BobGatewaySwapper/index.d.ts +3 -0
  17. package/dist/cjs/swappers/BobGatewaySwapper/index.js +22 -0
  18. package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.d.ts +3 -0
  19. package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +90 -0
  20. package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeRate.d.ts +3 -0
  21. package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeRate.js +73 -0
  22. package/dist/cjs/swappers/BobGatewaySwapper/types.d.ts +20 -0
  23. package/dist/cjs/swappers/BobGatewaySwapper/types.js +2 -0
  24. package/dist/cjs/swappers/BobGatewaySwapper/utils/constants.d.ts +13 -0
  25. package/dist/cjs/swappers/BobGatewaySwapper/utils/constants.js +31 -0
  26. package/dist/cjs/swappers/BobGatewaySwapper/utils/helpers.d.ts +49 -0
  27. package/dist/cjs/swappers/BobGatewaySwapper/utils/helpers.js +314 -0
  28. package/dist/cjs/swappers/ChainflipSwapper/ChainflipSwapper.js +1 -0
  29. package/dist/cjs/swappers/ChainflipSwapper/constants.d.ts +1 -1
  30. package/dist/cjs/swappers/ChainflipSwapper/constants.js +3 -0
  31. package/dist/cjs/swappers/ChainflipSwapper/endpoints.js +20 -0
  32. package/dist/cjs/swappers/ChainflipSwapper/types.d.ts +2 -1
  33. package/dist/cjs/swappers/ChainflipSwapper/types.js +1 -0
  34. package/dist/cjs/swappers/ChainflipSwapper/utils/getQuoteOrRate.js +23 -3
  35. package/dist/cjs/swappers/ChainflipSwapper/utils/helpers.d.ts +2 -2
  36. package/dist/cjs/swappers/ChainflipSwapper/utils/helpers.js +2 -1
  37. package/dist/cjs/swappers/CowSwapper/utils/helpers/helpers.test.js +3 -3
  38. package/dist/cjs/swappers/RelaySwapper/constant.js +1 -1
  39. package/dist/cjs/swappers/SunioSwapper/endpoints.js +19 -36
  40. package/dist/cjs/swappers/SunioSwapper/utils/buildSwapContractCall.d.ts +6 -0
  41. package/dist/cjs/swappers/SunioSwapper/utils/buildSwapContractCall.js +33 -0
  42. package/dist/cjs/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +6 -6
  43. package/dist/cjs/swappers/SunioSwapper/utils/constants.d.ts +2 -0
  44. package/dist/cjs/swappers/SunioSwapper/utils/constants.js +7 -1
  45. package/dist/cjs/swappers/SunioSwapper/utils/estimateSunioNetworkFee.d.ts +12 -0
  46. package/dist/cjs/swappers/SunioSwapper/utils/estimateSunioNetworkFee.js +78 -0
  47. package/dist/cjs/swappers/SunioSwapper/utils/getQuoteOrRate.js +16 -74
  48. package/dist/cjs/swappers/SunioSwapper/utils/getSunioTransactionFees.d.ts +2 -0
  49. package/dist/cjs/swappers/SunioSwapper/utils/getSunioTransactionFees.js +36 -0
  50. package/dist/cjs/swappers/utils/helpers/helpers.js +1 -0
  51. package/dist/cjs/thorchain-utils/getL1RateOrQuote.js +5 -2
  52. package/dist/cjs/thorchain-utils/getQuote.js +27 -29
  53. package/dist/cjs/thorchain-utils/tron/getTronTransactionFees.js +8 -5
  54. package/dist/cjs/thorchain-utils/types.d.ts +1 -1
  55. package/dist/cjs/types.d.ts +10 -3
  56. package/dist/cjs/types.js +5 -0
  57. package/dist/esm/.tsbuildinfo +1 -1
  58. package/dist/esm/constants.js +9 -0
  59. package/dist/esm/index.d.ts +1 -0
  60. package/dist/esm/index.js +1 -0
  61. package/dist/esm/swappers/ArbitrumBridgeSwapper/getTradeQuote/getTradeQuote.test.js +12 -4
  62. package/dist/esm/swappers/BebopSwapper/getBebopSolanaTradeRate/getBebopSolanaTradeRate.js +10 -6
  63. package/dist/esm/swappers/BebopSwapper/getBebopTradeQuote/getBebopTradeQuote.js +1 -9
  64. package/dist/esm/swappers/BebopSwapper/getBebopTradeRate/getBebopTradeRate.js +10 -14
  65. package/dist/esm/swappers/BebopSwapper/types.d.ts +64 -78
  66. package/dist/esm/swappers/BebopSwapper/utils/fetchFromBebop.d.ts +0 -16
  67. package/dist/esm/swappers/BebopSwapper/utils/fetchFromBebop.js +45 -76
  68. package/dist/esm/swappers/BobGatewaySwapper/BobGatewaySwapper.d.ts +2 -0
  69. package/dist/esm/swappers/BobGatewaySwapper/BobGatewaySwapper.js +5 -0
  70. package/dist/esm/swappers/BobGatewaySwapper/endpoints.d.ts +2 -0
  71. package/dist/esm/swappers/BobGatewaySwapper/endpoints.js +140 -0
  72. package/dist/esm/swappers/BobGatewaySwapper/index.d.ts +3 -0
  73. package/dist/esm/swappers/BobGatewaySwapper/index.js +3 -0
  74. package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.d.ts +3 -0
  75. package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +86 -0
  76. package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeRate.d.ts +3 -0
  77. package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeRate.js +69 -0
  78. package/dist/esm/swappers/BobGatewaySwapper/types.d.ts +20 -0
  79. package/dist/esm/swappers/BobGatewaySwapper/utils/constants.d.ts +13 -0
  80. package/dist/esm/swappers/BobGatewaySwapper/utils/constants.js +27 -0
  81. package/dist/esm/swappers/BobGatewaySwapper/utils/helpers.d.ts +49 -0
  82. package/dist/esm/swappers/BobGatewaySwapper/utils/helpers.js +299 -0
  83. package/dist/esm/swappers/ChainflipSwapper/ChainflipSwapper.js +2 -1
  84. package/dist/esm/swappers/ChainflipSwapper/constants.d.ts +1 -1
  85. package/dist/esm/swappers/ChainflipSwapper/constants.js +4 -1
  86. package/dist/esm/swappers/ChainflipSwapper/endpoints.js +20 -0
  87. package/dist/esm/swappers/ChainflipSwapper/types.d.ts +2 -1
  88. package/dist/esm/swappers/ChainflipSwapper/types.js +1 -0
  89. package/dist/esm/swappers/ChainflipSwapper/utils/getQuoteOrRate.js +24 -4
  90. package/dist/esm/swappers/ChainflipSwapper/utils/helpers.d.ts +2 -2
  91. package/dist/esm/swappers/ChainflipSwapper/utils/helpers.js +2 -1
  92. package/dist/esm/swappers/CowSwapper/utils/helpers/helpers.test.js +3 -3
  93. package/dist/esm/swappers/RelaySwapper/constant.js +1 -1
  94. package/dist/esm/swappers/SunioSwapper/endpoints.js +19 -36
  95. package/dist/esm/swappers/SunioSwapper/utils/buildSwapContractCall.d.ts +6 -0
  96. package/dist/esm/swappers/SunioSwapper/utils/buildSwapContractCall.js +29 -0
  97. package/dist/esm/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +6 -6
  98. package/dist/esm/swappers/SunioSwapper/utils/constants.d.ts +2 -0
  99. package/dist/esm/swappers/SunioSwapper/utils/constants.js +6 -0
  100. package/dist/esm/swappers/SunioSwapper/utils/estimateSunioNetworkFee.d.ts +12 -0
  101. package/dist/esm/swappers/SunioSwapper/utils/estimateSunioNetworkFee.js +74 -0
  102. package/dist/esm/swappers/SunioSwapper/utils/getQuoteOrRate.js +16 -74
  103. package/dist/esm/swappers/SunioSwapper/utils/getSunioTransactionFees.d.ts +2 -0
  104. package/dist/esm/swappers/SunioSwapper/utils/getSunioTransactionFees.js +32 -0
  105. package/dist/esm/swappers/utils/helpers/helpers.js +2 -1
  106. package/dist/esm/thorchain-utils/getL1RateOrQuote.js +5 -2
  107. package/dist/esm/thorchain-utils/getQuote.js +27 -29
  108. package/dist/esm/thorchain-utils/tron/getTronTransactionFees.js +8 -5
  109. package/dist/esm/thorchain-utils/types.d.ts +1 -1
  110. package/dist/esm/types.d.ts +10 -3
  111. package/dist/esm/types.js +5 -0
  112. package/package.json +8 -7
  113. package/dist/cjs/swappers/SunioSwapper/utils/buildSwapTransaction.d.ts +0 -11
  114. package/dist/cjs/swappers/SunioSwapper/utils/buildSwapTransaction.js +0 -57
  115. package/dist/cjs/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.d.ts +0 -12
  116. package/dist/cjs/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.js +0 -47
  117. package/dist/cjs/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.test.js +0 -100
  118. package/dist/esm/swappers/SunioSwapper/utils/buildSwapTransaction.d.ts +0 -11
  119. package/dist/esm/swappers/SunioSwapper/utils/buildSwapTransaction.js +0 -53
  120. package/dist/esm/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.d.ts +0 -12
  121. package/dist/esm/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.js +0 -41
  122. package/dist/esm/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.test.d.ts +0 -1
  123. package/dist/esm/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.test.js +0 -98
  124. /package/dist/{cjs/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.test.d.ts → esm/swappers/BobGatewaySwapper/types.js} +0 -0
@@ -0,0 +1,140 @@
1
+ import { isGatewayError } from '@gobob/bob-sdk';
2
+ import { evm } from '@shapeshiftoss/chain-adapters';
3
+ import { TxStatus } from '@shapeshiftoss/unchained-client';
4
+ import { bnOrZero } from '@shapeshiftoss/utils';
5
+ import { getExecutableTradeStep, isExecutableTradeQuote } from '../../utils.js';
6
+ import { getBobGatewayTradeQuote } from './swapperApi/getTradeQuote.js';
7
+ import { getBobGatewayTradeRate } from './swapperApi/getTradeRate.js';
8
+ import { getBobGatewayClient, mapBobGatewayOrderStatusToTxStatus, registerBobGatewayTx, } from './utils/helpers.js';
9
+ const registeredSwapIds = new Set();
10
+ export const bobGatewayApi = {
11
+ getTradeRate: async (input, deps) => {
12
+ return (await getBobGatewayTradeRate(input, deps)).map(tradeRate => [tradeRate]);
13
+ },
14
+ getTradeQuote: async (input, deps) => {
15
+ return (await getBobGatewayTradeQuote(input, deps)).map(tradeQuote => [tradeQuote]);
16
+ },
17
+ getUnsignedUtxoTransaction: ({ stepIndex, tradeQuote, xpub, accountType, assertGetUtxoChainAdapter, }) => {
18
+ if (!isExecutableTradeQuote(tradeQuote)) {
19
+ throw new Error('[BobGateway] unable to execute a trade rate');
20
+ }
21
+ const step = getExecutableTradeStep(tradeQuote, stepIndex);
22
+ const { bobSpecific, sellAsset } = step;
23
+ const adapter = assertGetUtxoChainAdapter(sellAsset.chainId);
24
+ if (!bobSpecific?.utxoTx)
25
+ throw new Error('[BobGateway] invalid utxo transaction');
26
+ const { depositAddress, opReturnData } = bobSpecific.utxoTx;
27
+ return adapter.buildSendApiTransaction({
28
+ value: step.sellAmountIncludingProtocolFeesCryptoBaseUnit,
29
+ xpub,
30
+ to: depositAddress,
31
+ accountNumber: step.accountNumber,
32
+ skipToAddressValidation: true,
33
+ chainSpecific: {
34
+ accountType,
35
+ opReturnData,
36
+ satoshiPerByte: step.feeData.chainSpecific.satsPerByte,
37
+ },
38
+ });
39
+ },
40
+ getUtxoTransactionFees: async ({ stepIndex, tradeQuote, xpub, assertGetUtxoChainAdapter }) => {
41
+ if (!isExecutableTradeQuote(tradeQuote)) {
42
+ throw new Error('[BobGateway] unable to execute a trade rate');
43
+ }
44
+ const step = getExecutableTradeStep(tradeQuote, stepIndex);
45
+ const { bobSpecific, sellAsset } = step;
46
+ const adapter = assertGetUtxoChainAdapter(sellAsset.chainId);
47
+ if (!bobSpecific?.utxoTx)
48
+ throw new Error('[BobGateway] invalid utxo transaction');
49
+ const { depositAddress, opReturnData } = bobSpecific.utxoTx;
50
+ const { fast } = await adapter.getFeeData({
51
+ to: depositAddress,
52
+ value: step.sellAmountIncludingProtocolFeesCryptoBaseUnit,
53
+ chainSpecific: { pubkey: xpub, opReturnData },
54
+ sendMax: false,
55
+ });
56
+ return fast.txFee;
57
+ },
58
+ getUnsignedEvmTransaction: async ({ from, stepIndex, tradeQuote, assertGetEvmChainAdapter, supportsEIP1559, }) => {
59
+ if (!isExecutableTradeQuote(tradeQuote)) {
60
+ throw new Error('[BobGateway] unable to execute a trade rate');
61
+ }
62
+ const step = getExecutableTradeStep(tradeQuote, stepIndex);
63
+ const { accountNumber, bobSpecific, sellAsset } = step;
64
+ const adapter = assertGetEvmChainAdapter(sellAsset.chainId);
65
+ if (!bobSpecific?.evmTx)
66
+ throw new Error('[BobGateway] invalid evm transaction');
67
+ const { to, data, value } = bobSpecific.evmTx;
68
+ const feeData = await evm.getFees({ adapter, data, to, value, from, supportsEIP1559 });
69
+ // Pad the gas limit of the tx we actually broadcast to reduce the risk of out-of-gas reverts.
70
+ const gasLimit = bnOrZero(feeData.gasLimit).times(1.2).toFixed(0);
71
+ return adapter.buildCustomApiTx({
72
+ accountNumber,
73
+ from,
74
+ to,
75
+ value,
76
+ data,
77
+ ...feeData,
78
+ gasLimit,
79
+ });
80
+ },
81
+ getEvmTransactionFees: async ({ from, stepIndex, tradeQuote, supportsEIP1559, assertGetEvmChainAdapter, }) => {
82
+ if (!isExecutableTradeQuote(tradeQuote)) {
83
+ throw new Error('[BobGateway] unable to execute a trade rate');
84
+ }
85
+ const step = getExecutableTradeStep(tradeQuote, stepIndex);
86
+ const { bobSpecific, sellAsset } = step;
87
+ const adapter = assertGetEvmChainAdapter(sellAsset.chainId);
88
+ if (!bobSpecific?.evmTx)
89
+ throw new Error('[BobGateway] invalid evm transaction');
90
+ const { to, data, value } = bobSpecific.evmTx;
91
+ const feeData = await evm.getFees({ adapter, data, to, value, from, supportsEIP1559 });
92
+ return feeData.networkFeeCryptoBaseUnit;
93
+ },
94
+ checkTradeStatus: async ({ swap, config, txHash }) => {
95
+ if (!swap)
96
+ throw new Error('[BobGateway] swap is required for status check');
97
+ const orderId = swap.metadata.bobSpecific?.orderId;
98
+ if (!orderId)
99
+ throw new Error('[BobGateway] orderId is required for status check');
100
+ if (txHash && !registeredSwapIds.has(swap.id)) {
101
+ try {
102
+ await registerBobGatewayTx({
103
+ config,
104
+ orderId,
105
+ txHash,
106
+ sellAsset: swap.sellAsset,
107
+ buyAsset: swap.buyAsset,
108
+ });
109
+ registeredSwapIds.add(swap.id);
110
+ }
111
+ catch { }
112
+ }
113
+ let orderInfo;
114
+ try {
115
+ orderInfo = await getBobGatewayClient(config).getOrder(orderId);
116
+ }
117
+ catch (err) {
118
+ if (isGatewayError(err)) {
119
+ if (err.code === 'ORDER_NOT_FOUND') {
120
+ return {
121
+ buyTxHash: undefined,
122
+ status: TxStatus.Unknown,
123
+ message: 'Waiting for deposit...',
124
+ };
125
+ }
126
+ }
127
+ throw err;
128
+ }
129
+ const status = mapBobGatewayOrderStatusToTxStatus(orderInfo.status);
130
+ const buyTxHash = 'success' in orderInfo.status ? orderInfo.status.success.receivedTokens[0]?.txHash : undefined;
131
+ const refundTxHash = 'refunded' in orderInfo.status
132
+ ? orderInfo.status.refunded.refundedTokens[0]?.txHash
133
+ : undefined;
134
+ return {
135
+ status,
136
+ buyTxHash,
137
+ message: refundTxHash ? 'Trade refunded' : undefined,
138
+ };
139
+ },
140
+ };
@@ -0,0 +1,3 @@
1
+ export { bobGatewayApi } from './endpoints.js';
2
+ export { bobGatewaySwapper } from './BobGatewaySwapper.js';
3
+ export * from './utils/constants.js';
@@ -0,0 +1,3 @@
1
+ export { bobGatewayApi } from './endpoints.js';
2
+ export { bobGatewaySwapper } from './BobGatewaySwapper.js';
3
+ export * from './utils/constants.js';
@@ -0,0 +1,3 @@
1
+ import type { Result } from '@sniptt/monads';
2
+ import type { CommonTradeQuoteInput, SwapErrorRight, SwapperDeps, TradeQuote } from '../../../types.js';
3
+ export declare const getBobGatewayTradeQuote: (input: CommonTradeQuoteInput, deps: SwapperDeps) => Promise<Result<TradeQuote, SwapErrorRight>>;
@@ -0,0 +1,86 @@
1
+ import { isEvmChainId } from '@shapeshiftoss/chain-adapters';
2
+ import { Err, Ok } from '@sniptt/monads';
3
+ import { v4 as uuid } from 'uuid';
4
+ import { SwapperName, TradeQuoteError } from '../../../types.js';
5
+ import { getInputOutputRate, makeSwapErrorRight } from '../../../utils.js';
6
+ import { assertValidTrade, createBobGatewayOrderMetadata, getBobGatewayAllowanceContract, getBobGatewayQuote, getBobGatewayQuoteFeeData, parseBobGatewayQuote, } from '../utils/helpers.js';
7
+ export const getBobGatewayTradeQuote = async (input, deps) => {
8
+ const { sellAsset, buyAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, sendAddress, receiveAddress, accountNumber, affiliateBps, slippageTolerancePercentageDecimal, } = input;
9
+ const { config } = deps;
10
+ if (!sendAddress) {
11
+ return Err(makeSwapErrorRight({
12
+ message: '[BobGateway] sendAddress is required for quote',
13
+ code: TradeQuoteError.UnknownError,
14
+ }));
15
+ }
16
+ if (!receiveAddress) {
17
+ return Err(makeSwapErrorRight({
18
+ message: '[BobGateway] receiveAddress is required for quote',
19
+ code: TradeQuoteError.UnknownError,
20
+ }));
21
+ }
22
+ const assertion = assertValidTrade({ sellAsset, buyAsset });
23
+ if (assertion.isErr())
24
+ return Err(assertion.unwrapErr());
25
+ const { sellChainName, buyChainName } = assertion.unwrap();
26
+ // omit the sender for utxo sells so order creation does not enforce a per-address confirmed
27
+ // funds check (deposits are matched via op_return, not the sending address)
28
+ const sender = isEvmChainId(sellAsset.chainId) ? sendAddress : undefined;
29
+ const maybeQuote = await getBobGatewayQuote({
30
+ config,
31
+ sellAsset,
32
+ buyAsset,
33
+ sellChainName,
34
+ buyChainName,
35
+ sender,
36
+ recipient: receiveAddress,
37
+ amount: sellAmountIncludingProtocolFeesCryptoBaseUnit,
38
+ affiliateBps,
39
+ slippageTolerancePercentageDecimal,
40
+ });
41
+ if (maybeQuote.isErr())
42
+ return Err(maybeQuote.unwrapErr());
43
+ const quote = maybeQuote.unwrap();
44
+ const maybeOrderMetadata = await createBobGatewayOrderMetadata(config, quote);
45
+ if (maybeOrderMetadata.isErr())
46
+ return Err(maybeOrderMetadata.unwrapErr());
47
+ const orderMetadata = maybeOrderMetadata.unwrap();
48
+ const maybeFeeData = await getBobGatewayQuoteFeeData(input, deps, orderMetadata);
49
+ if (maybeFeeData.isErr())
50
+ return Err(maybeFeeData.unwrapErr());
51
+ const feeData = maybeFeeData.unwrap();
52
+ const { buyAmountBeforeFeesCryptoBaseUnit, buyAmountAfterFeesCryptoBaseUnit, protocolFees, estimatedExecutionTimeMs, } = parseBobGatewayQuote(quote, buyAsset, deps.assetsById);
53
+ const rate = getInputOutputRate({
54
+ sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
55
+ buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
56
+ sellAsset,
57
+ buyAsset,
58
+ });
59
+ const allowanceContract = getBobGatewayAllowanceContract(quote, sellAsset);
60
+ const tradeQuote = {
61
+ id: uuid(),
62
+ quoteOrRate: 'quote',
63
+ rate,
64
+ receiveAddress,
65
+ affiliateBps,
66
+ slippageTolerancePercentageDecimal,
67
+ swapperName: SwapperName.BobGateway,
68
+ steps: [
69
+ {
70
+ buyAmountBeforeFeesCryptoBaseUnit,
71
+ buyAmountAfterFeesCryptoBaseUnit,
72
+ sellAmountIncludingProtocolFeesCryptoBaseUnit,
73
+ feeData: { ...feeData, protocolFees },
74
+ rate,
75
+ source: SwapperName.BobGateway,
76
+ buyAsset,
77
+ sellAsset,
78
+ accountNumber,
79
+ allowanceContract,
80
+ estimatedExecutionTimeMs,
81
+ bobSpecific: orderMetadata,
82
+ },
83
+ ],
84
+ };
85
+ return Ok(tradeQuote);
86
+ };
@@ -0,0 +1,3 @@
1
+ import type { Result } from '@sniptt/monads';
2
+ import type { GetTradeRateInput, SwapErrorRight, SwapperDeps, TradeRate } from '../../../types.js';
3
+ export declare const getBobGatewayTradeRate: (input: GetTradeRateInput, deps: SwapperDeps) => Promise<Result<TradeRate, SwapErrorRight>>;
@@ -0,0 +1,69 @@
1
+ import { btcChainId } from '@shapeshiftoss/caip';
2
+ import { Err, Ok } from '@sniptt/monads';
3
+ import { v4 as uuid } from 'uuid';
4
+ import { SwapperName } from '../../../types.js';
5
+ import { getInputOutputRate } from '../../../utils.js';
6
+ import { DUMMY_BTC_ADDRESS, DUMMY_EVM_ADDRESS } from '../utils/constants.js';
7
+ import { assertValidTrade, getBobGatewayAllowanceContract, getBobGatewayQuote, getBobGatewayRateNetworkFeeCryptoBaseUnit, parseBobGatewayQuote, } from '../utils/helpers.js';
8
+ export const getBobGatewayTradeRate = async (input, deps) => {
9
+ const { sellAsset, buyAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, receiveAddress, accountNumber, affiliateBps, slippageTolerancePercentageDecimal, } = input;
10
+ const { config } = deps;
11
+ const assertion = assertValidTrade({ sellAsset, buyAsset });
12
+ if (assertion.isErr())
13
+ return Err(assertion.unwrapErr());
14
+ const { sellChainName, buyChainName } = assertion.unwrap();
15
+ const recipient = receiveAddress ?? (buyAsset.chainId === btcChainId ? DUMMY_BTC_ADDRESS : DUMMY_EVM_ADDRESS);
16
+ const sender = sellAsset.chainId === btcChainId ? undefined : DUMMY_EVM_ADDRESS;
17
+ const maybeQuote = await getBobGatewayQuote({
18
+ config,
19
+ sellAsset,
20
+ buyAsset,
21
+ sellChainName,
22
+ buyChainName,
23
+ sender,
24
+ recipient,
25
+ amount: sellAmountIncludingProtocolFeesCryptoBaseUnit,
26
+ affiliateBps,
27
+ slippageTolerancePercentageDecimal,
28
+ });
29
+ if (maybeQuote.isErr())
30
+ return Err(maybeQuote.unwrapErr());
31
+ const quote = maybeQuote.unwrap();
32
+ const { buyAmountBeforeFeesCryptoBaseUnit, buyAmountAfterFeesCryptoBaseUnit, protocolFees, estimatedExecutionTimeMs, } = parseBobGatewayQuote(quote, buyAsset, deps.assetsById);
33
+ const rate = getInputOutputRate({
34
+ sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
35
+ buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
36
+ sellAsset,
37
+ buyAsset,
38
+ });
39
+ const allowanceContract = getBobGatewayAllowanceContract(quote, sellAsset);
40
+ const networkFeeCryptoBaseUnit = await getBobGatewayRateNetworkFeeCryptoBaseUnit(quote, sellAsset, deps);
41
+ const tradeRate = {
42
+ id: uuid(),
43
+ quoteOrRate: 'rate',
44
+ rate,
45
+ receiveAddress,
46
+ affiliateBps,
47
+ slippageTolerancePercentageDecimal,
48
+ swapperName: SwapperName.BobGateway,
49
+ steps: [
50
+ {
51
+ buyAmountBeforeFeesCryptoBaseUnit,
52
+ buyAmountAfterFeesCryptoBaseUnit,
53
+ sellAmountIncludingProtocolFeesCryptoBaseUnit,
54
+ feeData: {
55
+ networkFeeCryptoBaseUnit,
56
+ protocolFees,
57
+ },
58
+ rate,
59
+ source: SwapperName.BobGateway,
60
+ buyAsset,
61
+ sellAsset,
62
+ accountNumber,
63
+ allowanceContract,
64
+ estimatedExecutionTimeMs,
65
+ },
66
+ ],
67
+ };
68
+ return Ok(tradeRate);
69
+ };
@@ -0,0 +1,20 @@
1
+ type BobGatewayEvmTxMetadata = {
2
+ to: string;
3
+ data: string;
4
+ value: string;
5
+ chain: string;
6
+ };
7
+ type BobGatewayUtxoTxMetadata = {
8
+ depositAddress: string;
9
+ opReturnData?: string;
10
+ };
11
+ export type BobGatewayMetadata = {
12
+ orderId: string;
13
+ } & ({
14
+ evmTx: BobGatewayEvmTxMetadata;
15
+ utxoTx?: never;
16
+ } | {
17
+ utxoTx: BobGatewayUtxoTxMetadata;
18
+ evmTx?: never;
19
+ });
20
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { ChainId } from '@shapeshiftoss/caip';
2
+ export declare const BOB_GATEWAY_BASE_URL = "https://gateway-api-mainnet.gobob.xyz";
3
+ export declare const chainIdToBobGatewayChainName: {
4
+ readonly [x: string]: "arbitrum" | "avalanche" | "base" | "bera" | "bitcoin" | "bob" | "bsc" | "ethereum" | "sei" | "sonic" | "unichain";
5
+ };
6
+ export declare const bobGatewayChainNameToChainId: Record<BobGatewayChainName, ChainId>;
7
+ export type BobGatewayChainName = (typeof chainIdToBobGatewayChainName)[keyof typeof chainIdToBobGatewayChainName];
8
+ export declare const DUMMY_EVM_ADDRESS: `0x${string}`;
9
+ export declare const DUMMY_BTC_ADDRESS = "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq";
10
+ export declare const BOB_GATEWAY_TOKENSWAP_DEFAULT_GAS_LIMIT = "350000";
11
+ export declare const BOB_GATEWAY_OFFRAMP_DEFAULT_GAS_LIMIT = "550000";
12
+ export declare const BOB_GATEWAY_ONRAMP_DEFAULT_TX_VSIZE = "200";
13
+ export declare const decimalSlippageToBobBps: (slippageDecimal: string) => string;
@@ -0,0 +1,27 @@
1
+ import { arbitrumChainId, avalancheChainId, baseChainId, berachainChainId, bobChainId, bscChainId, btcChainId, ethChainId, seiChainId, sonicChainId, unichainChainId, } from '@shapeshiftoss/caip';
2
+ export const BOB_GATEWAY_BASE_URL = 'https://gateway-api-mainnet.gobob.xyz';
3
+ // Chain name strings expected by the BOB Gateway API
4
+ // https://gateway-api-mainnet.gobob.xyz/v2/get-routes
5
+ export const chainIdToBobGatewayChainName = {
6
+ [arbitrumChainId]: 'arbitrum',
7
+ [avalancheChainId]: 'avalanche',
8
+ [baseChainId]: 'base',
9
+ [berachainChainId]: 'bera',
10
+ [btcChainId]: 'bitcoin',
11
+ [bobChainId]: 'bob',
12
+ [bscChainId]: 'bsc',
13
+ [ethChainId]: 'ethereum',
14
+ [seiChainId]: 'sei',
15
+ [sonicChainId]: 'sonic',
16
+ [unichainChainId]: 'unichain',
17
+ };
18
+ export const bobGatewayChainNameToChainId = Object.fromEntries(Object.entries(chainIdToBobGatewayChainName).map(([chainId, chainName]) => [chainName, chainId]));
19
+ export const DUMMY_EVM_ADDRESS = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
20
+ export const DUMMY_BTC_ADDRESS = 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq';
21
+ export const BOB_GATEWAY_TOKENSWAP_DEFAULT_GAS_LIMIT = '350000'; // EVM→EVM
22
+ export const BOB_GATEWAY_OFFRAMP_DEFAULT_GAS_LIMIT = '550000'; // EVM→BTC
23
+ export const BOB_GATEWAY_ONRAMP_DEFAULT_TX_VSIZE = '200'; // BTC→EVM
24
+ // https://docs.gobob.xyz/api-reference/v2/get-a-gateway-quote#parameter-slippage
25
+ export const decimalSlippageToBobBps = (slippageDecimal) => {
26
+ return String(Math.round(parseFloat(slippageDecimal) * 10_000));
27
+ };
@@ -0,0 +1,49 @@
1
+ import type { GatewayOrderStatusV2, GatewayQuoteV2, GetQuoteParams } from '@gobob/bob-sdk';
2
+ import { GatewaySDK } from '@gobob/bob-sdk';
3
+ import type { AssetId } from '@shapeshiftoss/caip';
4
+ import type { Asset, AssetsByIdPartial } from '@shapeshiftoss/types';
5
+ import { TxStatus } from '@shapeshiftoss/unchained-client';
6
+ import type { Result } from '@sniptt/monads';
7
+ import type { GetTradeQuoteInput, QuoteFeeData, SwapErrorRight, SwapperConfig, SwapperDeps } from '../../../types.js';
8
+ import type { BobGatewayMetadata } from '../types.js';
9
+ import type { BobGatewayChainName } from './constants.js';
10
+ export declare const getBobGatewayClient: (config: SwapperConfig) => GatewaySDK;
11
+ export declare const assetIdToBobGatewayToken: (assetId: string) => string;
12
+ export declare const getBobGatewayAffiliates: (affiliateBps: string) => GetQuoteParams['affiliates'];
13
+ export declare const getBobGatewayQuote: ({ config, sellAsset, buyAsset, sellChainName, buyChainName, sender, recipient, amount, affiliateBps, slippageTolerancePercentageDecimal, }: {
14
+ config: SwapperConfig;
15
+ sellAsset: Asset;
16
+ buyAsset: Asset;
17
+ sellChainName: BobGatewayChainName;
18
+ buyChainName: BobGatewayChainName;
19
+ sender: string | undefined;
20
+ recipient: string;
21
+ amount: string;
22
+ affiliateBps: string;
23
+ slippageTolerancePercentageDecimal: string | undefined;
24
+ }) => Promise<Result<GatewayQuoteV2, SwapErrorRight>>;
25
+ export declare const createBobGatewayOrderMetadata: (config: SwapperConfig, gatewayQuote: GatewayQuoteV2) => Promise<Result<BobGatewayMetadata, SwapErrorRight>>;
26
+ export declare const registerBobGatewayTx: ({ config, orderId, txHash, sellAsset, buyAsset, }: {
27
+ config: SwapperConfig;
28
+ orderId: string;
29
+ txHash: string;
30
+ sellAsset: Asset;
31
+ buyAsset: Asset;
32
+ }) => Promise<void>;
33
+ export declare const getBobGatewayQuoteFeeData: (input: GetTradeQuoteInput, { assertGetUtxoChainAdapter, assertGetEvmChainAdapter }: SwapperDeps, orderMetadata: BobGatewayMetadata) => Promise<Result<Omit<QuoteFeeData, 'protocolFees'>, SwapErrorRight>>;
34
+ export declare const getBobGatewayRateNetworkFeeCryptoBaseUnit: (quote: GatewayQuoteV2, sellAsset: Asset, { assertGetEvmChainAdapter, assertGetUtxoChainAdapter }: SwapperDeps) => Promise<string | undefined>;
35
+ export declare const mapBobGatewayOrderStatusToTxStatus: (status: GatewayOrderStatusV2) => TxStatus;
36
+ export declare const parseBobGatewayQuote: (quote: GatewayQuoteV2, buyAsset: Asset, assetsById: AssetsByIdPartial) => {
37
+ buyAmountBeforeFeesCryptoBaseUnit: string;
38
+ buyAmountAfterFeesCryptoBaseUnit: string;
39
+ protocolFees: Partial<Record<AssetId, import("../../../types.js").ProtocolFee>>;
40
+ estimatedExecutionTimeMs: number | undefined;
41
+ };
42
+ export declare const getBobGatewayAllowanceContract: (quote: GatewayQuoteV2, sellAsset: Asset) => string;
43
+ export declare const assertValidTrade: ({ sellAsset, buyAsset, }: {
44
+ sellAsset: Asset;
45
+ buyAsset: Asset;
46
+ }) => Result<{
47
+ sellChainName: BobGatewayChainName;
48
+ buyChainName: BobGatewayChainName;
49
+ }, SwapErrorRight>;