@xswap-link/sdk 0.1.4 → 0.2.1

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.
@@ -27,11 +27,30 @@ jobs:
27
27
 
28
28
  - run: pnpm install
29
29
  - run: pnpm install react@18.2.0 react-dom@18.2.0 @types/react@18.2.0 @types/react-dom@18.2.0
30
+
30
31
  - name: Create Release Pull Request or Publish
31
32
  id: changesets
32
- uses: changesets/action@v1
33
+ uses: xswap-link/changesets-action@v1
33
34
  with:
34
35
  publish: pnpm run release
35
36
  env:
36
37
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
38
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
39
+
40
+ - name: Get latest created release info
41
+ if: steps.changesets.outputs.published == 'true'
42
+ id: latest_release_info
43
+ uses: jossef/action-latest-release-info@v1.2.1
44
+ env:
45
+ GITHUB_TOKEN: ${{ github.token }}
46
+
47
+ - name: Publish index.css
48
+ if: steps.changesets.outputs.published == 'true'
49
+ uses: actions/upload-release-asset@v1
50
+ env:
51
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52
+ with:
53
+ upload_url: ${{ steps.latest_release_info.outputs.upload_url }}
54
+ asset_path: ./dist/index.css
55
+ asset_name: index.css
56
+ asset_content_type: text/plain
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @xswap-link/xswap-sdk
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 0f722ce: tx monitoring integration update
8
+
9
+ ## 0.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 3fe79fb: publish index.css while releasing new version and append css element automatically so an integrator doesn't have to
14
+
3
15
  ## 0.1.4
4
16
 
5
17
  ### Patch Changes
package/dist/index.css CHANGED
@@ -756,6 +756,9 @@ video {
756
756
  .bg-\[rgba\(15\,15\,15\,1\)\] {
757
757
  background-color: rgba(15, 15, 15, 1);
758
758
  }
759
+ .bg-\[rgba\(2\,2\,2\,1\)\] {
760
+ background-color: rgba(2, 2, 2, 1);
761
+ }
759
762
  .bg-\[rgba\(255\,255\,255\,0\.1\)\] {
760
763
  background-color: rgba(255, 255, 255, 0.1);
761
764
  }
@@ -800,8 +803,8 @@ video {
800
803
  --tw-gradient-to: rgb(54 129 198 / 0) var(--tw-gradient-to-position);
801
804
  --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to);
802
805
  }
803
- .from-\[rgba\(54\,129\,198\,0\.1\)\] {
804
- --tw-gradient-from: rgba(54,129,198,0.1) var(--tw-gradient-from-position);
806
+ .from-\[rgba\(54\,129\,198\,0\.2\)\] {
807
+ --tw-gradient-from: rgba(54,129,198,0.2) var(--tw-gradient-from-position);
805
808
  --tw-gradient-to: rgba(54, 129, 198, 0) var(--tw-gradient-to-position);
806
809
  --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to);
807
810
  }
@@ -810,8 +813,8 @@ video {
810
813
  --tw-gradient-to: rgba(54, 129, 198, 0) var(--tw-gradient-to-position);
811
814
  --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to);
812
815
  }
813
- .from-\[rgba\(76\,175\,80\,0\.1\)\] {
814
- --tw-gradient-from: rgba(76,175,80,0.1) var(--tw-gradient-from-position);
816
+ .from-\[rgba\(76\,175\,80\,0\.2\)\] {
817
+ --tw-gradient-from: rgba(76,175,80,0.2) var(--tw-gradient-from-position);
815
818
  --tw-gradient-to: rgba(76, 175, 80, 0) var(--tw-gradient-to-position);
816
819
  --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to);
817
820
  }
@@ -823,14 +826,14 @@ video {
823
826
  .to-\[\#2b4a9d\] {
824
827
  --tw-gradient-to: #2b4a9d var(--tw-gradient-to-position);
825
828
  }
826
- .to-\[rgba\(43\,74\,157\,0\.1\)\] {
827
- --tw-gradient-to: rgba(43,74,157,0.1) var(--tw-gradient-to-position);
829
+ .to-\[rgba\(43\,74\,157\,0\.2\)\] {
830
+ --tw-gradient-to: rgba(43,74,157,0.2) var(--tw-gradient-to-position);
828
831
  }
829
832
  .to-\[rgba\(43\,74\,157\,1\)\] {
830
833
  --tw-gradient-to: rgba(43,74,157,1) var(--tw-gradient-to-position);
831
834
  }
832
- .to-\[rgba\(46\,125\,50\,0\.1\)\] {
833
- --tw-gradient-to: rgba(46,125,50,0.1) var(--tw-gradient-to-position);
835
+ .to-\[rgba\(46\,125\,50\,0\.2\)\] {
836
+ --tw-gradient-to: rgba(46,125,50,0.2) var(--tw-gradient-to-position);
834
837
  }
835
838
  .to-x_blue_dark {
836
839
  --tw-gradient-to: rgba(43,74,157,1) var(--tw-gradient-to-position);
package/dist/index.d.mts CHANGED
@@ -291,6 +291,11 @@ declare const ROUTE_TIMEOUT_MS = 5000;
291
291
  declare const MINIMUM_DISPLAYED_TOKEN_AMOUNT = 0.0001;
292
292
  declare const DEFAULT_SOURCE_CHAIN_ID = "1";
293
293
  declare const CCIP_EXPLORER = "https://ccip.chain.link/";
294
+ declare const TX_RECEIPT_STATUS_LIFETIME = 10000;
295
+ declare const MSG_SENT_EVENT_SIG = "MessageSent(bytes32,uint64,address,bytes,address,uint256,uint256,address,uint256)";
296
+ declare const MSG_SENT_EVENT_ABI: string[];
297
+ declare const MSG_RECEIVED_EVENT_SIG = "MessageReceived(bytes32,uint64,address,bytes,address,uint256)";
298
+ declare const MSG_RECEIVED_EVENT_ABI: string[];
294
299
 
295
300
  declare const BatchQueryAbi: ({
296
301
  inputs: {
@@ -389,8 +394,9 @@ declare function getPrices(payload: GetPricesPayload): Promise<TokenPrices>;
389
394
 
390
395
  declare const generateStakingCalls: ({ token, staking, stakingAbi, stakingFunName, stakingFunParams, }: GenerateStakingCallsParams) => ContractCall[];
391
396
 
397
+ declare const monitorTransactionStatus: (txChainId: string, txHash: string) => Promise<void>;
398
+
392
399
  declare const getSwapTx: ({ dstChain, dstToken, customContractCalls, desc, }: GetSwapTxPayload) => Promise<Transactions>;
393
- declare const monitorTransactionStatus: (srcChainId: number, txHash: string) => Promise<void>;
394
400
 
395
401
  declare const IERC20: ethers.utils.Interface;
396
402
  declare const getBalanceOf: (wallet: string, token: string, rpcUrl: string) => Promise<string>;
@@ -424,4 +430,4 @@ declare const deepMergeObjects: (obj1: Record<string, any>, obj2: Record<string,
424
430
  declare const chunkArray: (array: any[], chunkSize: number) => any[][];
425
431
  declare const getDate: (blockTimestamp: number) => string;
426
432
 
427
- export { ADDRESSES, type AddReferralPayload, type Addresses, Alert, BALANCES_CHUNK_SIZE, BatchQueryAbi, type BridgeToken, CCIP_EXPLORER, type Chain, type CoinTypeAddress, type CollectFees, type ContractCall, ContractName, type Contracts, DEFAULT_ECOSYSTEM, DEFAULT_SOURCE_CHAIN_ID, DELIVERY_TIME, ERC20Abi, EXPRESS_DELIVERY_TIME, Ecosystem, Environment, type GenerateStakingCallsParams, type GetPricesPayload, type GetRoutePayload, type GetSwapTxPayload, type HistoryTransaction, IERC20, MINIMUM_DISPLAYED_TOKEN_AMOUNT, type MonitoredTransaction, NUMBER_INPUT_REGEX, type Prices, type Protocol, ROUTE_TIMEOUT_MS, type Referral, type ReferralInfo, type Route, SLIPPAGE_PRESETS, Skeleton, type Token, type TokenBalances, type TokenPrices, type Transaction, type TransactionHistory, type TransactionStatus, type Transactions, type TxConfigFormData, type TxConfigFormProps, TxHistoryButton, Web3Environment, XSwapCallType, type XSwapConfig, type XSwapFee, type XSwapFees, addTransactionToRenderedTransactions, chunkArray, deepMergeObjects, findPlaceholderIndex, generateApproveTxData, generateRandomBigNumber, generateStakingCalls, generateUniqueRandomBigNumber, getBalanceOf, getBalances, getBridgeTokens, getChainData, getChains, getDate, getHistory, getPrices, getRoute, getSwapTx, getTokens, monitorTransactionStatus, openTxConfigForm, removeTransactionFromRenderedTransactions, renderTxHistoryButtons, replaceNull, safeBigNumberFrom, shortAddress, updateTransactionDoneInRenderedTransactions, weiToHumanReadable };
433
+ export { ADDRESSES, type AddReferralPayload, type Addresses, Alert, BALANCES_CHUNK_SIZE, BatchQueryAbi, type BridgeToken, CCIP_EXPLORER, type Chain, type CoinTypeAddress, type CollectFees, type ContractCall, ContractName, type Contracts, DEFAULT_ECOSYSTEM, DEFAULT_SOURCE_CHAIN_ID, DELIVERY_TIME, ERC20Abi, EXPRESS_DELIVERY_TIME, Ecosystem, Environment, type GenerateStakingCallsParams, type GetPricesPayload, type GetRoutePayload, type GetSwapTxPayload, type HistoryTransaction, IERC20, MINIMUM_DISPLAYED_TOKEN_AMOUNT, MSG_RECEIVED_EVENT_ABI, MSG_RECEIVED_EVENT_SIG, MSG_SENT_EVENT_ABI, MSG_SENT_EVENT_SIG, type MonitoredTransaction, NUMBER_INPUT_REGEX, type Prices, type Protocol, ROUTE_TIMEOUT_MS, type Referral, type ReferralInfo, type Route, SLIPPAGE_PRESETS, Skeleton, TX_RECEIPT_STATUS_LIFETIME, type Token, type TokenBalances, type TokenPrices, type Transaction, type TransactionHistory, type TransactionStatus, type Transactions, type TxConfigFormData, type TxConfigFormProps, TxHistoryButton, Web3Environment, XSwapCallType, type XSwapConfig, type XSwapFee, type XSwapFees, addTransactionToRenderedTransactions, chunkArray, deepMergeObjects, findPlaceholderIndex, generateApproveTxData, generateRandomBigNumber, generateStakingCalls, generateUniqueRandomBigNumber, getBalanceOf, getBalances, getBridgeTokens, getChainData, getChains, getDate, getHistory, getPrices, getRoute, getSwapTx, getTokens, monitorTransactionStatus, openTxConfigForm, removeTransactionFromRenderedTransactions, renderTxHistoryButtons, replaceNull, safeBigNumberFrom, shortAddress, updateTransactionDoneInRenderedTransactions, weiToHumanReadable };
package/dist/index.d.ts CHANGED
@@ -291,6 +291,11 @@ declare const ROUTE_TIMEOUT_MS = 5000;
291
291
  declare const MINIMUM_DISPLAYED_TOKEN_AMOUNT = 0.0001;
292
292
  declare const DEFAULT_SOURCE_CHAIN_ID = "1";
293
293
  declare const CCIP_EXPLORER = "https://ccip.chain.link/";
294
+ declare const TX_RECEIPT_STATUS_LIFETIME = 10000;
295
+ declare const MSG_SENT_EVENT_SIG = "MessageSent(bytes32,uint64,address,bytes,address,uint256,uint256,address,uint256)";
296
+ declare const MSG_SENT_EVENT_ABI: string[];
297
+ declare const MSG_RECEIVED_EVENT_SIG = "MessageReceived(bytes32,uint64,address,bytes,address,uint256)";
298
+ declare const MSG_RECEIVED_EVENT_ABI: string[];
294
299
 
295
300
  declare const BatchQueryAbi: ({
296
301
  inputs: {
@@ -389,8 +394,9 @@ declare function getPrices(payload: GetPricesPayload): Promise<TokenPrices>;
389
394
 
390
395
  declare const generateStakingCalls: ({ token, staking, stakingAbi, stakingFunName, stakingFunParams, }: GenerateStakingCallsParams) => ContractCall[];
391
396
 
397
+ declare const monitorTransactionStatus: (txChainId: string, txHash: string) => Promise<void>;
398
+
392
399
  declare const getSwapTx: ({ dstChain, dstToken, customContractCalls, desc, }: GetSwapTxPayload) => Promise<Transactions>;
393
- declare const monitorTransactionStatus: (srcChainId: number, txHash: string) => Promise<void>;
394
400
 
395
401
  declare const IERC20: ethers.utils.Interface;
396
402
  declare const getBalanceOf: (wallet: string, token: string, rpcUrl: string) => Promise<string>;
@@ -424,4 +430,4 @@ declare const deepMergeObjects: (obj1: Record<string, any>, obj2: Record<string,
424
430
  declare const chunkArray: (array: any[], chunkSize: number) => any[][];
425
431
  declare const getDate: (blockTimestamp: number) => string;
426
432
 
427
- export { ADDRESSES, type AddReferralPayload, type Addresses, Alert, BALANCES_CHUNK_SIZE, BatchQueryAbi, type BridgeToken, CCIP_EXPLORER, type Chain, type CoinTypeAddress, type CollectFees, type ContractCall, ContractName, type Contracts, DEFAULT_ECOSYSTEM, DEFAULT_SOURCE_CHAIN_ID, DELIVERY_TIME, ERC20Abi, EXPRESS_DELIVERY_TIME, Ecosystem, Environment, type GenerateStakingCallsParams, type GetPricesPayload, type GetRoutePayload, type GetSwapTxPayload, type HistoryTransaction, IERC20, MINIMUM_DISPLAYED_TOKEN_AMOUNT, type MonitoredTransaction, NUMBER_INPUT_REGEX, type Prices, type Protocol, ROUTE_TIMEOUT_MS, type Referral, type ReferralInfo, type Route, SLIPPAGE_PRESETS, Skeleton, type Token, type TokenBalances, type TokenPrices, type Transaction, type TransactionHistory, type TransactionStatus, type Transactions, type TxConfigFormData, type TxConfigFormProps, TxHistoryButton, Web3Environment, XSwapCallType, type XSwapConfig, type XSwapFee, type XSwapFees, addTransactionToRenderedTransactions, chunkArray, deepMergeObjects, findPlaceholderIndex, generateApproveTxData, generateRandomBigNumber, generateStakingCalls, generateUniqueRandomBigNumber, getBalanceOf, getBalances, getBridgeTokens, getChainData, getChains, getDate, getHistory, getPrices, getRoute, getSwapTx, getTokens, monitorTransactionStatus, openTxConfigForm, removeTransactionFromRenderedTransactions, renderTxHistoryButtons, replaceNull, safeBigNumberFrom, shortAddress, updateTransactionDoneInRenderedTransactions, weiToHumanReadable };
433
+ export { ADDRESSES, type AddReferralPayload, type Addresses, Alert, BALANCES_CHUNK_SIZE, BatchQueryAbi, type BridgeToken, CCIP_EXPLORER, type Chain, type CoinTypeAddress, type CollectFees, type ContractCall, ContractName, type Contracts, DEFAULT_ECOSYSTEM, DEFAULT_SOURCE_CHAIN_ID, DELIVERY_TIME, ERC20Abi, EXPRESS_DELIVERY_TIME, Ecosystem, Environment, type GenerateStakingCallsParams, type GetPricesPayload, type GetRoutePayload, type GetSwapTxPayload, type HistoryTransaction, IERC20, MINIMUM_DISPLAYED_TOKEN_AMOUNT, MSG_RECEIVED_EVENT_ABI, MSG_RECEIVED_EVENT_SIG, MSG_SENT_EVENT_ABI, MSG_SENT_EVENT_SIG, type MonitoredTransaction, NUMBER_INPUT_REGEX, type Prices, type Protocol, ROUTE_TIMEOUT_MS, type Referral, type ReferralInfo, type Route, SLIPPAGE_PRESETS, Skeleton, TX_RECEIPT_STATUS_LIFETIME, type Token, type TokenBalances, type TokenPrices, type Transaction, type TransactionHistory, type TransactionStatus, type Transactions, type TxConfigFormData, type TxConfigFormProps, TxHistoryButton, Web3Environment, XSwapCallType, type XSwapConfig, type XSwapFee, type XSwapFees, addTransactionToRenderedTransactions, chunkArray, deepMergeObjects, findPlaceholderIndex, generateApproveTxData, generateRandomBigNumber, generateStakingCalls, generateUniqueRandomBigNumber, getBalanceOf, getBalances, getBridgeTokens, getChainData, getChains, getDate, getHistory, getPrices, getRoute, getSwapTx, getTokens, monitorTransactionStatus, openTxConfigForm, removeTransactionFromRenderedTransactions, renderTxHistoryButtons, replaceNull, safeBigNumberFrom, shortAddress, updateTransactionDoneInRenderedTransactions, weiToHumanReadable };
package/dist/index.js CHANGED
@@ -45,10 +45,15 @@ __export(src_exports, {
45
45
  Environment: () => Environment,
46
46
  IERC20: () => IERC20,
47
47
  MINIMUM_DISPLAYED_TOKEN_AMOUNT: () => MINIMUM_DISPLAYED_TOKEN_AMOUNT,
48
+ MSG_RECEIVED_EVENT_ABI: () => MSG_RECEIVED_EVENT_ABI,
49
+ MSG_RECEIVED_EVENT_SIG: () => MSG_RECEIVED_EVENT_SIG,
50
+ MSG_SENT_EVENT_ABI: () => MSG_SENT_EVENT_ABI,
51
+ MSG_SENT_EVENT_SIG: () => MSG_SENT_EVENT_SIG,
48
52
  NUMBER_INPUT_REGEX: () => NUMBER_INPUT_REGEX,
49
53
  ROUTE_TIMEOUT_MS: () => ROUTE_TIMEOUT_MS,
50
54
  SLIPPAGE_PRESETS: () => SLIPPAGE_PRESETS,
51
55
  Skeleton: () => Skeleton,
56
+ TX_RECEIPT_STATUS_LIFETIME: () => TX_RECEIPT_STATUS_LIFETIME,
52
57
  TxHistoryButton: () => TxHistoryButton,
53
58
  Web3Environment: () => Web3Environment,
54
59
  XSwapCallType: () => XSwapCallType,
@@ -649,6 +654,15 @@ var ROUTE_TIMEOUT_MS = 5e3;
649
654
  var MINIMUM_DISPLAYED_TOKEN_AMOUNT = 1e-4;
650
655
  var DEFAULT_SOURCE_CHAIN_ID = "1";
651
656
  var CCIP_EXPLORER = "https://ccip.chain.link/";
657
+ var TX_RECEIPT_STATUS_LIFETIME = 1e4;
658
+ var MSG_SENT_EVENT_SIG = "MessageSent(bytes32,uint64,address,bytes,address,uint256,uint256,address,uint256)";
659
+ var MSG_SENT_EVENT_ABI = [
660
+ "event MessageSent(bytes32 indexed messageId, uint64 indexed destinationChainSelector, address indexed sender, bytes data, address token, uint256 tokenAmount, uint256 valueForInstantCcipRecieve, address transferedToken, uint256 transferedTokenAmount)"
661
+ ];
662
+ var MSG_RECEIVED_EVENT_SIG = "MessageReceived(bytes32,uint64,address,bytes,address,uint256)";
663
+ var MSG_RECEIVED_EVENT_ABI = [
664
+ "event MessageReceived(bytes32 indexed messageId, uint64 indexed sourceChainSelector, address indexed sender, bytes data, address token, uint256 tokenAmount)"
665
+ ];
652
666
 
653
667
  // src/utils/contracts.ts
654
668
  var IERC20 = new import_ethers2.ethers.utils.Interface(ERC20Abi);
@@ -855,91 +869,49 @@ var generateStakingCalls = ({
855
869
  return [stakingApproveCall, stakingCall];
856
870
  };
857
871
 
858
- // src/services/integrations/transactions.ts
872
+ // src/services/integrations/monitoring.ts
859
873
  var import_ethers4 = require("ethers");
860
- var getSwapTx = async ({
861
- dstChain,
862
- dstToken,
863
- customContractCalls = [],
864
- desc
865
- }) => {
866
- const supportedChains = (await getChains()).filter(
867
- ({ web3Environment, swapSupported }) => web3Environment === "mainnet" /* MAINNET */ && swapSupported
868
- );
869
- validateSwapTxData(supportedChains, dstChain, dstToken);
870
- const route = await openTxConfigForm({
871
- dstChainId: dstChain,
872
- dstTokenAddr: dstToken,
873
- customContractCalls,
874
- desc,
875
- supportedChains
876
- });
877
- return route.transactions;
878
- };
879
- var validateSwapTxData = (supportedChains, dstChain, dstToken) => {
880
- const supportedDstChain = supportedChains.find(
881
- ({ chainId }) => chainId === dstChain
882
- );
883
- if (!supportedDstChain) {
884
- throw new Error(`Provided chain '${dstChain}' is not supported`);
885
- }
886
- if (!supportedDstChain.tokens.some(({ address }) => address === dstToken)) {
887
- throw new Error(`Provided token '${dstToken}' is not supported`);
888
- }
889
- };
890
- var monitorTransactionStatus = async (srcChainId, txHash) => {
891
- const txReceipt = await getTxReceipt(srcChainId, txHash);
892
- if (!txReceipt) {
893
- throw new Error(
894
- `No transaction found for chain ${srcChainId} tx ${txHash}`
895
- );
896
- }
874
+ var import_async_retry = __toESM(require("async-retry"));
875
+ var monitorTransactionStatus = async (txChainId, txHash) => {
876
+ const txReceipt = await getTxReceipt(txChainId, txHash);
897
877
  const supportedChains = (await getChains()).filter(
898
878
  ({ web3Environment, swapSupported }) => web3Environment === "mainnet" /* MAINNET */ && swapSupported
899
879
  );
900
- const messageSentEventSignature = "MessageSent(bytes32,uint64,address,bytes,address,uint256,uint256,address,uint256)";
901
- const messageSentEventAbi = [
902
- "event MessageSent(bytes32 indexed messageId, uint64 indexed destinationChainSelector, address indexed sender, bytes data, address token, uint256 tokenAmount, uint256 valueForInstantCcipRecieve, address transferedToken, uint256 transferedTokenAmount)"
903
- ];
904
- const messageReceivedEventSignature = "MessageReceived(bytes32,uint64,address,bytes,address,uint256)";
905
- const messageReceivedEventAbi = [
906
- "event MessageReceived(bytes32 indexed messageId, uint64 indexed sourceChainSelector, address indexed sender, bytes data, address token, uint256 tokenAmount)"
907
- ];
908
880
  const messageSentEvent = txReceipt.logs?.find((log) => {
909
- return log.topics[0] === import_ethers4.ethers.utils.id(messageSentEventSignature);
881
+ return log.topics[0] === import_ethers4.ethers.utils.id(MSG_SENT_EVENT_SIG);
910
882
  });
911
883
  if (!messageSentEvent) {
912
884
  throw new Error(
913
- `No transaction event found for chain ${srcChainId} tx ${txHash}`
885
+ `No transaction event found for chain ${txChainId} tx ${txHash}`
914
886
  );
915
887
  }
916
888
  const messageId = messageSentEvent?.topics[1];
917
- const iface = new import_ethers4.ethers.utils.Interface(messageSentEventAbi);
889
+ const iface = new import_ethers4.ethers.utils.Interface(MSG_SENT_EVENT_ABI);
918
890
  const decodedMessageSentEvent = iface.parseLog(messageSentEvent);
919
891
  if (!decodedMessageSentEvent) {
920
892
  throw new Error(
921
- `No transaction event arguments found for chain ${srcChainId} tx ${txHash}`
893
+ `No transaction event arguments found for chain ${txChainId} tx ${txHash}`
922
894
  );
923
895
  }
924
896
  const srcChain = supportedChains.find(
925
- (chain) => chain.chainId === srcChainId.toString()
897
+ (chain) => chain.chainId === txChainId.toString()
926
898
  );
927
899
  const srcToken = srcChain?.tokens.find(
928
900
  (token) => token.address === decodedMessageSentEvent.args?.token.toString()
929
901
  );
930
- const targetChain = supportedChains.find(
902
+ const dstChain = supportedChains.find(
931
903
  (chain) => chain.ccipChainId === decodedMessageSentEvent.args?.destinationChainSelector?.toString()
932
904
  );
933
- const toChainId = targetChain?.chainId;
934
- if (!toChainId) {
905
+ const dstChainId = dstChain?.chainId;
906
+ if (!dstChainId) {
935
907
  throw new Error(`Unknown destination chain!`);
936
908
  }
937
909
  const transaction = {
938
910
  txHash,
939
911
  fromChain: srcChain?.displayName,
940
912
  fromChainImage: srcChain?.image,
941
- toChain: targetChain.displayName,
942
- toChainImage: targetChain.image,
913
+ toChain: dstChain.displayName,
914
+ toChainImage: dstChain.image,
943
915
  fromToken: srcToken?.symbol,
944
916
  fromTokenImage: srcToken?.image,
945
917
  fromAmount: weiToHumanReadable({
@@ -952,41 +924,83 @@ var monitorTransactionStatus = async (srcChainId, txHash) => {
952
924
  };
953
925
  addTransactionToRenderedTransactions(transaction);
954
926
  renderTxHistoryButtons();
955
- const xSwapRouterOnDestinationAddress = ADDRESSES[toChainId]?.XSwapRouter;
927
+ const xSwapRouterOnDestinationAddress = ADDRESSES[dstChainId]?.XSwapRouter;
956
928
  if (!xSwapRouterOnDestinationAddress) {
957
929
  throw new Error(`Unknown destination XSwapRouter!`);
958
930
  }
959
931
  const xSwapRouterOnDestination = new import_ethers4.ethers.Contract(
960
932
  xSwapRouterOnDestinationAddress,
961
- messageReceivedEventAbi,
933
+ MSG_RECEIVED_EVENT_ABI,
962
934
  import_ethers4.ethers.getDefaultProvider(
963
- supportedChains.find((chain) => chain.chainId === toChainId)?.publicRpcUrls[0]
935
+ supportedChains.find((chain) => chain.chainId === dstChainId)?.publicRpcUrls[0]
964
936
  )
965
937
  );
966
- const eventFilter = {
938
+ const msgReceivedEventFilter = {
967
939
  address: xSwapRouterOnDestinationAddress,
968
- topics: [import_ethers4.ethers.utils.id(messageReceivedEventSignature), messageId]
940
+ topics: [import_ethers4.ethers.utils.id(MSG_RECEIVED_EVENT_SIG), messageId]
969
941
  };
970
942
  const onSuccess = async () => {
971
943
  updateTransactionDoneInRenderedTransactions(txHash);
972
944
  renderTxHistoryButtons();
973
- await new Promise((resolve) => setTimeout(() => resolve(true), 5e3));
945
+ await new Promise(
946
+ (resolve) => setTimeout(() => resolve(true), TX_RECEIPT_STATUS_LIFETIME)
947
+ );
974
948
  removeTransactionFromRenderedTransactions(txHash);
975
949
  renderTxHistoryButtons();
976
950
  };
977
- xSwapRouterOnDestination.once(eventFilter, () => onSuccess());
951
+ xSwapRouterOnDestination.once(msgReceivedEventFilter, () => onSuccess());
978
952
  };
979
953
  var getTxReceipt = async (txChainId, txHash) => {
980
- const chains = await getChains();
981
- const chain = chains.find((chain2) => chain2.chainId === txChainId.toString());
982
- const provider = new import_ethers4.ethers.providers.JsonRpcProvider(
983
- chain?.publicRpcUrls[0]
984
- );
985
954
  try {
986
- return await provider.getTransactionReceipt(txHash);
987
- } catch (error) {
988
- console.error("Error fetching transaction receipt:", error);
989
- return null;
955
+ const chain = (await getChains()).find(
956
+ (chain2) => chain2.chainId === txChainId
957
+ );
958
+ const provider = new import_ethers4.ethers.providers.JsonRpcProvider(
959
+ chain?.publicRpcUrls[0]
960
+ );
961
+ return await (0, import_async_retry.default)(async () => {
962
+ const txReceipt = await provider.getTransactionReceipt(txHash);
963
+ if (!txReceipt) {
964
+ throw new Error(`Couldn't fetch tx receipt`);
965
+ }
966
+ return txReceipt;
967
+ });
968
+ } catch (e) {
969
+ throw new Error(
970
+ `Couldn't fetch tx ${txHash} receipt on chain ${txChainId}`
971
+ );
972
+ }
973
+ };
974
+
975
+ // src/services/integrations/transactions.ts
976
+ var getSwapTx = async ({
977
+ dstChain,
978
+ dstToken,
979
+ customContractCalls = [],
980
+ desc
981
+ }) => {
982
+ const supportedChains = (await getChains()).filter(
983
+ ({ web3Environment, swapSupported }) => web3Environment === "mainnet" /* MAINNET */ && swapSupported
984
+ );
985
+ validateSwapTxData(supportedChains, dstChain, dstToken);
986
+ const route = await openTxConfigForm({
987
+ dstChainId: dstChain,
988
+ dstTokenAddr: dstToken,
989
+ customContractCalls,
990
+ desc,
991
+ supportedChains
992
+ });
993
+ return route.transactions;
994
+ };
995
+ var validateSwapTxData = (supportedChains, dstChain, dstToken) => {
996
+ const supportedDstChain = supportedChains.find(
997
+ ({ chainId }) => chainId === dstChain
998
+ );
999
+ if (!supportedDstChain) {
1000
+ throw new Error(`Provided chain '${dstChain}' is not supported`);
1001
+ }
1002
+ if (!supportedDstChain.tokens.some(({ address }) => address === dstToken)) {
1003
+ throw new Error(`Provided token '${dstToken}' is not supported`);
990
1004
  }
991
1005
  };
992
1006
 
@@ -995,14 +1009,12 @@ var import_react = require("react");
995
1009
  var useDebounce = (value, delay) => {
996
1010
  const timeoutRef = (0, import_react.useRef)(null);
997
1011
  (0, import_react.useEffect)(() => {
998
- if (timeoutRef.current)
999
- clearTimeout(timeoutRef.current);
1012
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
1000
1013
  timeoutRef.current = setTimeout(() => {
1001
1014
  setValue(value);
1002
1015
  }, delay);
1003
1016
  return () => {
1004
- if (timeoutRef.current)
1005
- clearTimeout(timeoutRef.current);
1017
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
1006
1018
  };
1007
1019
  }, [value, delay]);
1008
1020
  const [debouncedValue, setValue] = (0, import_react.useState)(value);
@@ -1575,8 +1587,7 @@ var History = ({ signer, supportedChains }) => {
1575
1587
  continue;
1576
1588
  }
1577
1589
  let status;
1578
- if (entry.failed)
1579
- status = "REVERTED";
1590
+ if (entry.failed) status = "REVERTED";
1580
1591
  if (!!entry.target) {
1581
1592
  status = "DONE";
1582
1593
  } else {
@@ -1607,8 +1618,7 @@ var History = ({ signer, supportedChains }) => {
1607
1618
  }
1608
1619
  }, [signer, getHistory]);
1609
1620
  (0, import_react3.useEffect)(() => {
1610
- if (!historyLoadedOnce)
1611
- fetchHistory();
1621
+ if (!historyLoadedOnce) fetchHistory();
1612
1622
  const timer = setInterval(() => {
1613
1623
  fetchHistory();
1614
1624
  }, 6e4);
@@ -2092,10 +2102,8 @@ var import_bignumber3 = __toESM(require("bignumber.js"));
2092
2102
  var import_jsx_runtime33 = require("react/jsx-runtime");
2093
2103
  var BalanceComponent = ({ srcToken, balances }) => {
2094
2104
  const balanceText = (0, import_react8.useMemo)(() => {
2095
- if (!balances || !srcToken)
2096
- return "0";
2097
- if (balances[srcToken.address]?.toString() === "0")
2098
- return "0";
2105
+ if (!balances || !srcToken) return "0";
2106
+ if (balances[srcToken.address]?.toString() === "0") return "0";
2099
2107
  const fullHumanReadable = weiToHumanReadable({
2100
2108
  amount: balances[srcToken.address]?.toString() || "0",
2101
2109
  decimals: srcToken.decimals,
@@ -2179,8 +2187,7 @@ var SwapPanel = ({
2179
2187
  className: "p-0 border-none outline-none bg-transparent text-2xl overflow-ellipsis",
2180
2188
  value: amount,
2181
2189
  onChange: (e) => {
2182
- if (e.target.value === ".")
2183
- return;
2190
+ if (e.target.value === ".") return;
2184
2191
  if (NUMBER_INPUT_REGEX.test(e.target.value)) {
2185
2192
  setAmount(e.target.value.replace(/,/g, "."));
2186
2193
  }
@@ -2446,8 +2453,7 @@ var Form = ({
2446
2453
  }, [srcChain, signer]);
2447
2454
  const handleSubmit = (event) => {
2448
2455
  event.preventDefault();
2449
- if (route)
2450
- onSubmit(route);
2456
+ if (route) onSubmit(route);
2451
2457
  };
2452
2458
  const handleSwitchChain = async () => {
2453
2459
  await switchChainAsync({ chainId: Number(srcChain?.chainId) });
@@ -2531,6 +2537,9 @@ var Form = ({
2531
2537
  );
2532
2538
  };
2533
2539
 
2540
+ // package.json
2541
+ var version = "0.2.1";
2542
+
2534
2543
  // src/components/TxConfigForm/index.tsx
2535
2544
  var import_jsx_runtime39 = require("react/jsx-runtime");
2536
2545
  var TxConfigForm = ({
@@ -2598,7 +2607,7 @@ var openTxConfigForm = async ({
2598
2607
  }) => {
2599
2608
  try {
2600
2609
  return await new Promise((resolve) => {
2601
- txConfigFormRoot.render(
2610
+ xswapRoot.render(
2602
2611
  /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
2603
2612
  TxConfigForm,
2604
2613
  {
@@ -2609,10 +2618,10 @@ var openTxConfigForm = async ({
2609
2618
  supportedChains,
2610
2619
  onSubmit: (route) => {
2611
2620
  resolve(route);
2612
- txConfigFormRoot.render("");
2621
+ xswapRoot.render("");
2613
2622
  },
2614
2623
  onClose: () => {
2615
- txConfigFormRoot.render("");
2624
+ xswapRoot.render("");
2616
2625
  }
2617
2626
  }
2618
2627
  )
@@ -2622,12 +2631,17 @@ var openTxConfigForm = async ({
2622
2631
  throw new Error(`XSwap component error, ${err}`);
2623
2632
  }
2624
2633
  };
2625
- var txConfigFormRoot;
2634
+ var xswapRoot;
2626
2635
  if (typeof document !== "undefined") {
2627
- const xswapElement = document.createElement("div");
2628
- xswapElement.setAttribute("id", "xswap-modal");
2629
- document.body.appendChild(xswapElement);
2630
- txConfigFormRoot = (0, import_client.createRoot)(xswapElement);
2636
+ const xswapStyleElement = document.createElement("link");
2637
+ xswapStyleElement.rel = "stylesheet";
2638
+ xswapStyleElement.type = "text/css";
2639
+ xswapStyleElement.href = `${xswap_config_default.apiUrl}/sdk/css?data={"version": "${version}"}`;
2640
+ document.head.appendChild(xswapStyleElement);
2641
+ const xswapModalElement = document.createElement("div");
2642
+ xswapModalElement.setAttribute("id", "xswap-modal");
2643
+ document.body.appendChild(xswapModalElement);
2644
+ xswapRoot = (0, import_client.createRoot)(xswapModalElement);
2631
2645
  }
2632
2646
 
2633
2647
  // src/components/TxHistoryButton/index.tsx
@@ -2648,11 +2662,19 @@ var TxHistoryButton = ({ transaction }) => {
2648
2662
  explorer
2649
2663
  } = transaction;
2650
2664
  const [isWide, setIsWide] = (0, import_react12.useState)(false);
2665
+ const background = (0, import_react12.useMemo)(
2666
+ () => isDone ? "bg-[rgba(2,2,2,1)] bg-gradient-to-r from-[rgba(76,175,80,0.2)] to-[rgba(46,125,50,0.2)]" : "bg-[rgba(2,2,2,1)] bg-gradient-to-r from-[rgba(54,129,198,0.2)] to-[rgba(43,74,157,0.2)]",
2667
+ [isDone]
2668
+ );
2669
+ const border = (0, import_react12.useMemo)(
2670
+ () => isDone ? "border border-solid border-x_green_dark" : "border border-solid border-x_blue_dark",
2671
+ [isDone]
2672
+ );
2651
2673
  return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex gap-2", onClick: () => setIsWide((x) => !x), children: [
2652
2674
  isWide && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(
2653
2675
  "div",
2654
2676
  {
2655
- className: `flex items-center min-w-60 sm:w-[520px] text-white h-14 px-4 text-sm gap-3 rounded-xl bg-gradient-to-r ${isDone ? "from-[rgba(76,175,80,0.1)] to-[rgba(46,125,50,0.1)] border border-solid border-x_green_dark" : "from-[rgba(54,129,198,0.1)] to-[rgba(43,74,157,0.1)] border border-solid border-x_blue_dark"}`,
2677
+ className: `flex items-center min-w-60 sm:w-[520px] text-white h-14 px-4 text-sm gap-3 rounded-xl ${background} ${border}`,
2656
2678
  children: [
2657
2679
  /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex justify-between flex-col gap-2 sm:gap-5 sm:flex-row w-full", children: [
2658
2680
  /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex items-center gap-2", children: [
@@ -2700,8 +2722,7 @@ var TxHistoryButton = ({ transaction }) => {
2700
2722
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
2701
2723
  "div",
2702
2724
  {
2703
- className: `text-white rounded-xl cursor-pointer bg-gradient-to-r
2704
- ${isDone ? "from-[rgba(76,175,80,0.1)] to-[rgba(46,125,50,0.1)] border border-solid border-x_green_dark" : "from-[rgba(54,129,198,0.1)] to-[rgba(43,74,157,0.1)] border border-solid border-x_blue_dark"}`,
2725
+ className: `text-white rounded-xl cursor-pointer ${background} ${border}`,
2705
2726
  children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex gap-2 items-center h-14 w-20 justify-center", children: [
2706
2727
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(ArrowLeftIcon, {}),
2707
2728
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "relative flex items-center justify-center w-9 h-9", children: isDone ? /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "text-x_green w-5 h-5", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(CheckIcon, {}) }) : /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_jsx_runtime40.Fragment, { children: [
@@ -2767,10 +2788,15 @@ var Skeleton = ({ width, height }) => {
2767
2788
  Environment,
2768
2789
  IERC20,
2769
2790
  MINIMUM_DISPLAYED_TOKEN_AMOUNT,
2791
+ MSG_RECEIVED_EVENT_ABI,
2792
+ MSG_RECEIVED_EVENT_SIG,
2793
+ MSG_SENT_EVENT_ABI,
2794
+ MSG_SENT_EVENT_SIG,
2770
2795
  NUMBER_INPUT_REGEX,
2771
2796
  ROUTE_TIMEOUT_MS,
2772
2797
  SLIPPAGE_PRESETS,
2773
2798
  Skeleton,
2799
+ TX_RECEIPT_STATUS_LIFETIME,
2774
2800
  TxHistoryButton,
2775
2801
  Web3Environment,
2776
2802
  XSwapCallType,