@allbridge/bridge-core-sdk 0.4.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,6 +35,7 @@ Provides an easy integration with the Allbridge Core Bridge for DApps in the bro
35
35
  ```bash
36
36
  $ npm install @allbridge/bridge-core-sdk
37
37
  ```
38
+
38
39
  ## How to use
39
40
 
40
41
  ### 1. Initialize SDK instance
@@ -55,18 +56,22 @@ const {bridgeAddress, tokens, chainId, name} = supportedChains[ChainSymbol.ETH];
55
56
  const usdtOnEthTokenInfo = tokens.find(tokensInfo => tokensInfo.symbol === 'USDT');
56
57
  ```
57
58
 
58
- ### 3.1 Approve the transfer of tokens
59
+ ### 3.1 Approve the transfer of tokens
59
60
 
60
- Before sending tokens the bridge has to be authorized to use user's tokens. This is done by calling the `evmApprove` method on SDK instance.
61
+ Before sending tokens the bridge has to be authorized to use user's tokens. This is done by calling the `approve` method
62
+ on SDK instance.
61
63
 
62
64
  ```js
63
- const response = await sdk.evmApprove(web3, {
65
+ const response = await sdk.approve(web3, {
64
66
  tokenAddress: tokenAddress,
65
67
  owner: senderAddress,
66
- spender: bridgeAddress,
68
+ spender: poolAddress,
67
69
  });
68
70
  ```
69
71
 
72
+ **TIP:** To interact with the **Tron** blockchain, use: </br>
73
+ ```tronWeb``` instead of ```web3```
74
+
70
75
  ### 3.2 Send Tokens
71
76
 
72
77
  Initiate the transfer of tokens with `send` method on SDK instance.
@@ -83,6 +88,7 @@ await sdk.send(web3, {
83
88
  ```
84
89
 
85
90
  ### Full example
91
+
86
92
  Swap BUSD on BSC chain to USDT on TRX chain
87
93
 
88
94
  ```js
@@ -117,11 +123,11 @@ async function runExample() {
117
123
  const trxChain = chains[ChainSymbol.TRX];
118
124
  const usdtTokenInfo = trxChain.tokens.find(tokenInfo => tokenInfo.symbol === 'USDT');
119
125
 
120
- // authorize the bridge to transfer tokens from sender's address
121
- await sdk.evmApprove(web3, {
126
+ // authorize a transfer of tokens from sender's address
127
+ await sdk.approve(web3, {
122
128
  tokenAddress: busdTokenInfo.tokenAddress,
123
129
  owner: fromAddress,
124
- spender: bscChain.bridgeAddress,
130
+ spender: busdTokenInfo.poolAddress,
125
131
  });
126
132
 
127
133
  // initiate transfer
@@ -141,9 +147,18 @@ runExample();
141
147
 
142
148
  ## Other operations
143
149
 
144
- ### Calculating amount of tokens to be received after fee
150
+ ### Get information about sent transaction
151
+
152
+ SDK method `getTransferStatus` can be used to get information about tokens transfer.
153
+
154
+ ```js
155
+ const transferStatus = await sdk.getTransferStatus(chainSymbol, txId);
156
+ ```
157
+
158
+ ### Calculating amount of tokens to be received after fee
145
159
 
146
- SDK method `getAmountToBeReceived` can be used to calculate the amount of tokens the receiving party will get after applying the bridging fee.
160
+ SDK method `getAmountToBeReceived` can be used to calculate the amount of tokens the receiving party will get after
161
+ applying the bridging fee.
147
162
 
148
163
  ```js
149
164
  const amountToBeReceived = sdk.getAmountToBeReceived(
@@ -155,7 +170,8 @@ const amountToBeReceived = sdk.getAmountToBeReceived(
155
170
 
156
171
  ### Calculating amount of tokens to send
157
172
 
158
- SDK method `getAmountToSend` can be used to calculate the amount of tokens to send based on the required amount of tokens the receiving party should get.
173
+ SDK method `getAmountToSend` can be used to calculate the amount of tokens to send based on the required amount of
174
+ tokens the receiving party should get.
159
175
 
160
176
  ```js
161
177
  const amountToSend = sdk.getAmountToSend(
@@ -167,7 +183,8 @@ const amountToSend = sdk.getAmountToSend(
167
183
 
168
184
  ### Getting the amount of gas fee
169
185
 
170
- SDK method `getTxCost` can be used to fetch information about the amount of gas fee required to complete the transfer on the destination chain. Gas fee is paid during the [send](#32-send-tokens) operation in the source chain currency.
186
+ SDK method `getTxCost` can be used to fetch information about the amount of gas fee required to complete the transfer on
187
+ the destination chain. Gas fee is paid during the [send](#32-send-tokens) operation in the source chain currency.
171
188
 
172
189
  ```js
173
190
  const weiValue = await sdk.getTxCost(
@@ -179,7 +196,8 @@ const weiValue = await sdk.getTxCost(
179
196
 
180
197
  ### Getting the average transfer time
181
198
 
182
- SDK method `getAverageTransferTime` can be used to get the average time in ms it takes to complete a transfer for a given combination of tokens and messenger.
199
+ SDK method `getAverageTransferTime` can be used to get the average time in ms it takes to complete a transfer for a
200
+ given combination of tokens and messenger.
183
201
 
184
202
  ```js
185
203
  const transferTimeMs = sdk.getAverageTransferTime(
@@ -191,4 +209,5 @@ const transferTimeMs = sdk.getAverageTransferTime(
191
209
 
192
210
  ## Semver
193
211
 
194
- Until bridge-core-sdk reaches a `1.0.0` release, breaking changes will be released with a new minor version. For example `0.3.1`, and `0.3.4` will have the same API, but `0.4.0` will have breaking changes.
212
+ Until bridge-core-sdk reaches a `1.0.0` release, breaking changes will be released with a new minor version. For
213
+ example `0.3.1`, and `0.3.4` will have the same API, but `0.4.0` will have breaking changes.
@@ -12353,13 +12353,13 @@ var require_lib14 = __commonJS({
12353
12353
  return TransactionOrderForkEvent2;
12354
12354
  }(ForkEvent);
12355
12355
  exports.TransactionOrderForkEvent = TransactionOrderForkEvent;
12356
- var Provider = function() {
12357
- function Provider2() {
12356
+ var Provider2 = function() {
12357
+ function Provider3() {
12358
12358
  var _newTarget = this.constructor;
12359
- logger.checkAbstract(_newTarget, Provider2);
12359
+ logger.checkAbstract(_newTarget, Provider3);
12360
12360
  (0, properties_1.defineReadOnly)(this, "_isProvider", true);
12361
12361
  }
12362
- Provider2.prototype.getFeeData = function() {
12362
+ Provider3.prototype.getFeeData = function() {
12363
12363
  return __awaiter(this, void 0, void 0, function() {
12364
12364
  var _a, block, gasPrice, lastBaseFeePerGas, maxFeePerGas, maxPriorityFeePerGas;
12365
12365
  return __generator(this, function(_b) {
@@ -12384,18 +12384,18 @@ var require_lib14 = __commonJS({
12384
12384
  });
12385
12385
  });
12386
12386
  };
12387
- Provider2.prototype.addListener = function(eventName, listener) {
12387
+ Provider3.prototype.addListener = function(eventName, listener) {
12388
12388
  return this.on(eventName, listener);
12389
12389
  };
12390
- Provider2.prototype.removeListener = function(eventName, listener) {
12390
+ Provider3.prototype.removeListener = function(eventName, listener) {
12391
12391
  return this.off(eventName, listener);
12392
12392
  };
12393
- Provider2.isProvider = function(value) {
12393
+ Provider3.isProvider = function(value) {
12394
12394
  return !!(value && value._isProvider);
12395
12395
  };
12396
- return Provider2;
12396
+ return Provider3;
12397
12397
  }();
12398
- exports.Provider = Provider;
12398
+ exports.Provider = Provider2;
12399
12399
  }
12400
12400
  });
12401
12401
 
@@ -50377,46 +50377,6 @@ P.valueOf = function() {
50377
50377
  };
50378
50378
  var Big = _Big_();
50379
50379
 
50380
- // src/chains/index.ts
50381
- var ChainSymbol = /* @__PURE__ */ ((ChainSymbol3) => {
50382
- ChainSymbol3["GRL"] = "GRL";
50383
- ChainSymbol3["BSC"] = "BSC";
50384
- ChainSymbol3["ETH"] = "ETH";
50385
- ChainSymbol3["SOL"] = "SOL";
50386
- ChainSymbol3["TRX"] = "TRX";
50387
- return ChainSymbol3;
50388
- })(ChainSymbol || {});
50389
- var chainProperties = {
50390
- ["GRL" /* GRL */]: {
50391
- chainSymbol: "GRL" /* GRL */,
50392
- chainId: "0x5",
50393
- name: "Goerli",
50394
- chainType: "EVM" /* EVM */
50395
- },
50396
- ["BSC" /* BSC */]: {
50397
- chainSymbol: "BSC" /* BSC */,
50398
- chainId: "0x38",
50399
- name: "BNB Chain",
50400
- chainType: "EVM" /* EVM */
50401
- },
50402
- ["ETH" /* ETH */]: {
50403
- chainSymbol: "ETH" /* ETH */,
50404
- chainId: "0x1",
50405
- name: "Ethereum",
50406
- chainType: "EVM" /* EVM */
50407
- },
50408
- ["SOL" /* SOL */]: {
50409
- chainSymbol: "SOL" /* SOL */,
50410
- name: "Solana",
50411
- chainType: "SOLANA" /* SOLANA */
50412
- },
50413
- ["TRX" /* TRX */]: {
50414
- chainSymbol: "TRX" /* TRX */,
50415
- name: "Tron",
50416
- chainType: "TRX" /* TRX */
50417
- }
50418
- };
50419
-
50420
50380
  // src/bridge/evm/index.ts
50421
50381
  var import_bn = __toESM(require_bn());
50422
50382
 
@@ -50646,8 +50606,65 @@ var abi_default = [
50646
50606
  }
50647
50607
  ];
50648
50608
 
50649
- // src/bridge/evm/index.ts
50609
+ // src/chains/index.ts
50610
+ var ChainSymbol = /* @__PURE__ */ ((ChainSymbol3) => {
50611
+ ChainSymbol3["GRL"] = "GRL";
50612
+ ChainSymbol3["BSC"] = "BSC";
50613
+ ChainSymbol3["ETH"] = "ETH";
50614
+ ChainSymbol3["SOL"] = "SOL";
50615
+ ChainSymbol3["TRX"] = "TRX";
50616
+ return ChainSymbol3;
50617
+ })(ChainSymbol || {});
50618
+ var ChainType = /* @__PURE__ */ ((ChainType2) => {
50619
+ ChainType2["EVM"] = "EVM";
50620
+ ChainType2["SOLANA"] = "SOLANA";
50621
+ ChainType2["TRX"] = "TRX";
50622
+ return ChainType2;
50623
+ })(ChainType || {});
50624
+ var chainProperties = {
50625
+ ["GRL" /* GRL */]: {
50626
+ chainSymbol: "GRL" /* GRL */,
50627
+ chainId: "0x5",
50628
+ name: "Goerli",
50629
+ chainType: "EVM" /* EVM */
50630
+ },
50631
+ ["BSC" /* BSC */]: {
50632
+ chainSymbol: "BSC" /* BSC */,
50633
+ chainId: "0x38",
50634
+ name: "BNB Chain",
50635
+ chainType: "EVM" /* EVM */
50636
+ },
50637
+ ["ETH" /* ETH */]: {
50638
+ chainSymbol: "ETH" /* ETH */,
50639
+ chainId: "0x1",
50640
+ name: "Ethereum",
50641
+ chainType: "EVM" /* EVM */
50642
+ },
50643
+ ["SOL" /* SOL */]: {
50644
+ chainSymbol: "SOL" /* SOL */,
50645
+ name: "Solana",
50646
+ chainType: "SOLANA" /* SOLANA */
50647
+ },
50648
+ ["TRX" /* TRX */]: {
50649
+ chainSymbol: "TRX" /* TRX */,
50650
+ name: "Tron",
50651
+ chainType: "TRX" /* TRX */
50652
+ }
50653
+ };
50654
+
50655
+ // src/bridge/models/bridge.model.ts
50656
+ var Bridge = class {
50657
+ };
50658
+ var ApprovalBridge = class extends Bridge {
50659
+ async isNeededApprove(approveData) {
50660
+ const allowance = await this.getAllowance(approveData);
50661
+ return Big(allowance).eq(0);
50662
+ }
50663
+ };
50664
+
50665
+ // src/bridge/utils.ts
50650
50666
  var import_randombytes = __toESM(require_browser());
50667
+ var TronWebLib = __toESM(require_TronWeb_node());
50651
50668
 
50652
50669
  // src/utils/calculation/constants.ts
50653
50670
  var SYSTEM_PRECISION = 3;
@@ -50751,18 +50768,7 @@ function getY(x, a, d) {
50751
50768
  return commonPartBig.times(x).plus(sqrtBig).div(dividerBig).round(0, 0).plus(1);
50752
50769
  }
50753
50770
 
50754
- // src/bridge/models/bridge.model.ts
50755
- var Bridge = class {
50756
- };
50757
- var ApprovalBridge = class extends Bridge {
50758
- async isNeededApprove(approveData) {
50759
- const allowance = await this.getAllowance(approveData);
50760
- return Big(allowance).eq(0);
50761
- }
50762
- };
50763
-
50764
50771
  // src/bridge/utils.ts
50765
- var TronWebLib = __toESM(require_TronWeb_node());
50766
50772
  function formatAddress(address, from, to) {
50767
50773
  let buffer;
50768
50774
  switch (from) {
@@ -50795,7 +50801,7 @@ function formatAddress(address, from, to) {
50795
50801
  );
50796
50802
  }
50797
50803
  case "TRX" /* TRX */: {
50798
- return buffer.toString();
50804
+ return buffer.toJSON().data;
50799
50805
  }
50800
50806
  default: {
50801
50807
  throw new Error(
@@ -50828,6 +50834,84 @@ function bufferToSize(buffer, size) {
50828
50834
  buffer.copy(result, size - buffer.length);
50829
50835
  return result;
50830
50836
  }
50837
+ function getDecimalsByContractAddress(chainDetailsMap, chainSymbol, contractAddress) {
50838
+ const sourceTokenInfoWithChainDetails = chainDetailsMap[chainSymbol].tokens.find(
50839
+ (value) => value.tokenAddress.toUpperCase() === contractAddress.toUpperCase()
50840
+ );
50841
+ if (!sourceTokenInfoWithChainDetails) {
50842
+ throw new Error("Cannot find source token info");
50843
+ }
50844
+ return sourceTokenInfoWithChainDetails.decimals;
50845
+ }
50846
+ function getNonce() {
50847
+ return (0, import_randombytes.default)(32);
50848
+ }
50849
+ async function prepareTxSendParams(bridgeChainType, params, api) {
50850
+ const txSendParams = {};
50851
+ let fromChainId;
50852
+ let toChainType;
50853
+ if (isSendParamsWithChainSymbol(params)) {
50854
+ const chainDetailsMap = (await api.getTokensInfo()).chainDetailsMap();
50855
+ fromChainId = chainDetailsMap[params.fromChainSymbol].allbridgeChainId;
50856
+ toChainType = chainProperties[params.toChainSymbol].chainType;
50857
+ txSendParams.contractAddress = chainDetailsMap[params.fromChainSymbol].bridgeAddress;
50858
+ txSendParams.fromTokenAddress = params.fromTokenAddress;
50859
+ txSendParams.toChainId = chainDetailsMap[params.toChainSymbol].allbridgeChainId;
50860
+ txSendParams.toTokenAddress = params.toTokenAddress;
50861
+ txSendParams.amount = convertFloatAmountToInt(
50862
+ params.amount,
50863
+ getDecimalsByContractAddress(
50864
+ chainDetailsMap,
50865
+ params.fromChainSymbol,
50866
+ txSendParams.fromTokenAddress
50867
+ )
50868
+ ).toFixed();
50869
+ } else {
50870
+ fromChainId = params.sourceChainToken.allbridgeChainId;
50871
+ toChainType = chainProperties[params.destinationChainToken.chainSymbol].chainType;
50872
+ txSendParams.contractAddress = params.sourceChainToken.bridgeAddress;
50873
+ txSendParams.fromTokenAddress = params.sourceChainToken.tokenAddress;
50874
+ txSendParams.toChainId = params.destinationChainToken.allbridgeChainId;
50875
+ txSendParams.toTokenAddress = params.destinationChainToken.tokenAddress;
50876
+ txSendParams.amount = convertFloatAmountToInt(
50877
+ params.amount,
50878
+ params.sourceChainToken.decimals
50879
+ ).toFixed();
50880
+ }
50881
+ txSendParams.messenger = params.messenger;
50882
+ txSendParams.fromAccountAddress = params.fromAccountAddress;
50883
+ let { fee } = params;
50884
+ if (fee == null) {
50885
+ fee = await api.getReceiveTransactionCost({
50886
+ sourceChainId: fromChainId,
50887
+ destinationChainId: txSendParams.toChainId,
50888
+ messenger: txSendParams.messenger
50889
+ });
50890
+ }
50891
+ txSendParams.fee = fee;
50892
+ txSendParams.fromTokenAddress = formatAddress(
50893
+ txSendParams.fromTokenAddress,
50894
+ bridgeChainType,
50895
+ bridgeChainType
50896
+ );
50897
+ txSendParams.toAccountAddress = formatAddress(
50898
+ params.toAccountAddress,
50899
+ toChainType,
50900
+ bridgeChainType
50901
+ );
50902
+ txSendParams.toTokenAddress = formatAddress(
50903
+ txSendParams.toTokenAddress,
50904
+ toChainType,
50905
+ bridgeChainType
50906
+ );
50907
+ return txSendParams;
50908
+ }
50909
+ function isSendParamsWithChainSymbol(params) {
50910
+ return params.fromChainSymbol !== void 0;
50911
+ }
50912
+ function sleep(ms) {
50913
+ return new Promise((resolve) => setTimeout(() => resolve(), ms));
50914
+ }
50831
50915
 
50832
50916
  // src/bridge/evm/abi/Abi.json
50833
50917
  var Abi_default = [
@@ -51528,73 +51612,13 @@ var Abi_default = [
51528
51612
  // src/bridge/evm/index.ts
51529
51613
  var MAX_AMOUNT = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
51530
51614
  var EvmBridge = class extends ApprovalBridge {
51531
- constructor(api, web3) {
51615
+ constructor(web3) {
51532
51616
  super();
51533
- this.api = api;
51534
51617
  this.web3 = web3;
51618
+ this.chainType = "EVM" /* EVM */;
51535
51619
  }
51536
- getTokenBalance(data) {
51537
- return this.getContract(abi_default, data.tokenAddress).methods.balanceOf(data.account).call();
51538
- }
51539
- async send(params) {
51540
- const txSendParams = {};
51541
- let fromChainId;
51542
- let toChainType;
51543
- if (BridgeService.isSendParamsWithChainSymbol(params)) {
51544
- const chainDetailsMap = (await this.api.getTokensInfo()).chainDetailsMap();
51545
- fromChainId = chainDetailsMap[params.fromChainSymbol].allbridgeChainId;
51546
- toChainType = chainProperties[params.toChainSymbol].chainType;
51547
- txSendParams.contractAddress = chainDetailsMap[params.fromChainSymbol].bridgeAddress;
51548
- txSendParams.fromTokenAddress = params.fromTokenAddress;
51549
- txSendParams.toChainId = chainDetailsMap[params.toChainSymbol].allbridgeChainId;
51550
- txSendParams.toTokenAddress = params.toTokenAddress;
51551
- txSendParams.amount = convertFloatAmountToInt(
51552
- params.amount,
51553
- this.getDecimalsByContractAddress(
51554
- chainDetailsMap,
51555
- params.fromChainSymbol,
51556
- txSendParams.fromTokenAddress
51557
- )
51558
- ).toFixed();
51559
- } else {
51560
- fromChainId = params.sourceChainToken.allbridgeChainId;
51561
- toChainType = chainProperties[params.destinationChainToken.chainSymbol].chainType;
51562
- txSendParams.contractAddress = params.sourceChainToken.bridgeAddress;
51563
- txSendParams.fromTokenAddress = params.sourceChainToken.tokenAddress;
51564
- txSendParams.toChainId = params.destinationChainToken.allbridgeChainId;
51565
- txSendParams.toTokenAddress = params.destinationChainToken.tokenAddress;
51566
- txSendParams.amount = convertFloatAmountToInt(
51567
- params.amount,
51568
- params.sourceChainToken.decimals
51569
- ).toFixed();
51570
- }
51571
- txSendParams.messenger = params.messenger;
51572
- txSendParams.fromAccountAddress = params.fromAccountAddress;
51573
- let { fee } = params;
51574
- if (fee == null) {
51575
- fee = await this.api.getReceiveTransactionCost({
51576
- sourceChainId: fromChainId,
51577
- destinationChainId: txSendParams.toChainId,
51578
- messenger: txSendParams.messenger
51579
- });
51580
- }
51581
- txSendParams.fee = fee;
51582
- txSendParams.fromTokenAddress = formatAddress(
51583
- txSendParams.fromTokenAddress,
51584
- "EVM" /* EVM */,
51585
- "EVM" /* EVM */
51586
- );
51587
- txSendParams.toAccountAddress = formatAddress(
51588
- params.toAccountAddress,
51589
- toChainType,
51590
- "EVM" /* EVM */
51591
- );
51592
- txSendParams.toTokenAddress = formatAddress(
51593
- txSendParams.toTokenAddress,
51594
- toChainType,
51595
- "EVM" /* EVM */
51596
- );
51597
- return this.sendTx(txSendParams);
51620
+ async getTokenBalance(data) {
51621
+ return await this.getContract(abi_default, data.tokenAddress).methods.balanceOf(data.account).call();
51598
51622
  }
51599
51623
  async sendTx(params) {
51600
51624
  const {
@@ -51609,7 +51633,7 @@ var EvmBridge = class extends ApprovalBridge {
51609
51633
  fee
51610
51634
  } = params;
51611
51635
  const bridgeContract = this.getBridgeContract(contractAddress);
51612
- const nonce = new import_bn.default(EvmBridge.getNonce());
51636
+ const nonce = new import_bn.default(getNonce());
51613
51637
  const swapAndBridgeMethod = bridgeContract.methods.swapAndBridge(
51614
51638
  fromTokenAddress,
51615
51639
  amount,
@@ -51655,17 +51679,82 @@ var EvmBridge = class extends ApprovalBridge {
51655
51679
  getBridgeContract(contractAddress) {
51656
51680
  return this.getContract(Abi_default, contractAddress);
51657
51681
  }
51658
- static getNonce() {
51659
- return (0, import_randombytes.default)(32);
51682
+ };
51683
+
51684
+ // src/bridge/trx/index.ts
51685
+ var MAX_AMOUNT2 = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
51686
+ var TronBridge = class extends ApprovalBridge {
51687
+ constructor(tronWeb) {
51688
+ super();
51689
+ this.tronWeb = tronWeb;
51690
+ this.chainType = "TRX" /* TRX */;
51660
51691
  }
51661
- getDecimalsByContractAddress(chainDetailsMap, chainSymbol, contractAddress) {
51662
- const sourceTokenInfoWithChainDetails = chainDetailsMap[chainSymbol].tokens.find(
51663
- (value) => value.tokenAddress.toUpperCase() === contractAddress.toUpperCase()
51692
+ async getTokenBalance(data) {
51693
+ const contract = await this.getContract(data.tokenAddress);
51694
+ const balance = await contract.balanceOf(data.account).call();
51695
+ return balance.toString();
51696
+ }
51697
+ async sendTx(params) {
51698
+ const {
51699
+ amount,
51700
+ contractAddress,
51701
+ fromTokenAddress,
51702
+ toChainId,
51703
+ toAccountAddress,
51704
+ toTokenAddress,
51705
+ messenger,
51706
+ fee
51707
+ } = params;
51708
+ const bridgeContract = await this.getContract(contractAddress);
51709
+ const nonce = getNonce().toJSON().data;
51710
+ const swapAndBridgeMethod = bridgeContract.methods.swapAndBridge(
51711
+ fromTokenAddress,
51712
+ amount,
51713
+ toAccountAddress,
51714
+ toChainId,
51715
+ toTokenAddress,
51716
+ nonce,
51717
+ messenger
51664
51718
  );
51665
- if (!sourceTokenInfoWithChainDetails) {
51666
- throw new Error("Cannot find source token info");
51719
+ const transactionHash = await swapAndBridgeMethod.send({
51720
+ callValue: fee
51721
+ });
51722
+ await this.verifyTx(transactionHash);
51723
+ return { txId: transactionHash };
51724
+ }
51725
+ async approve(approveData) {
51726
+ const { tokenAddress, spender, owner } = approveData;
51727
+ const tokenContract = await this.getContract(tokenAddress);
51728
+ const transactionHash = await tokenContract.approve(spender, MAX_AMOUNT2).send({ from: owner });
51729
+ await this.verifyTx(transactionHash);
51730
+ return { txId: transactionHash };
51731
+ }
51732
+ async getAllowance(approveData) {
51733
+ const { tokenAddress, spender, owner } = approveData;
51734
+ const tokenContract = await this.getContract(tokenAddress);
51735
+ const allowance = await tokenContract.allowance(owner, spender).call();
51736
+ return allowance.toString();
51737
+ }
51738
+ getContract(contractAddress) {
51739
+ return this.tronWeb.contract().at(contractAddress);
51740
+ }
51741
+ async verifyTx(txId, timeout = 1e4) {
51742
+ const start = Date.now();
51743
+ while (true) {
51744
+ if (Date.now() - start > timeout) {
51745
+ throw new Error("Transaction not found");
51746
+ }
51747
+ const result = await this.tronWeb.trx.getUnconfirmedTransactionInfo(txId);
51748
+ if (!result?.receipt) {
51749
+ await sleep(2e3);
51750
+ continue;
51751
+ }
51752
+ if (result.receipt.result === "SUCCESS") {
51753
+ return result;
51754
+ } else {
51755
+ throw new Error(`Transaction status is ${result.receipt.result}`);
51756
+ }
51667
51757
  }
51668
- return sourceTokenInfoWithChainDetails.decimals;
51669
51758
  }
51670
51759
  };
51671
51760
 
@@ -51674,39 +51763,27 @@ var BridgeService = class {
51674
51763
  constructor(api) {
51675
51764
  this.api = api;
51676
51765
  }
51677
- async evmApprove(web3, approveData) {
51678
- const evmBridge = new EvmBridge(this.api, web3);
51679
- return evmBridge.approve(approveData);
51766
+ async approve(provider, approveData) {
51767
+ return this.getBridge(provider).approve(approveData);
51768
+ }
51769
+ async send(provider, params) {
51770
+ const bridge = this.getBridge(provider);
51771
+ const txSendParams = await prepareTxSendParams(
51772
+ bridge.chainType,
51773
+ params,
51774
+ this.api
51775
+ );
51776
+ return bridge.sendTx(txSendParams);
51680
51777
  }
51681
- async send(web3, params) {
51682
- let chainType;
51683
- if (BridgeService.isSendParamsWithChainSymbol(params)) {
51684
- chainType = chainProperties[params.fromChainSymbol].chainType;
51778
+ getBridge(provider) {
51779
+ if (this.isTronWeb(provider)) {
51780
+ return new TronBridge(provider);
51685
51781
  } else {
51686
- chainType = chainProperties[params.sourceChainToken.chainSymbol].chainType;
51687
- }
51688
- switch (chainType) {
51689
- case "EVM" /* EVM */: {
51690
- const evmBridge = new EvmBridge(this.api, web3);
51691
- return evmBridge.send(params);
51692
- }
51693
- case "SOLANA" /* SOLANA */: {
51694
- throw new Error(
51695
- `Error in send method: method not implemented for SOLANA`
51696
- );
51697
- }
51698
- case "TRX" /* TRX */: {
51699
- throw new Error(`Error in send method: method not implemented for TRX`);
51700
- }
51701
- default: {
51702
- throw new Error(
51703
- `Error in send method: unknown chain type ${chainType}, or method not implemented`
51704
- );
51705
- }
51782
+ return new EvmBridge(provider);
51706
51783
  }
51707
51784
  }
51708
- static isSendParamsWithChainSymbol(params) {
51709
- return params.fromChainSymbol !== void 0;
51785
+ isTronWeb(params) {
51786
+ return params.trx !== void 0;
51710
51787
  }
51711
51788
  };
51712
51789
 
@@ -53625,6 +53702,12 @@ var AllbridgeCoreClient = class {
53625
53702
  const { data } = await this.api.get("/token-info");
53626
53703
  return new TokensInfo(mapChainDetailsMapFromDTO(data));
53627
53704
  }
53705
+ async getTransferStatus(chainSymbol, txId) {
53706
+ const { data } = await this.api.get(
53707
+ `/chain/${chainSymbol}/${txId}`
53708
+ );
53709
+ return data;
53710
+ }
53628
53711
  async getReceiveTransactionCost(args) {
53629
53712
  const { data } = await this.api.post(
53630
53713
  "/receive-fee",
@@ -53661,11 +53744,14 @@ var AllbridgeCoreSdk = class {
53661
53744
  async getTokensInfo() {
53662
53745
  return this.api.getTokensInfo();
53663
53746
  }
53664
- async evmApprove(web3, approveData) {
53665
- return this.bridgeService.evmApprove(web3, approveData);
53747
+ async approve(provider, approveData) {
53748
+ return await this.bridgeService.approve(provider, approveData);
53749
+ }
53750
+ async send(provider, params) {
53751
+ return this.bridgeService.send(provider, params);
53666
53752
  }
53667
- async send(web3, params) {
53668
- return this.bridgeService.send(web3, params);
53753
+ async getTransferStatus(chainSymbol, txId) {
53754
+ return this.api.getTransferStatus(chainSymbol, txId);
53669
53755
  }
53670
53756
  calculateFeePercentOnSourceChain(amountFloat, sourceChainToken) {
53671
53757
  const amountInt = convertFloatAmountToInt(
@@ -53777,6 +53863,7 @@ var AllbridgeCoreSdk = class {
53777
53863
  export {
53778
53864
  AllbridgeCoreSdk,
53779
53865
  ChainSymbol,
53866
+ ChainType,
53780
53867
  Messenger,
53781
53868
  TokensInfo,
53782
53869
  production