@allbridge/bridge-core-sdk 3.27.0-alpha.13 → 3.27.0-alpha.15

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 (58) hide show
  1. package/dist/browser/index.js +2 -2
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/cjs/index.js +2 -2
  4. package/dist/cjs/index.js.map +4 -4
  5. package/dist/esm/index.js +2 -2
  6. package/dist/esm/index.js.map +4 -4
  7. package/dist/src/chains/models.d.ts +2 -2
  8. package/dist/src/chains/models.js.map +1 -1
  9. package/dist/src/client/core-api/api-client.js +1 -0
  10. package/dist/src/client/core-api/api-client.js.map +1 -1
  11. package/dist/src/client/core-api/core-api-mapper.js +29 -0
  12. package/dist/src/client/core-api/core-api-mapper.js.map +1 -1
  13. package/dist/src/client/core-api/core-api.model.d.ts +13 -2
  14. package/dist/src/client/core-api/core-api.model.js.map +1 -1
  15. package/dist/src/models/index.d.ts +12 -4
  16. package/dist/src/models/index.js +4 -0
  17. package/dist/src/models/index.js.map +1 -1
  18. package/dist/src/services/bridge/alg/index.js +52 -43
  19. package/dist/src/services/bridge/alg/index.js.map +1 -1
  20. package/dist/src/services/bridge/evm/index.d.ts +1 -0
  21. package/dist/src/services/bridge/evm/index.js +108 -33
  22. package/dist/src/services/bridge/evm/index.js.map +1 -1
  23. package/dist/src/services/bridge/index.d.ts +2 -2
  24. package/dist/src/services/bridge/index.js +10 -4
  25. package/dist/src/services/bridge/index.js.map +1 -1
  26. package/dist/src/services/bridge/models/bridge.model.d.ts +9 -2
  27. package/dist/src/services/bridge/models/bridge.model.js.map +1 -1
  28. package/dist/src/services/bridge/raw-bridge-transaction-builder.js +1 -1
  29. package/dist/src/services/bridge/raw-bridge-transaction-builder.js.map +1 -1
  30. package/dist/src/services/bridge/srb/index.js +36 -28
  31. package/dist/src/services/bridge/srb/index.js.map +1 -1
  32. package/dist/src/services/bridge/stx/index.js +23 -14
  33. package/dist/src/services/bridge/stx/index.js.map +1 -1
  34. package/dist/src/services/bridge/sui/index.js +166 -138
  35. package/dist/src/services/bridge/sui/index.js.map +1 -1
  36. package/dist/src/services/bridge/trx/index.js +98 -70
  37. package/dist/src/services/bridge/trx/index.js.map +1 -1
  38. package/dist/src/services/bridge/utils.js +63 -8
  39. package/dist/src/services/bridge/utils.js.map +1 -1
  40. package/dist/src/services/models/abi/PayerWithAbr.d.ts +203 -0
  41. package/dist/src/services/models/abi/PayerWithAbr.js +266 -0
  42. package/dist/src/services/models/abi/PayerWithAbr.js.map +1 -0
  43. package/dist/src/services/token/index.js +2 -2
  44. package/dist/src/services/token/index.js.map +1 -1
  45. package/dist/src/services/token/models/token.model.d.ts +4 -4
  46. package/dist/src/services/token/models/token.model.js.map +1 -1
  47. package/dist/src/services/token/trx/index.d.ts +2 -1
  48. package/dist/src/services/token/trx/index.js +7 -3
  49. package/dist/src/services/token/trx/index.js.map +1 -1
  50. package/dist/src/tokens-info/tokens-info.model.d.ts +17 -0
  51. package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
  52. package/dist/src/utils/utils.d.ts +2 -0
  53. package/dist/src/utils/utils.js +11 -0
  54. package/dist/src/utils/utils.js.map +1 -1
  55. package/dist/src/version.d.ts +1 -1
  56. package/dist/src/version.js +1 -1
  57. package/dist/src/version.js.map +1 -1
  58. package/package.json +1 -1
@@ -7,9 +7,10 @@ const chain_enums_1 = require("../../../chains/chain.enums");
7
7
  const exceptions_1 = require("../../../exceptions");
8
8
  const index_1 = require("../../../index");
9
9
  const models_1 = require("../../../models");
10
+ const utils_1 = require("../../../utils/utils");
10
11
  const bridge_contract_1 = require("../../models/srb/bridge-contract");
11
12
  const models_2 = require("../models");
12
- const utils_1 = require("../utils");
13
+ const utils_2 = require("../utils");
13
14
  class SrbBridgeService extends models_2.ChainBridgeService {
14
15
  nodeRpcUrlsConfig;
15
16
  params;
@@ -22,7 +23,7 @@ class SrbBridgeService extends models_2.ChainBridgeService {
22
23
  this.api = api;
23
24
  }
24
25
  async buildRawTransactionSend(params) {
25
- const txSendParams = await (0, utils_1.prepareTxSendParams)(this.chainType, params, this.api);
26
+ const txSendParams = await (0, utils_2.prepareTxSendParams)(this.chainType, params, this.api);
26
27
  return await this.buildRawTransactionSendFromParams(txSendParams);
27
28
  }
28
29
  async buildRawTransactionSendFromParams(params) {
@@ -33,36 +34,43 @@ class SrbBridgeService extends models_2.ChainBridgeService {
33
34
  }
34
35
  const contract = this.getContract(bridge_contract_1.BridgeContract, contractAddress, fromAccountAddress);
35
36
  let tx;
36
- if (gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN) {
37
- tx = await contract.swap_and_bridge({
38
- sender: fromAccountAddress,
39
- token: stellar_sdk_1.Address.contract(Buffer.from(fromTokenAddress)).toString(),
40
- amount: BigInt(amount),
41
- recipient: Buffer.from(toAccountAddress),
42
- destination_chain_id: +toChainId,
43
- receive_token: Buffer.from(toTokenAddress),
44
- nonce: (0, utils_1.getNonceBigInt)(),
45
- gas_amount: BigInt(0),
46
- fee_token_amount: BigInt(totalFee),
47
- });
48
- }
49
- else {
50
- tx = await contract.swap_and_bridge({
51
- sender: fromAccountAddress,
52
- token: stellar_sdk_1.Address.contract(Buffer.from(fromTokenAddress)).toString(),
53
- amount: BigInt(amount),
54
- recipient: Buffer.from(toAccountAddress),
55
- destination_chain_id: +toChainId,
56
- receive_token: Buffer.from(toTokenAddress),
57
- nonce: (0, utils_1.getNonceBigInt)(),
58
- gas_amount: BigInt(totalFee),
59
- fee_token_amount: BigInt(0),
60
- });
37
+ switch (gasFeePaymentMethod) {
38
+ case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY:
39
+ tx = await contract.swap_and_bridge({
40
+ sender: fromAccountAddress,
41
+ token: stellar_sdk_1.Address.contract(Buffer.from(fromTokenAddress)).toString(),
42
+ amount: BigInt(amount),
43
+ recipient: Buffer.from(toAccountAddress),
44
+ destination_chain_id: +toChainId,
45
+ receive_token: Buffer.from(toTokenAddress),
46
+ nonce: (0, utils_2.getNonceBigInt)(),
47
+ gas_amount: BigInt(totalFee),
48
+ fee_token_amount: BigInt(0),
49
+ });
50
+ break;
51
+ case models_1.FeePaymentMethod.WITH_STABLECOIN:
52
+ tx = await contract.swap_and_bridge({
53
+ sender: fromAccountAddress,
54
+ token: stellar_sdk_1.Address.contract(Buffer.from(fromTokenAddress)).toString(),
55
+ amount: BigInt(amount),
56
+ recipient: Buffer.from(toAccountAddress),
57
+ destination_chain_id: +toChainId,
58
+ receive_token: Buffer.from(toTokenAddress),
59
+ nonce: (0, utils_2.getNonceBigInt)(),
60
+ gas_amount: BigInt(0),
61
+ fee_token_amount: BigInt(totalFee),
62
+ });
63
+ break;
64
+ case models_1.FeePaymentMethod.WITH_ARB:
65
+ throw new exceptions_1.SdkError("SRB bridge does not support ARB0 payment method");
66
+ default: {
67
+ return (0, utils_1.assertNever)(gasFeePaymentMethod, "Unhandled FeePaymentMethod");
68
+ }
61
69
  }
62
70
  return tx.toXDR();
63
71
  }
64
72
  async buildRawTransactionSwap(params) {
65
- const txSwapParams = (0, utils_1.prepareTxSwapParams)(this.chainType, params);
73
+ const txSwapParams = (0, utils_2.prepareTxSwapParams)(this.chainType, params);
66
74
  return await this.buildRawTransactionSwapFromParams(txSwapParams);
67
75
  }
68
76
  async buildRawTransactionSwapFromParams(params) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/srb/index.ts"],"names":[],"mappings":";;;AAAA,sDAAyD;AACzD,mCAA6B;AAC7B,6DAA0D;AAE1D,oDAA8D;AAC9D,0CAAoE;AACpE,4CAAmD;AAGnD,sEAAkE;AAClE,sCAAyG;AACzG,oCAAoF;AAGpF,MAAa,gBAAiB,SAAQ,2BAAkB;IAI3C;IACA;IACA;IALX,SAAS,GAAkB,iBAAS,CAAC,GAAG,CAAC;IAEzC,YACW,iBAAoC,EACpC,MAA+B,EAC/B,GAAwB;QAEjC,KAAK,EAAE,CAAC;QAJC,sBAAiB,GA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EAAE,kBAAkB,CAAC,CAAC;QACvF,OAAO,CACL,MAAM,QAAQ,CAAC,IAAI,CAAC;YAClB,MAAM,EAAE,kBAAkB;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;YACtB,KAAK,EAAE,qBAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,QAAQ,EAAE;YACjE,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC;YAC1C,SAAS,EAAE,gBAAgB;YAC3B,kBAAkB,EAAE,MAAM,CAAC,oBAAoB,CAAC;SACjD,CAAC,CACH,CAAC,KAAK,EAAE,CAAC;IACZ,CAAC;IAED,6DAA6D;IAC7D,IAAI,CAAC,MAAkB;QACrB,MAAM,IAAI,oCAAuB,EAAE,CAAC;IACtC,CAAC;IAEO,WAAW,CAAI,QAAgD,EAAE,OAAe,EAAE,MAAe;QACvG,MAAM,MAAM,GAA0B;YACpC,SAAS,EAAE,MAAM;YACjB,UAAU,EAAE,OAAO;YACnB,iBAAiB,EAAE,IAAI,CAAC,MAAM,CAAC,wBAAwB;YACvD,MAAM,EAAE,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,yBAAW,CAAC,GAAG,CAAC;SAC9D,CAAC;QACF,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF;AA1GD,4CA0GC","sourcesContent":["import { Address, contract } from \"@stellar/stellar-sdk\";\nimport { Big } from \"big.js\";\nimport { ChainSymbol } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError } from \"../../../exceptions\";\nimport { AllbridgeCoreSdkOptions, ChainType } from \"../../../index\";\nimport { FeePaymentMethod } from \"../../../models\";\nimport { NodeRpcUrlsConfig } from \"../../index\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { BridgeContract } from \"../../models/srb/bridge-contract\";\nimport { ChainBridgeService, SendParams, SwapParams, TxSendParamsSrb, TxSwapParamsSol } from \"../models\";\nimport { getNonceBigInt, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\nimport ContractClientOptions = contract.ClientOptions;\n\nexport class SrbBridgeService extends ChainBridgeService {\n chainType: ChainType.SRB = ChainType.SRB;\n\n constructor(\n readonly nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n readonly params: AllbridgeCoreSdkOptions,\n readonly api: AllbridgeCoreClient\n ) {\n super();\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n return await this.buildRawTransactionSendFromParams(txSendParams);\n }\n\n async buildRawTransactionSendFromParams(params: TxSendParamsSrb): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n fee,\n gasFeePaymentMethod,\n extraGas,\n } = params;\n\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n const contract = this.getContract(BridgeContract, contractAddress, fromAccountAddress);\n let tx;\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n tx = await contract.swap_and_bridge({\n sender: fromAccountAddress,\n token: Address.contract(Buffer.from(fromTokenAddress)).toString(),\n amount: BigInt(amount),\n recipient: Buffer.from(toAccountAddress),\n destination_chain_id: +toChainId,\n receive_token: Buffer.from(toTokenAddress),\n nonce: getNonceBigInt(),\n gas_amount: BigInt(0),\n fee_token_amount: BigInt(totalFee),\n });\n } else {\n tx = await contract.swap_and_bridge({\n sender: fromAccountAddress,\n token: Address.contract(Buffer.from(fromTokenAddress)).toString(),\n amount: BigInt(amount),\n recipient: Buffer.from(toAccountAddress),\n destination_chain_id: +toChainId,\n receive_token: Buffer.from(toTokenAddress),\n nonce: getNonceBigInt(),\n gas_amount: BigInt(totalFee),\n fee_token_amount: BigInt(0),\n });\n }\n return tx.toXDR();\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n return await this.buildRawTransactionSwapFromParams(txSwapParams);\n }\n\n async buildRawTransactionSwapFromParams(params: TxSwapParamsSol): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toAccountAddress,\n toTokenAddress,\n minimumReceiveAmount,\n } = params;\n const contract = this.getContract(BridgeContract, contractAddress, fromAccountAddress);\n return (\n await contract.swap({\n sender: fromAccountAddress,\n amount: BigInt(amount),\n token: Address.contract(Buffer.from(fromTokenAddress)).toBuffer(),\n receive_token: Buffer.from(toTokenAddress),\n recipient: toAccountAddress,\n receive_amount_min: BigInt(minimumReceiveAmount),\n })\n ).toXDR();\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n send(params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n private getContract<T>(contract: new (args: ContractClientOptions) => T, address: string, sender?: string): T {\n const config: ContractClientOptions = {\n publicKey: sender,\n contractId: address,\n networkPassphrase: this.params.sorobanNetworkPassphrase,\n rpcUrl: this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB),\n };\n return new contract(config);\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/srb/index.ts"],"names":[],"mappings":";;;AAAA,sDAAyD;AACzD,mCAA6B;AAC7B,6DAA0D;AAE1D,oDAAwE;AACxE,0CAAoE;AACpE,4CAAmD;AACnD,gDAAmD;AAGnD,sEAAkE;AAClE,sCAAyG;AACzG,oCAAoF;AAGpF,MAAa,gBAAiB,SAAQ,2BAAkB;IAI3C;IACA;IACA;IALX,SAAS,GAAkB,iBAAS,CAAC,GAAG,CAAC;IAEzC,YACW,iBAAoC,EACpC,MAA+B,EAC/B,GAAwB;QAEjC,KAAK,EAAE,CAAC;QAJC,sBAAiB,GAAjB,iBAAiB,CAAmB;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,CAAC,iCAAiC,CAAC,MAAuB;QAC7D,MAAM,EACJ,MAAM,EACN,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,oBAAoB,GACrB,GAAG,MAAM,CAAC;QACX,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,gCAAc,EAAE,eAAe,EAAE,kBAAkB,CAAC,CAAC;QACvF,OAAO,CACL,MAAM,QAAQ,CAAC,IAAI,CAAC;YAClB,MAAM,EAAE,kBAAkB;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;YACtB,KAAK,EAAE,qBAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,QAAQ,EAAE;YACjE,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC;YAC1C,SAAS,EAAE,gBAAgB;YAC3B,kBAAkB,EAAE,MAAM,CAAC,oBAAoB,CAAC;SACjD,CAAC,CACH,CAAC,KAAK,EAAE,CAAC;IACZ,CAAC;IAED,6DAA6D;IAC7D,IAAI,CAAC,MAAkB;QACrB,MAAM,IAAI,oCAAuB,EAAE,CAAC;IACtC,CAAC;IAEO,WAAW,CAAI,QAAgD,EAAE,OAAe,EAAE,MAAe;QACvG,MAAM,MAAM,GAA0B;YACpC,SAAS,EAAE,MAAM;YACjB,UAAU,EAAE,OAAO;YACnB,iBAAiB,EAAE,IAAI,CAAC,MAAM,CAAC,wBAAwB;YACvD,MAAM,EAAE,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,yBAAW,CAAC,GAAG,CAAC;SAC9D,CAAC;QACF,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF;AAnHD,4CAmHC","sourcesContent":["import { Address, contract } from \"@stellar/stellar-sdk\";\nimport { Big } from \"big.js\";\nimport { ChainSymbol } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError, SdkError } from \"../../../exceptions\";\nimport { AllbridgeCoreSdkOptions, ChainType } from \"../../../index\";\nimport { FeePaymentMethod } from \"../../../models\";\nimport { assertNever } from \"../../../utils/utils\";\nimport { NodeRpcUrlsConfig } from \"../../index\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { BridgeContract } from \"../../models/srb/bridge-contract\";\nimport { ChainBridgeService, SendParams, SwapParams, TxSendParamsSrb, TxSwapParamsSol } from \"../models\";\nimport { getNonceBigInt, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\nimport ContractClientOptions = contract.ClientOptions;\n\nexport class SrbBridgeService extends ChainBridgeService {\n chainType: ChainType.SRB = ChainType.SRB;\n\n constructor(\n readonly nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n readonly params: AllbridgeCoreSdkOptions,\n readonly api: AllbridgeCoreClient\n ) {\n super();\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n return await this.buildRawTransactionSendFromParams(txSendParams);\n }\n\n async buildRawTransactionSendFromParams(params: TxSendParamsSrb): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n fee,\n gasFeePaymentMethod,\n extraGas,\n } = params;\n\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n const contract = this.getContract(BridgeContract, contractAddress, fromAccountAddress);\n let tx;\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY:\n tx = await contract.swap_and_bridge({\n sender: fromAccountAddress,\n token: Address.contract(Buffer.from(fromTokenAddress)).toString(),\n amount: BigInt(amount),\n recipient: Buffer.from(toAccountAddress),\n destination_chain_id: +toChainId,\n receive_token: Buffer.from(toTokenAddress),\n nonce: getNonceBigInt(),\n gas_amount: BigInt(totalFee),\n fee_token_amount: BigInt(0),\n });\n break;\n case FeePaymentMethod.WITH_STABLECOIN:\n tx = await contract.swap_and_bridge({\n sender: fromAccountAddress,\n token: Address.contract(Buffer.from(fromTokenAddress)).toString(),\n amount: BigInt(amount),\n recipient: Buffer.from(toAccountAddress),\n destination_chain_id: +toChainId,\n receive_token: Buffer.from(toTokenAddress),\n nonce: getNonceBigInt(),\n gas_amount: BigInt(0),\n fee_token_amount: BigInt(totalFee),\n });\n break;\n case FeePaymentMethod.WITH_ARB:\n throw new SdkError(\"SRB bridge does not support ARB0 payment method\");\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n\n return tx.toXDR();\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n return await this.buildRawTransactionSwapFromParams(txSwapParams);\n }\n\n async buildRawTransactionSwapFromParams(params: TxSwapParamsSol): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toAccountAddress,\n toTokenAddress,\n minimumReceiveAmount,\n } = params;\n const contract = this.getContract(BridgeContract, contractAddress, fromAccountAddress);\n return (\n await contract.swap({\n sender: fromAccountAddress,\n amount: BigInt(amount),\n token: Address.contract(Buffer.from(fromTokenAddress)).toBuffer(),\n receive_token: Buffer.from(toTokenAddress),\n recipient: toAccountAddress,\n receive_amount_min: BigInt(minimumReceiveAmount),\n })\n ).toXDR();\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n send(params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n private getContract<T>(contract: new (args: ContractClientOptions) => T, address: string, sender?: string): T {\n const config: ContractClientOptions = {\n publicKey: sender,\n contractId: address,\n networkPassphrase: this.params.sorobanNetworkPassphrase,\n rpcUrl: this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB),\n };\n return new contract(config);\n }\n}\n"]}
@@ -7,11 +7,12 @@ const transactions_1 = require("@stacks/transactions");
7
7
  const chain_enums_1 = require("../../../chains/chain.enums");
8
8
  const exceptions_1 = require("../../../exceptions");
9
9
  const models_1 = require("../../../models");
10
+ const utils_1 = require("../../../utils/utils");
10
11
  const clarigen_types_1 = require("../../models/stx/clarigen-types");
11
12
  const get_token_name_1 = require("../../utils/stx/get-token-name");
12
13
  const post_conditions_1 = require("../../utils/stx/post-conditions");
13
14
  const models_2 = require("../models");
14
- const utils_1 = require("../utils");
15
+ const utils_2 = require("../utils");
15
16
  class StxBridgeService extends models_2.ChainBridgeService {
16
17
  nodeRpcUrl;
17
18
  params;
@@ -34,7 +35,7 @@ class StxBridgeService extends models_2.ChainBridgeService {
34
35
  throw new exceptions_1.MethodNotSupportedError();
35
36
  }
36
37
  async buildRawTransactionSend(params) {
37
- const txSendParams = await (0, utils_1.prepareTxSendParams)(this.chainType, params, this.api);
38
+ const txSendParams = await (0, utils_2.prepareTxSendParams)(this.chainType, params, this.api);
38
39
  const { contractAddress: bridgeAddress, messenger, toChainId, toAccountAddress, toTokenAddress } = txSendParams;
39
40
  const amount = BigInt(txSendParams.amount);
40
41
  const postFungiblePostCondition = (0, post_conditions_1.getFungiblePostCondition)(amount, "lte", params.fromAccountAddress, params.sourceToken.tokenAddress, (0, get_token_name_1.getTokenName)(params.sourceToken));
@@ -44,18 +45,26 @@ class StxBridgeService extends models_2.ChainBridgeService {
44
45
  if (txSendParams.extraGas) {
45
46
  totalFee = totalFee + BigInt(txSendParams.extraGas);
46
47
  }
47
- const isPayWithStable = txSendParams.gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN;
48
48
  let feeTokenAmount;
49
49
  let feeNativeAmount;
50
- if (isPayWithStable) {
51
- feeTokenAmount = totalFee;
52
- feeNativeAmount = 0n;
53
- }
54
- else {
55
- feeTokenAmount = 0n;
56
- feeNativeAmount = totalFee;
57
- const postUserStxPostCondition = (0, post_conditions_1.getStxPostCondition)(totalFee, "lte", params.fromAccountAddress);
58
- postConditions.push(postUserStxPostCondition);
50
+ switch (txSendParams.gasFeePaymentMethod) {
51
+ case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY: {
52
+ feeTokenAmount = 0n;
53
+ feeNativeAmount = totalFee;
54
+ const postUserStxPostCondition = (0, post_conditions_1.getStxPostCondition)(totalFee, "lte", params.fromAccountAddress);
55
+ postConditions.push(postUserStxPostCondition);
56
+ break;
57
+ }
58
+ case models_1.FeePaymentMethod.WITH_STABLECOIN: {
59
+ feeTokenAmount = totalFee;
60
+ feeNativeAmount = 0n;
61
+ break;
62
+ }
63
+ case models_1.FeePaymentMethod.WITH_ARB:
64
+ throw new exceptions_1.SdkError("STX bridge does not support ARB0 payment method");
65
+ default: {
66
+ return (0, utils_1.assertNever)(txSendParams.gasFeePaymentMethod, "Unhandled FeePaymentMethod");
67
+ }
59
68
  }
60
69
  const [contractPrincipal] = (0, transactions_1.parseContractId)(bridgeAddress);
61
70
  const bridge = (0, core_1.contractFactory)(clarigen_types_1.stacksContracts.bridge, bridgeAddress);
@@ -68,7 +77,7 @@ class StxBridgeService extends models_2.ChainBridgeService {
68
77
  recipient: Uint8Array.from(toAccountAddress),
69
78
  destinationChainId: toChainId,
70
79
  receiveToken: Uint8Array.from(toTokenAddress),
71
- nonce: Uint8Array.from((0, utils_1.getNonce)()),
80
+ nonce: Uint8Array.from((0, utils_2.getNonce)()),
72
81
  messengerId: messenger,
73
82
  feeNativeAmount: feeNativeAmount,
74
83
  feeTokenAmount: feeTokenAmount,
@@ -90,7 +99,7 @@ class StxBridgeService extends models_2.ChainBridgeService {
90
99
  return transaction.serialize();
91
100
  }
92
101
  async buildRawTransactionSwap(params) {
93
- const txSwapParams = (0, utils_1.prepareTxSwapParams)(this.chainType, params);
102
+ const txSwapParams = (0, utils_2.prepareTxSwapParams)(this.chainType, params);
94
103
  const amount = BigInt(txSwapParams.amount);
95
104
  const minimumReceiveAmount = BigInt(txSwapParams.minimumReceiveAmount);
96
105
  const bridgeAddress = params.sourceToken.bridgeAddress;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/stx/index.ts"],"names":[],"mappings":";;;AAAA,yCAAiE;AACjE,6CAAgD;AAChD,uDAQ8B;AAC9B,6DAAwD;AAExD,oDAA8D;AAE9D,4CAAmD;AAEnD,oEAA+E;AAC/E,mEAA8D;AAC9D,qEAAgG;AAChG,sCAAuE;AACvE,oCAA8E;AAE9E,MAAa,gBAAiB,SAAQ,2BAAkB;IAM7C;IACA;IACA;IAPT,SAAS,GAAkB,uBAAS,CAAC,GAAG,CAAC;IAEjC,MAAM,CAAiB;IAE/B,YACS,UAAkB,EAClB,MAA+B,EAC/B,GAAwB;QAE/B,KAAK,EAAE,CAAC;QAJD,eAAU,GAAV,UAAU,CAAQ;QAClB,WAAM,GAAN,MAAM,CAAyB;QAC/B,QAAG,GAAH,GAAG,CAAqB;QAG/B,MAAM,OAAO,GAAG,IAAA,uBAAa,EAAC;YAC5B,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;YACzD,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;YACpC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa;SAClC,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,GAAG,IAAI,qBAAc,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IACvE,CAAC;IAED,IAAI,CAAC,OAAmB;QACtB,MAAM,IAAI,oCAAuB,EAAE,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,MAAkB;QAC9C,MAAM,YAAY,GAAG,MAAM,IAAA,2BAAmB,EAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACjF,MAAM,EAAE,eAAe,EAAE,aAAa,EAAE,SAAS,EAAE,SA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SAAS,GAAG;YAChB,eAAe;YACf,YAAY;YACZ,YAAY;YACZ,YAAY;YACZ,SAAS;YACT,eAAe,EAAE,IAAI;YACrB,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAC5B,cAAc,EAAE,CAAC,qBAAqB,EAAE,+BAA+B,CAAC;YACxE,iBAAiB,EAAE,gCAAiB,CAAC,IAAI;SAC1C,CAAC;QACF,MAAM,WAAW,GAAG,MAAM,IAAA,uCAAwB,EAAC,SAAS,CAAC,CAAC;QAC9D,OAAO,WAAW,CAAC,SAAS,EAAE,CAAC;IACjC,CAAC;CACF;AA/ID,4CA+IC","sourcesContent":["import { ClarigenClient, contractFactory } from \"@clarigen/core\";\nimport { createNetwork } from \"@stacks/network\";\nimport {\n ContractIdString,\n makeRandomPrivKey,\n makeUnsignedContractCall,\n parseContractId,\n PostCondition,\n PostConditionMode,\n privateKeyToPublic,\n} from \"@stacks/transactions\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError } from \"../../../exceptions\";\nimport { AllbridgeCoreSdkOptions } from \"../../../index\";\nimport { FeePaymentMethod } from \"../../../models\";\nimport { RawStxTransaction, TransactionResponse } from \"../../models\";\nimport { stacksContracts as contracts } from \"../../models/stx/clarigen-types\";\nimport { getTokenName } from \"../../utils/stx/get-token-name\";\nimport { getFungiblePostCondition, getStxPostCondition } from \"../../utils/stx/post-conditions\";\nimport { ChainBridgeService, SendParams, SwapParams } from \"../models\";\nimport { getNonce, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class StxBridgeService extends ChainBridgeService {\n chainType: ChainType.STX = ChainType.STX;\n\n private client: ClarigenClient;\n\n constructor(\n public nodeRpcUrl: string,\n public params: AllbridgeCoreSdkOptions,\n public api: AllbridgeCoreClient\n ) {\n super();\n const network = createNetwork({\n network: this.params.stxIsTestnet ? \"testnet\" : \"mainnet\",\n client: { baseUrl: this.nodeRpcUrl },\n apiKey: this.params.stxHeroApiKey,\n });\n this.client = new ClarigenClient(network, this.params.stxHeroApiKey);\n }\n\n send(_params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawStxTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n const { contractAddress: bridgeAddress, messenger, toChainId, toAccountAddress, toTokenAddress } = txSendParams;\n const amount = BigInt(txSendParams.amount);\n\n const postFungiblePostCondition = getFungiblePostCondition(\n amount,\n \"lte\",\n params.fromAccountAddress,\n params.sourceToken.tokenAddress,\n getTokenName(params.sourceToken)\n );\n const postStxPostCondition = getStxPostCondition(0, \"gte\", params.sourceToken.bridgeAddress);\n const postConditions: PostCondition[] = [postFungiblePostCondition, postStxPostCondition];\n\n let totalFee = BigInt(txSendParams.fee);\n if (txSendParams.extraGas) {\n totalFee = totalFee + BigInt(txSendParams.extraGas);\n }\n\n const isPayWithStable = txSendParams.gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN;\n\n let feeTokenAmount: bigint;\n let feeNativeAmount: bigint;\n if (isPayWithStable) {\n feeTokenAmount = totalFee;\n feeNativeAmount = 0n;\n } else {\n feeTokenAmount = 0n;\n feeNativeAmount = totalFee;\n const postUserStxPostCondition = getStxPostCondition(totalFee, \"lte\", params.fromAccountAddress);\n postConditions.push(postUserStxPostCondition);\n }\n\n const [contractPrincipal] = parseContractId(bridgeAddress as ContractIdString);\n\n const bridge = contractFactory(contracts.bridge, bridgeAddress);\n const { contractAddress, contractName, functionName, functionArgs } = bridge.swapAndBridge({\n ftRef: params.sourceToken.tokenAddress,\n poolRef: params.sourceToken.poolAddress,\n messengerRef: `${contractPrincipal}.messenger`,\n gasOracleRef: `${contractPrincipal}.gas-oracle`,\n amount,\n recipient: Uint8Array.from(toAccountAddress),\n destinationChainId: toChainId,\n receiveToken: Uint8Array.from(toTokenAddress),\n nonce: Uint8Array.from(getNonce()),\n messengerId: messenger,\n feeNativeAmount: feeNativeAmount,\n feeTokenAmount: feeTokenAmount,\n });\n\n const privateKey = makeRandomPrivKey();\n const publicKey = privateKeyToPublic(privateKey);\n\n const txOptions = {\n contractAddress,\n contractName,\n functionName,\n functionArgs,\n publicKey,\n validateWithAbi: true,\n network: this.client.network,\n postConditions,\n postConditionMode: PostConditionMode.Deny,\n };\n const transaction = await makeUnsignedContractCall(txOptions);\n return transaction.serialize();\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawStxTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n const amount = BigInt(txSwapParams.amount);\n const minimumReceiveAmount = BigInt(txSwapParams.minimumReceiveAmount);\n\n const bridgeAddress = params.sourceToken.bridgeAddress;\n const bridge = contractFactory(contracts.bridge, bridgeAddress);\n const { contractAddress, contractName, functionName, functionArgs } = bridge.swap({\n amount,\n sendPoolRef: params.sourceToken.poolAddress,\n sendFtRef: params.sourceToken.tokenAddress,\n receivePoolRef: params.destinationToken.poolAddress,\n receiveFtRef: params.destinationToken.tokenAddress,\n recipient: params.toAccountAddress,\n receiveAmountMin: minimumReceiveAmount,\n });\n\n const privateKey = makeRandomPrivKey();\n const publicKey = privateKeyToPublic(privateKey);\n\n const postFungibleCondition = getFungiblePostCondition(\n amount,\n \"lte\",\n params.fromAccountAddress,\n params.sourceToken.tokenAddress,\n getTokenName(params.sourceToken)\n );\n\n const postFungibleMinReceiveCondition = getFungiblePostCondition(\n minimumReceiveAmount,\n \"gte\",\n params.destinationToken.poolAddress,\n params.destinationToken.tokenAddress,\n getTokenName(params.destinationToken)\n );\n\n const txOptions = {\n contractAddress,\n contractName,\n functionName,\n functionArgs,\n publicKey,\n validateWithAbi: true,\n network: this.client.network,\n postConditions: [postFungibleCondition, postFungibleMinReceiveCondition],\n postConditionMode: PostConditionMode.Deny,\n };\n const transaction = await makeUnsignedContractCall(txOptions);\n return transaction.serialize();\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../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CAAC;QAEF,MAAM,+BAA+B,GAAG,IAAA,0CAAwB,EAC9D,oBAAoB,EACpB,KAAK,EACL,MAAM,CAAC,gBAAgB,CAAC,WAAW,EACnC,MAAM,CAAC,gBAAgB,CAAC,YAAY,EACpC,IAAA,6BAAY,EAAC,MAAM,CAAC,gBAAgB,CAAC,CACtC,CAAC;QAEF,MAAM,SAAS,GAAG;YAChB,eAAe;YACf,YAAY;YACZ,YAAY;YACZ,YAAY;YACZ,SAAS;YACT,eAAe,EAAE,IAAI;YACrB,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAC5B,cAAc,EAAE,CAAC,qBAAqB,EAAE,+BAA+B,CAAC;YACxE,iBAAiB,EAAE,gCAAiB,CAAC,IAAI;SAC1C,CAAC;QACF,MAAM,WAAW,GAAG,MAAM,IAAA,uCAAwB,EAAC,SAAS,CAAC,CAAC;QAC9D,OAAO,WAAW,CAAC,SAAS,EAAE,CAAC;IACjC,CAAC;CACF;AAvJD,4CAuJC","sourcesContent":["import { ClarigenClient, contractFactory } from \"@clarigen/core\";\nimport { createNetwork } from \"@stacks/network\";\nimport {\n ContractIdString,\n makeRandomPrivKey,\n makeUnsignedContractCall,\n parseContractId,\n PostCondition,\n PostConditionMode,\n privateKeyToPublic,\n} from \"@stacks/transactions\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError, SdkError } from \"../../../exceptions\";\nimport { AllbridgeCoreSdkOptions } from \"../../../index\";\nimport { FeePaymentMethod } from \"../../../models\";\nimport { assertNever } from \"../../../utils/utils\";\nimport { RawStxTransaction, TransactionResponse } from \"../../models\";\nimport { stacksContracts as contracts } from \"../../models/stx/clarigen-types\";\nimport { getTokenName } from \"../../utils/stx/get-token-name\";\nimport { getFungiblePostCondition, getStxPostCondition } from \"../../utils/stx/post-conditions\";\nimport { ChainBridgeService, SendParams, SwapParams } from \"../models\";\nimport { getNonce, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class StxBridgeService extends ChainBridgeService {\n chainType: ChainType.STX = ChainType.STX;\n\n private client: ClarigenClient;\n\n constructor(\n public nodeRpcUrl: string,\n public params: AllbridgeCoreSdkOptions,\n public api: AllbridgeCoreClient\n ) {\n super();\n const network = createNetwork({\n network: this.params.stxIsTestnet ? \"testnet\" : \"mainnet\",\n client: { baseUrl: this.nodeRpcUrl },\n apiKey: this.params.stxHeroApiKey,\n });\n this.client = new ClarigenClient(network, this.params.stxHeroApiKey);\n }\n\n send(_params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawStxTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n const { contractAddress: bridgeAddress, messenger, toChainId, toAccountAddress, toTokenAddress } = txSendParams;\n const amount = BigInt(txSendParams.amount);\n\n const postFungiblePostCondition = getFungiblePostCondition(\n amount,\n \"lte\",\n params.fromAccountAddress,\n params.sourceToken.tokenAddress,\n getTokenName(params.sourceToken)\n );\n const postStxPostCondition = getStxPostCondition(0, \"gte\", params.sourceToken.bridgeAddress);\n const postConditions: PostCondition[] = [postFungiblePostCondition, postStxPostCondition];\n\n let totalFee = BigInt(txSendParams.fee);\n if (txSendParams.extraGas) {\n totalFee = totalFee + BigInt(txSendParams.extraGas);\n }\n\n let feeTokenAmount: bigint;\n let feeNativeAmount: bigint;\n switch (txSendParams.gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n feeTokenAmount = 0n;\n feeNativeAmount = totalFee;\n const postUserStxPostCondition = getStxPostCondition(totalFee, \"lte\", params.fromAccountAddress);\n postConditions.push(postUserStxPostCondition);\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n feeTokenAmount = totalFee;\n feeNativeAmount = 0n;\n break;\n }\n case FeePaymentMethod.WITH_ARB:\n throw new SdkError(\"STX bridge does not support ARB0 payment method\");\n default: {\n return assertNever(txSendParams.gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n\n const [contractPrincipal] = parseContractId(bridgeAddress as ContractIdString);\n\n const bridge = contractFactory(contracts.bridge, bridgeAddress);\n const { contractAddress, contractName, functionName, functionArgs } = bridge.swapAndBridge({\n ftRef: params.sourceToken.tokenAddress,\n poolRef: params.sourceToken.poolAddress,\n messengerRef: `${contractPrincipal}.messenger`,\n gasOracleRef: `${contractPrincipal}.gas-oracle`,\n amount,\n recipient: Uint8Array.from(toAccountAddress),\n destinationChainId: toChainId,\n receiveToken: Uint8Array.from(toTokenAddress),\n nonce: Uint8Array.from(getNonce()),\n messengerId: messenger,\n feeNativeAmount: feeNativeAmount,\n feeTokenAmount: feeTokenAmount,\n });\n\n const privateKey = makeRandomPrivKey();\n const publicKey = privateKeyToPublic(privateKey);\n\n const txOptions = {\n contractAddress,\n contractName,\n functionName,\n functionArgs,\n publicKey,\n validateWithAbi: true,\n network: this.client.network,\n postConditions,\n postConditionMode: PostConditionMode.Deny,\n };\n const transaction = await makeUnsignedContractCall(txOptions);\n return transaction.serialize();\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawStxTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n const amount = BigInt(txSwapParams.amount);\n const minimumReceiveAmount = BigInt(txSwapParams.minimumReceiveAmount);\n\n const bridgeAddress = params.sourceToken.bridgeAddress;\n const bridge = contractFactory(contracts.bridge, bridgeAddress);\n const { contractAddress, contractName, functionName, functionArgs } = bridge.swap({\n amount,\n sendPoolRef: params.sourceToken.poolAddress,\n sendFtRef: params.sourceToken.tokenAddress,\n receivePoolRef: params.destinationToken.poolAddress,\n receiveFtRef: params.destinationToken.tokenAddress,\n recipient: params.toAccountAddress,\n receiveAmountMin: minimumReceiveAmount,\n });\n\n const privateKey = makeRandomPrivKey();\n const publicKey = privateKeyToPublic(privateKey);\n\n const postFungibleCondition = getFungiblePostCondition(\n amount,\n \"lte\",\n params.fromAccountAddress,\n params.sourceToken.tokenAddress,\n getTokenName(params.sourceToken)\n );\n\n const postFungibleMinReceiveCondition = getFungiblePostCondition(\n minimumReceiveAmount,\n \"gte\",\n params.destinationToken.poolAddress,\n params.destinationToken.tokenAddress,\n getTokenName(params.destinationToken)\n );\n\n const txOptions = {\n contractAddress,\n contractName,\n functionName,\n functionArgs,\n publicKey,\n validateWithAbi: true,\n network: this.client.network,\n postConditions: [postFungibleCondition, postFungibleMinReceiveCondition],\n postConditionMode: PostConditionMode.Deny,\n };\n const transaction = await makeUnsignedContractCall(txOptions);\n return transaction.serialize();\n }\n}\n"]}