@allbridge/bridge-core-sdk 3.27.0-beta.6 → 3.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/browser/index.js +1 -6
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/cjs/index.js +1 -6
  4. package/dist/cjs/index.js.map +4 -4
  5. package/dist/esm/index.js +1 -6
  6. package/dist/esm/index.js.map +4 -4
  7. package/dist/src/chains/chain.enums.d.ts +2 -12
  8. package/dist/src/chains/chain.enums.js +0 -10
  9. package/dist/src/chains/chain.enums.js.map +1 -1
  10. package/dist/src/chains/index.js +0 -12
  11. package/dist/src/chains/index.js.map +1 -1
  12. package/dist/src/client/core-api/api-client.js +0 -1
  13. package/dist/src/client/core-api/api-client.js.map +1 -1
  14. package/dist/src/client/core-api/core-api-mapper.js +0 -33
  15. package/dist/src/client/core-api/core-api-mapper.js.map +1 -1
  16. package/dist/src/client/core-api/core-api.model.d.ts +2 -14
  17. package/dist/src/client/core-api/core-api.model.js.map +1 -1
  18. package/dist/src/configs/mainnet.js +0 -1
  19. package/dist/src/configs/mainnet.js.map +1 -1
  20. package/dist/src/index.d.ts +4 -12
  21. package/dist/src/index.js +11 -11
  22. package/dist/src/index.js.map +1 -1
  23. package/dist/src/models/index.d.ts +4 -12
  24. package/dist/src/models/index.js +0 -4
  25. package/dist/src/models/index.js.map +1 -1
  26. package/dist/src/services/bridge/evm/index.d.ts +0 -1
  27. package/dist/src/services/bridge/evm/index.js +33 -103
  28. package/dist/src/services/bridge/evm/index.js.map +1 -1
  29. package/dist/src/services/bridge/index.d.ts +2 -2
  30. package/dist/src/services/bridge/index.js +4 -31
  31. package/dist/src/services/bridge/index.js.map +1 -1
  32. package/dist/src/services/bridge/models/bridge.model.d.ts +4 -13
  33. package/dist/src/services/bridge/models/bridge.model.js.map +1 -1
  34. package/dist/src/services/bridge/raw-bridge-transaction-builder.js +1 -1
  35. package/dist/src/services/bridge/raw-bridge-transaction-builder.js.map +1 -1
  36. package/dist/src/services/bridge/srb/index.js +28 -36
  37. package/dist/src/services/bridge/srb/index.js.map +1 -1
  38. package/dist/src/services/bridge/sui/index.js +138 -166
  39. package/dist/src/services/bridge/sui/index.js.map +1 -1
  40. package/dist/src/services/bridge/trx/index.js +70 -98
  41. package/dist/src/services/bridge/trx/index.js.map +1 -1
  42. package/dist/src/services/bridge/utils.d.ts +1 -5
  43. package/dist/src/services/bridge/utils.js +23 -164
  44. package/dist/src/services/bridge/utils.js.map +1 -1
  45. package/dist/src/services/liquidity-pool/index.js +0 -21
  46. package/dist/src/services/liquidity-pool/index.js.map +1 -1
  47. package/dist/src/services/liquidity-pool/sui/index.js.map +1 -1
  48. package/dist/src/services/liquidity-pool/trx/index.js.map +1 -1
  49. package/dist/src/services/models/index.d.ts +5 -7
  50. package/dist/src/services/models/index.js.map +1 -1
  51. package/dist/src/services/token/index.js +2 -23
  52. package/dist/src/services/token/index.js.map +1 -1
  53. package/dist/src/services/token/models/token.model.d.ts +4 -4
  54. package/dist/src/services/token/models/token.model.js.map +1 -1
  55. package/dist/src/services/token/sui/index.js.map +1 -1
  56. package/dist/src/services/utils/trx/index.js.map +1 -1
  57. package/dist/src/services/yield/index.js +0 -8
  58. package/dist/src/services/yield/index.js.map +1 -1
  59. package/dist/src/tokens-info/tokens-info.model.d.ts +0 -25
  60. package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
  61. package/dist/src/utils/index.d.ts +0 -3
  62. package/dist/src/utils/index.js +0 -3
  63. package/dist/src/utils/index.js.map +1 -1
  64. package/dist/src/utils/utils.d.ts +0 -2
  65. package/dist/src/utils/utils.js +0 -11
  66. package/dist/src/utils/utils.js.map +1 -1
  67. package/dist/src/version.d.ts +1 -1
  68. package/dist/src/version.js +1 -1
  69. package/dist/src/version.js.map +1 -1
  70. package/package.json +2 -9
  71. package/dist/src/services/bridge/alg/index.d.ts +0 -16
  72. package/dist/src/services/bridge/alg/index.js +0 -191
  73. package/dist/src/services/bridge/alg/index.js.map +0 -1
  74. package/dist/src/services/bridge/stx/index.d.ts +0 -16
  75. package/dist/src/services/bridge/stx/index.js +0 -136
  76. package/dist/src/services/bridge/stx/index.js.map +0 -1
  77. package/dist/src/services/liquidity-pool/alg/index.d.ts +0 -19
  78. package/dist/src/services/liquidity-pool/alg/index.js +0 -135
  79. package/dist/src/services/liquidity-pool/alg/index.js.map +0 -1
  80. package/dist/src/services/liquidity-pool/stx/index.d.ts +0 -21
  81. package/dist/src/services/liquidity-pool/stx/index.js +0 -141
  82. package/dist/src/services/liquidity-pool/stx/index.js.map +0 -1
  83. package/dist/src/services/models/abi/PayerWithAbr.d.ts +0 -203
  84. package/dist/src/services/models/abi/PayerWithAbr.js +0 -266
  85. package/dist/src/services/models/abi/PayerWithAbr.js.map +0 -1
  86. package/dist/src/services/models/alg/BridgeClient.d.ts +0 -2751
  87. package/dist/src/services/models/alg/BridgeClient.js +0 -2685
  88. package/dist/src/services/models/alg/BridgeClient.js.map +0 -1
  89. package/dist/src/services/models/alg/PaddingUtilClient.d.ts +0 -654
  90. package/dist/src/services/models/alg/PaddingUtilClient.js +0 -425
  91. package/dist/src/services/models/alg/PaddingUtilClient.js.map +0 -1
  92. package/dist/src/services/models/alg/PoolClient.d.ts +0 -2276
  93. package/dist/src/services/models/alg/PoolClient.js +0 -2195
  94. package/dist/src/services/models/alg/PoolClient.js.map +0 -1
  95. package/dist/src/services/models/stx/clarigen-types.d.ts +0 -657
  96. package/dist/src/services/models/stx/clarigen-types.js +0 -2296
  97. package/dist/src/services/models/stx/clarigen-types.js.map +0 -1
  98. package/dist/src/services/token/alg/index.d.ts +0 -17
  99. package/dist/src/services/token/alg/index.js +0 -47
  100. package/dist/src/services/token/alg/index.js.map +0 -1
  101. package/dist/src/services/token/stx/index.d.ts +0 -20
  102. package/dist/src/services/token/stx/index.js +0 -59
  103. package/dist/src/services/token/stx/index.js.map +0 -1
  104. package/dist/src/services/utils/alg/index.d.ts +0 -9
  105. package/dist/src/services/utils/alg/index.js +0 -74
  106. package/dist/src/services/utils/alg/index.js.map +0 -1
  107. package/dist/src/services/utils/stx/get-token-name.d.ts +0 -2
  108. package/dist/src/services/utils/stx/get-token-name.js +0 -15
  109. package/dist/src/services/utils/stx/get-token-name.js.map +0 -1
  110. package/dist/src/services/utils/stx/post-conditions.d.ts +0 -3
  111. package/dist/src/services/utils/stx/post-conditions.js +0 -27
  112. package/dist/src/services/utils/stx/post-conditions.js.map +0 -1
  113. package/dist/src/utils/alg/index.d.ts +0 -21
  114. package/dist/src/utils/alg/index.js +0 -71
  115. package/dist/src/utils/alg/index.js.map +0 -1
@@ -6,17 +6,16 @@ const transactions_1 = require("@mysten/sui/transactions");
6
6
  const utils_1 = require("@mysten/sui/utils");
7
7
  const big_js_1 = require("big.js");
8
8
  const models_1 = require("../../../models");
9
- const utils_2 = require("../../../utils/utils");
10
9
  const bridge_1 = require("../../models/sui/bridge");
11
10
  const functions_1 = require("../../models/sui/bridge/bridge-interface/functions");
12
11
  const cctp_bridge_1 = require("../../models/sui/cctp-bridge");
13
12
  const functions_2 = require("../../models/sui/cctp-bridge/cctp-bridge-interface/functions");
14
- const utils_3 = require("../../models/sui/utils");
13
+ const utils_2 = require("../../models/sui/utils");
15
14
  const functions_3 = require("../../models/sui/utils/bytes32/functions");
16
15
  const paginated_1 = require("../../utils/sui/paginated");
17
16
  const get_cctp_sol_token_recipient_address_1 = require("../get-cctp-sol-token-recipient-address");
18
17
  const models_2 = require("../models");
19
- const utils_4 = require("../utils");
18
+ const utils_3 = require("../utils");
20
19
  class SuiBridgeService extends models_2.ChainBridgeService {
21
20
  nodeRpcUrlsConfig;
22
21
  api;
@@ -40,7 +39,7 @@ class SuiBridgeService extends models_2.ChainBridgeService {
40
39
  throw new models_1.SdkError("SUI token must contain 'suiAddresses'");
41
40
  }
42
41
  (0, bridge_1.setAddress)(suiAddresses.bridgeAddress, suiAddresses.bridgeAddressOrigin);
43
- const txSwapParams = (0, utils_4.prepareTxSwapParams)(this.chainType, params);
42
+ const txSwapParams = (0, utils_3.prepareTxSwapParams)(this.chainType, params);
44
43
  return await this.buildRawTransactionSwapFromParams(txSwapParams, suiAddresses);
45
44
  }
46
45
  async buildRawTransactionSwapFromParams(params, suiAddresses) {
@@ -74,14 +73,14 @@ class SuiBridgeService extends models_2.ChainBridgeService {
74
73
  return this.buildRawTransactionSendFromTx(params, new transactions_1.Transaction());
75
74
  }
76
75
  async buildRawTransactionSendFromTx(params, tx, inputCoin) {
77
- const txSendParams = await (0, utils_4.prepareTxSendParams)(this.chainType, params, this.api);
76
+ const txSendParams = await (0, utils_3.prepareTxSendParams)(this.chainType, params, this.api);
78
77
  const { messenger } = txSendParams;
79
78
  const suiAddresses = params.sourceToken.suiAddresses;
80
79
  if (!suiAddresses) {
81
80
  throw new models_1.SdkError("SUI token must contain 'suiAddresses'");
82
81
  }
83
82
  (0, bridge_1.setAddress)(suiAddresses.bridgeAddress, suiAddresses.bridgeAddressOrigin);
84
- (0, utils_3.setAddress)(suiAddresses.utilsAddress);
83
+ (0, utils_2.setAddress)(suiAddresses.utilsAddress);
85
84
  switch (messenger) {
86
85
  case models_1.Messenger.ALLBRIDGE:
87
86
  return this.buildRawTransactionAllbridgeSend(txSendParams, suiAddresses, tx, inputCoin);
@@ -101,58 +100,49 @@ class SuiBridgeService extends models_2.ChainBridgeService {
101
100
  totalFee = (0, big_js_1.Big)(totalFee).plus(extraGas).toFixed();
102
101
  }
103
102
  tx.setSender(fromAccountAddress);
104
- switch (gasFeePaymentMethod) {
105
- case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY: {
106
- const totalFeeCoin = totalFee === "0"
107
- ? (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee), useGasCoin: false })
108
- : (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee) });
109
- const args = {
110
- bridge: suiAddresses.bridgeObjectAddress,
111
- messenger: suiAddresses.allbridgeMessengerObjectAddress,
112
- amount: inputCoin ?? (0, transactions_1.coinWithBalance)({ balance: BigInt(amount), type: fromTokenAddress }),
113
- destinationChainId: toChainId,
114
- nonce: (0, utils_4.getNonceBigInt)(),
115
- recipient: (0, functions_3.fromHex)(tx, (0, utils_4.normalizeSuiHex)(toAccountAddress)),
116
- receiveToken: (0, functions_3.fromHex)(tx, (0, utils_4.normalizeSuiHex)(toTokenAddress)),
117
- gasOracle: suiAddresses.gasOracleObjectAddress,
118
- feeTokenCoin: (0, transactions_1.coinWithBalance)({ balance: BigInt(0), type: fromTokenAddress }),
119
- feeSuiCoin: totalFeeCoin,
120
- };
121
- (0, functions_1.swapAndBridge)(tx, fromTokenAddress, args);
122
- break;
103
+ if (gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN) {
104
+ const amountWithoutFee = BigInt(amount) - BigInt(totalFee);
105
+ let amountCoin, feeTokenCoin;
106
+ if (inputCoin) {
107
+ const [feeTokenCoinS] = tx.splitCoins(inputCoin, [totalFee]);
108
+ amountCoin = inputCoin;
109
+ feeTokenCoin = feeTokenCoinS;
123
110
  }
124
- case models_1.FeePaymentMethod.WITH_STABLECOIN: {
125
- const amountWithoutFee = BigInt(amount) - BigInt(totalFee);
126
- let amountCoin, feeTokenCoin;
127
- if (inputCoin) {
128
- const [feeTokenCoinS] = tx.splitCoins(inputCoin, [totalFee]);
129
- amountCoin = inputCoin;
130
- feeTokenCoin = feeTokenCoinS;
131
- }
132
- else {
133
- amountCoin = (0, transactions_1.coinWithBalance)({ balance: amountWithoutFee, type: fromTokenAddress });
134
- feeTokenCoin = (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee), type: fromTokenAddress });
135
- }
136
- const args = {
137
- bridge: suiAddresses.bridgeObjectAddress,
138
- messenger: suiAddresses.allbridgeMessengerObjectAddress,
139
- amount: amountCoin,
140
- destinationChainId: toChainId,
141
- nonce: (0, utils_4.getNonceBigInt)(),
142
- recipient: (0, functions_3.fromHex)(tx, (0, utils_4.normalizeSuiHex)(toAccountAddress)),
143
- receiveToken: (0, functions_3.fromHex)(tx, (0, utils_4.normalizeSuiHex)(toTokenAddress)),
144
- gasOracle: suiAddresses.gasOracleObjectAddress,
145
- feeTokenCoin: feeTokenCoin,
146
- feeSuiCoin: (0, transactions_1.coinWithBalance)({ balance: BigInt(0), useGasCoin: false }),
147
- };
148
- (0, functions_1.swapAndBridge)(tx, fromTokenAddress, args);
149
- break;
150
- }
151
- case models_1.FeePaymentMethod.WITH_ARB:
152
- throw new models_1.SdkError("SUI bridge does not support ARB0 payment method");
153
- default: {
154
- return (0, utils_2.assertNever)(gasFeePaymentMethod, "Unhandled FeePaymentMethod");
111
+ else {
112
+ amountCoin = (0, transactions_1.coinWithBalance)({ balance: amountWithoutFee, type: fromTokenAddress });
113
+ feeTokenCoin = (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee), type: fromTokenAddress });
155
114
  }
115
+ const args = {
116
+ bridge: suiAddresses.bridgeObjectAddress,
117
+ messenger: suiAddresses.allbridgeMessengerObjectAddress,
118
+ amount: amountCoin,
119
+ destinationChainId: toChainId,
120
+ nonce: (0, utils_3.getNonceBigInt)(),
121
+ recipient: (0, functions_3.fromHex)(tx, (0, utils_3.normalizeSuiHex)(toAccountAddress)),
122
+ receiveToken: (0, functions_3.fromHex)(tx, (0, utils_3.normalizeSuiHex)(toTokenAddress)),
123
+ gasOracle: suiAddresses.gasOracleObjectAddress,
124
+ feeTokenCoin: feeTokenCoin,
125
+ feeSuiCoin: (0, transactions_1.coinWithBalance)({ balance: BigInt(0), useGasCoin: false }),
126
+ };
127
+ (0, functions_1.swapAndBridge)(tx, fromTokenAddress, args);
128
+ }
129
+ else {
130
+ const totalFeeCoin = totalFee === "0"
131
+ ? (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee), useGasCoin: false })
132
+ : (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee) });
133
+ const args = {
134
+ bridge: suiAddresses.bridgeObjectAddress,
135
+ messenger: suiAddresses.allbridgeMessengerObjectAddress,
136
+ amount: inputCoin ?? (0, transactions_1.coinWithBalance)({ balance: BigInt(amount), type: fromTokenAddress }),
137
+ destinationChainId: toChainId,
138
+ nonce: (0, utils_3.getNonceBigInt)(),
139
+ recipient: (0, functions_3.fromHex)(tx, (0, utils_3.normalizeSuiHex)(toAccountAddress)),
140
+ receiveToken: (0, functions_3.fromHex)(tx, (0, utils_3.normalizeSuiHex)(toTokenAddress)),
141
+ gasOracle: suiAddresses.gasOracleObjectAddress,
142
+ feeTokenCoin: (0, transactions_1.coinWithBalance)({ balance: BigInt(0), type: fromTokenAddress }),
143
+ feeSuiCoin: totalFeeCoin,
144
+ };
145
+ (0, functions_1.swapAndBridge)(tx, fromTokenAddress, args);
156
146
  }
157
147
  return await tx.toJSON({ client: this.client });
158
148
  }
@@ -163,62 +153,53 @@ class SuiBridgeService extends models_2.ChainBridgeService {
163
153
  totalFee = (0, big_js_1.Big)(totalFee).plus(extraGas).toFixed();
164
154
  }
165
155
  tx.setSender(fromAccountAddress);
166
- switch (gasFeePaymentMethod) {
167
- case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY: {
168
- const totalFeeCoin = totalFee === "0"
169
- ? (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee), useGasCoin: false })
170
- : (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee) });
171
- const args = {
172
- bridge: suiAddresses.bridgeObjectAddress,
173
- messenger: suiAddresses.wormholeMessengerObjectAddress,
174
- wormholeState: suiAddresses.wormholeStateObjectAddress,
175
- theClock: utils_1.SUI_CLOCK_OBJECT_ID,
176
- amount: inputCoin ?? (0, transactions_1.coinWithBalance)({ balance: BigInt(amount), type: fromTokenAddress }),
177
- destinationChainId: toChainId,
178
- nonce: (0, utils_4.getNonceBigInt)(),
179
- recipient: (0, functions_3.fromHex)(tx, (0, utils_4.normalizeSuiHex)(toAccountAddress)),
180
- receiveToken: (0, functions_3.fromHex)(tx, (0, utils_4.normalizeSuiHex)(toTokenAddress)),
181
- gasOracle: suiAddresses.gasOracleObjectAddress,
182
- feeTokenCoin: (0, transactions_1.coinWithBalance)({ balance: BigInt(0), type: fromTokenAddress }),
183
- feeSuiCoin: totalFeeCoin,
184
- };
185
- (0, functions_1.swapAndBridgeWormhole)(tx, fromTokenAddress, args);
186
- break;
156
+ if (gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN) {
157
+ const amountWithoutFee = BigInt(amount) - BigInt(totalFee);
158
+ let amountCoin, feeTokenCoin;
159
+ if (inputCoin) {
160
+ const [feeTokenCoinS] = tx.splitCoins(inputCoin, [totalFee]);
161
+ amountCoin = inputCoin;
162
+ feeTokenCoin = feeTokenCoinS;
187
163
  }
188
- case models_1.FeePaymentMethod.WITH_STABLECOIN: {
189
- const amountWithoutFee = BigInt(amount) - BigInt(totalFee);
190
- let amountCoin, feeTokenCoin;
191
- if (inputCoin) {
192
- const [feeTokenCoinS] = tx.splitCoins(inputCoin, [totalFee]);
193
- amountCoin = inputCoin;
194
- feeTokenCoin = feeTokenCoinS;
195
- }
196
- else {
197
- amountCoin = (0, transactions_1.coinWithBalance)({ balance: amountWithoutFee, type: fromTokenAddress });
198
- feeTokenCoin = (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee), type: fromTokenAddress });
199
- }
200
- const args = {
201
- bridge: suiAddresses.bridgeObjectAddress,
202
- messenger: suiAddresses.wormholeMessengerObjectAddress,
203
- wormholeState: suiAddresses.wormholeStateObjectAddress,
204
- theClock: utils_1.SUI_CLOCK_OBJECT_ID,
205
- amount: amountCoin,
206
- destinationChainId: toChainId,
207
- nonce: (0, utils_4.getNonceBigInt)(),
208
- recipient: (0, functions_3.fromHex)(tx, (0, utils_4.normalizeSuiHex)(toAccountAddress)),
209
- receiveToken: (0, functions_3.fromHex)(tx, (0, utils_4.normalizeSuiHex)(toTokenAddress)),
210
- gasOracle: suiAddresses.gasOracleObjectAddress,
211
- feeTokenCoin: feeTokenCoin,
212
- feeSuiCoin: (0, transactions_1.coinWithBalance)({ balance: BigInt(0), useGasCoin: false }),
213
- };
214
- (0, functions_1.swapAndBridgeWormhole)(tx, fromTokenAddress, args);
215
- break;
216
- }
217
- case models_1.FeePaymentMethod.WITH_ARB:
218
- throw new models_1.SdkError("SUI bridge does not support ARB0 payment method");
219
- default: {
220
- return (0, utils_2.assertNever)(gasFeePaymentMethod, "Unhandled FeePaymentMethod");
164
+ else {
165
+ amountCoin = (0, transactions_1.coinWithBalance)({ balance: amountWithoutFee, type: fromTokenAddress });
166
+ feeTokenCoin = (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee), type: fromTokenAddress });
221
167
  }
168
+ const args = {
169
+ bridge: suiAddresses.bridgeObjectAddress,
170
+ messenger: suiAddresses.wormholeMessengerObjectAddress,
171
+ wormholeState: suiAddresses.wormholeStateObjectAddress,
172
+ theClock: utils_1.SUI_CLOCK_OBJECT_ID,
173
+ amount: amountCoin,
174
+ destinationChainId: toChainId,
175
+ nonce: (0, utils_3.getNonceBigInt)(),
176
+ recipient: (0, functions_3.fromHex)(tx, (0, utils_3.normalizeSuiHex)(toAccountAddress)),
177
+ receiveToken: (0, functions_3.fromHex)(tx, (0, utils_3.normalizeSuiHex)(toTokenAddress)),
178
+ gasOracle: suiAddresses.gasOracleObjectAddress,
179
+ feeTokenCoin: feeTokenCoin,
180
+ feeSuiCoin: (0, transactions_1.coinWithBalance)({ balance: BigInt(0), useGasCoin: false }),
181
+ };
182
+ (0, functions_1.swapAndBridgeWormhole)(tx, fromTokenAddress, args);
183
+ }
184
+ else {
185
+ const totalFeeCoin = totalFee === "0"
186
+ ? (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee), useGasCoin: false })
187
+ : (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee) });
188
+ const args = {
189
+ bridge: suiAddresses.bridgeObjectAddress,
190
+ messenger: suiAddresses.wormholeMessengerObjectAddress,
191
+ wormholeState: suiAddresses.wormholeStateObjectAddress,
192
+ theClock: utils_1.SUI_CLOCK_OBJECT_ID,
193
+ amount: inputCoin ?? (0, transactions_1.coinWithBalance)({ balance: BigInt(amount), type: fromTokenAddress }),
194
+ destinationChainId: toChainId,
195
+ nonce: (0, utils_3.getNonceBigInt)(),
196
+ recipient: (0, functions_3.fromHex)(tx, (0, utils_3.normalizeSuiHex)(toAccountAddress)),
197
+ receiveToken: (0, functions_3.fromHex)(tx, (0, utils_3.normalizeSuiHex)(toTokenAddress)),
198
+ gasOracle: suiAddresses.gasOracleObjectAddress,
199
+ feeTokenCoin: (0, transactions_1.coinWithBalance)({ balance: BigInt(0), type: fromTokenAddress }),
200
+ feeSuiCoin: totalFeeCoin,
201
+ };
202
+ (0, functions_1.swapAndBridgeWormhole)(tx, fromTokenAddress, args);
222
203
  }
223
204
  return await tx.toJSON({ client: this.client });
224
205
  }
@@ -230,71 +211,62 @@ class SuiBridgeService extends models_2.ChainBridgeService {
230
211
  totalFee = (0, big_js_1.Big)(totalFee).plus(extraGas).toFixed();
231
212
  }
232
213
  tx.setSender(fromAccountAddress);
233
- const recipientWalletAddress = (0, functions_3.fromHex)(tx, (0, utils_4.normalizeSuiHex)(toAccountAddress));
214
+ const recipientWalletAddress = (0, functions_3.fromHex)(tx, (0, utils_3.normalizeSuiHex)(toAccountAddress));
234
215
  let recipient;
235
216
  if (params.destinationToken.chainType === models_1.ChainType.SOLANA) {
236
217
  const recipientStr = await (0, get_cctp_sol_token_recipient_address_1.getCctpSolTokenRecipientAddress)(this.chainType, params.toAccountAddress, params.destinationToken.tokenAddress, this.nodeRpcUrlsConfig.getNodeRpcUrl(models_1.ChainSymbol.SOL));
237
- recipient = (0, functions_3.fromHex)(tx, (0, utils_4.normalizeSuiHex)(recipientStr));
218
+ recipient = (0, functions_3.fromHex)(tx, (0, utils_3.normalizeSuiHex)(recipientStr));
238
219
  }
239
220
  else {
240
221
  recipient = recipientWalletAddress;
241
222
  }
242
- switch (gasFeePaymentMethod) {
243
- case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY: {
244
- const totalFeeCoin = totalFee === "0"
245
- ? (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee), useGasCoin: false })
246
- : (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee) });
247
- const args = {
248
- cctpBridge: suiAddresses.cctpObjectAddress,
249
- tokenMessengerMinterState: suiAddresses.cctpTokenMessengerMinterStateObjectAddress,
250
- messageTransmitterState: suiAddresses.cctpMessageTransmitterStateObjectAddress,
251
- treasury: suiAddresses.cctpTreasuryObjectAddress,
252
- denyList: suiAddresses.cctpDenyListObjectAddress,
253
- amount: inputCoin ?? (0, transactions_1.coinWithBalance)({ balance: BigInt(amount), type: fromTokenAddress }),
254
- destinationChainId: toChainId,
255
- recipient: recipient,
256
- recipientWalletAddress: recipientWalletAddress,
257
- gasOracle: suiAddresses.gasOracleObjectAddress,
258
- feeTokenCoin: (0, transactions_1.coinWithBalance)({ balance: BigInt(0), type: fromTokenAddress }),
259
- feeSuiCoin: totalFeeCoin,
260
- };
261
- (0, functions_2.bridge)(tx, fromTokenAddress, args);
262
- break;
263
- }
264
- case models_1.FeePaymentMethod.WITH_STABLECOIN: {
265
- const amountWithoutFee = BigInt(amount) - BigInt(totalFee);
266
- let amountCoin, feeTokenCoin;
267
- if (inputCoin) {
268
- const [feeTokenCoinS] = tx.splitCoins(inputCoin, [totalFee]);
269
- amountCoin = inputCoin;
270
- feeTokenCoin = feeTokenCoinS;
271
- }
272
- else {
273
- amountCoin = (0, transactions_1.coinWithBalance)({ balance: amountWithoutFee, type: fromTokenAddress });
274
- feeTokenCoin = (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee), type: fromTokenAddress });
275
- }
276
- const args = {
277
- cctpBridge: suiAddresses.cctpObjectAddress,
278
- tokenMessengerMinterState: suiAddresses.cctpTokenMessengerMinterStateObjectAddress,
279
- messageTransmitterState: suiAddresses.cctpMessageTransmitterStateObjectAddress,
280
- treasury: suiAddresses.cctpTreasuryObjectAddress,
281
- denyList: suiAddresses.cctpDenyListObjectAddress,
282
- amount: amountCoin,
283
- destinationChainId: toChainId,
284
- recipient: recipient,
285
- recipientWalletAddress: recipientWalletAddress,
286
- gasOracle: suiAddresses.gasOracleObjectAddress,
287
- feeTokenCoin: feeTokenCoin,
288
- feeSuiCoin: (0, transactions_1.coinWithBalance)({ balance: BigInt(0), useGasCoin: false }),
289
- };
290
- (0, functions_2.bridge)(tx, fromTokenAddress, args);
291
- break;
223
+ if (gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN) {
224
+ const amountWithoutFee = BigInt(amount) - BigInt(totalFee);
225
+ let amountCoin, feeTokenCoin;
226
+ if (inputCoin) {
227
+ const [feeTokenCoinS] = tx.splitCoins(inputCoin, [totalFee]);
228
+ amountCoin = inputCoin;
229
+ feeTokenCoin = feeTokenCoinS;
292
230
  }
293
- case models_1.FeePaymentMethod.WITH_ARB:
294
- throw new models_1.SdkError("SUI bridge does not support ARB0 payment method");
295
- default: {
296
- return (0, utils_2.assertNever)(gasFeePaymentMethod, "Unhandled FeePaymentMethod");
231
+ else {
232
+ amountCoin = (0, transactions_1.coinWithBalance)({ balance: amountWithoutFee, type: fromTokenAddress });
233
+ feeTokenCoin = (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee), type: fromTokenAddress });
297
234
  }
235
+ const args = {
236
+ cctpBridge: suiAddresses.cctpObjectAddress,
237
+ tokenMessengerMinterState: suiAddresses.cctpTokenMessengerMinterStateObjectAddress,
238
+ messageTransmitterState: suiAddresses.cctpMessageTransmitterStateObjectAddress,
239
+ treasury: suiAddresses.cctpTreasuryObjectAddress,
240
+ denyList: suiAddresses.cctpDenyListObjectAddress,
241
+ amount: amountCoin,
242
+ destinationChainId: toChainId,
243
+ recipient: recipient,
244
+ recipientWalletAddress: recipientWalletAddress,
245
+ gasOracle: suiAddresses.gasOracleObjectAddress,
246
+ feeTokenCoin: feeTokenCoin,
247
+ feeSuiCoin: (0, transactions_1.coinWithBalance)({ balance: BigInt(0), useGasCoin: false }),
248
+ };
249
+ (0, functions_2.bridge)(tx, fromTokenAddress, args);
250
+ }
251
+ else {
252
+ const totalFeeCoin = totalFee === "0"
253
+ ? (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee), useGasCoin: false })
254
+ : (0, transactions_1.coinWithBalance)({ balance: BigInt(totalFee) });
255
+ const args = {
256
+ cctpBridge: suiAddresses.cctpObjectAddress,
257
+ tokenMessengerMinterState: suiAddresses.cctpTokenMessengerMinterStateObjectAddress,
258
+ messageTransmitterState: suiAddresses.cctpMessageTransmitterStateObjectAddress,
259
+ treasury: suiAddresses.cctpTreasuryObjectAddress,
260
+ denyList: suiAddresses.cctpDenyListObjectAddress,
261
+ amount: inputCoin ?? (0, transactions_1.coinWithBalance)({ balance: BigInt(amount), type: fromTokenAddress }),
262
+ destinationChainId: toChainId,
263
+ recipient: recipient,
264
+ recipientWalletAddress: recipientWalletAddress,
265
+ gasOracle: suiAddresses.gasOracleObjectAddress,
266
+ feeTokenCoin: (0, transactions_1.coinWithBalance)({ balance: BigInt(0), type: fromTokenAddress }),
267
+ feeSuiCoin: totalFeeCoin,
268
+ };
269
+ (0, functions_2.bridge)(tx, fromTokenAddress, args);
298
270
  }
299
271
  return await tx.toJSON({ client: this.client });
300
272
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/sui/index.ts"],"names":[],"mappings":";;;AAAA,+CAA2D;AAC3D,2DAA2F;AAC3F,6CAAwD;AACxD,mCAA6B;AAE7B,4CAUyB;AAEzB,gDAAmD;AAEnD,oDAAqD;AACrD,kFAAgH;AAChH,8DAA4E;AAC5E,4FAAsF;AACtF,kDAAuE;AACvE,wEAAmE;AACnE,yDAAmE;AACnE,kGAA0F;AAC1F,sCAA6F;AAC7F,oCAAqG;AAErG,MAAa,gBAAiB,SAAQ,2BAAkB;IAO5C;IACD;IAPT,SAAS,GAAkB,kBAAS,CAAC,GAAG,CAAC;IACzC,WAAW,GAAoB,oBAAW,CAAC,GAAG,CAAC;IAE9B,MAAM,CAAY;IAEnC,YACU,iBA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,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC;gBACnC,MAAM;YACR,CAAC;YACD,KAAK,yBAAgB,CAAC,QAAQ;gBAC5B,MAAM,IAAI,iBAAQ,CAAC,iDAAiD,CAAC,CAAC;YACxE,OAAO,CAAC,CAAC,CAAC;gBACR,OAAO,IAAA,mBAAW,EAAC,mBAAmB,EAAE,4BAA4B,CAAC,CAAC;YACxE,CAAC;QACH,CAAC;QAED,OAAO,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAClD,CAAC;CACF;AAvXD,4CAuXC","sourcesContent":["import { CoinStruct, SuiClient } from \"@mysten/sui/client\";\nimport { coinWithBalance, Transaction, TransactionResult } from \"@mysten/sui/transactions\";\nimport { SUI_CLOCK_OBJECT_ID } from \"@mysten/sui/utils\";\nimport { Big } from \"big.js\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport {\n ChainSymbol,\n ChainType,\n FeePaymentMethod,\n Messenger,\n OFTDoesNotSupportedError,\n RawSuiTransaction,\n SdkError,\n SwapParams,\n TransactionResponse,\n} from \"../../../models\";\nimport { SuiAddresses } from \"../../../tokens-info\";\nimport { assertNever } from \"../../../utils/utils\";\nimport { NodeRpcUrlsConfig } from \"../../index\";\nimport { setAddress } from \"../../models/sui/bridge\";\nimport { swap, swapAndBridge, swapAndBridgeWormhole } from \"../../models/sui/bridge/bridge-interface/functions\";\nimport { setAddress as setCctpAddress } from \"../../models/sui/cctp-bridge\";\nimport { bridge } from \"../../models/sui/cctp-bridge/cctp-bridge-interface/functions\";\nimport { setAddress as setUtilsAddress } from \"../../models/sui/utils\";\nimport { fromHex } from \"../../models/sui/utils/bytes32/functions\";\nimport { fetchAllPagesRecursive } from \"../../utils/sui/paginated\";\nimport { getCctpSolTokenRecipientAddress } from \"../get-cctp-sol-token-recipient-address\";\nimport { ChainBridgeService, SendParams, TxSendParamsSui, TxSwapParamsSui } from \"../models\";\nimport { getNonceBigInt, normalizeSuiHex, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class SuiBridgeService extends ChainBridgeService {\n chainType: ChainType.SUI = ChainType.SUI;\n chainSymbol: ChainSymbol.SUI = ChainSymbol.SUI;\n\n private readonly client: SuiClient;\n\n constructor(\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n public api: AllbridgeCoreClient\n ) {\n super();\n this.client = new SuiClient({\n url: nodeRpcUrlsConfig.getNodeRpcUrl(this.chainSymbol),\n });\n }\n\n send(): Promise<TransactionResponse> {\n throw new SdkError(\"Method send not implemented.\");\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawSuiTransaction> {\n const suiAddresses = params.sourceToken.suiAddresses;\n if (!suiAddresses) {\n throw new SdkError(\"SUI token must contain 'suiAddresses'\");\n }\n setAddress(suiAddresses.bridgeAddress, suiAddresses.bridgeAddressOrigin);\n\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n return await this.buildRawTransactionSwapFromParams(txSwapParams, suiAddresses);\n }\n\n private async buildRawTransactionSwapFromParams(\n params: TxSwapParamsSui,\n suiAddresses: SuiAddresses\n ): Promise<RawSuiTransaction> {\n const { amount, fromAccountAddress, fromTokenAddress, toTokenAddress, minimumReceiveAmount } = params;\n\n const tx = new Transaction();\n tx.setSender(fromAccountAddress);\n\n const args = {\n bridge: suiAddresses.bridgeObjectAddress,\n coin: coinWithBalance({ balance: BigInt(amount), type: fromTokenAddress }),\n receiveAmountMin: BigInt(minimumReceiveAmount),\n };\n const swapResult = swap(tx, [fromTokenAddress, toTokenAddress], args);\n\n const coins: CoinStruct[] = await fetchAllPagesRecursive((cursor: string | null | undefined) =>\n this.client.getCoins({\n owner: params.toAccountAddress,\n coinType: toTokenAddress,\n cursor,\n })\n );\n if (coins.length === 0 || !coins[0]) {\n tx.transferObjects([swapResult], params.toAccountAddress);\n } else {\n tx.mergeCoins(coins[0].coinObjectId, [swapResult]);\n }\n return await tx.toJSON({ client: this.client });\n }\n\n async buildRawTransactionSendFromCustomTx(\n baseTx: string | Uint8Array | Transaction,\n inputCoin: TransactionResult,\n params: SendParams\n ): Promise<RawSuiTransaction> {\n const transaction = Transaction.from(baseTx);\n return this.buildRawTransactionSendFromTx(params, transaction, inputCoin);\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawSuiTransaction> {\n return this.buildRawTransactionSendFromTx(params, new Transaction());\n }\n\n private async buildRawTransactionSendFromTx(\n params: SendParams,\n tx: Transaction,\n inputCoin?: TransactionResult\n ): Promise<RawSuiTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n const { messenger } = txSendParams;\n\n const suiAddresses = params.sourceToken.suiAddresses;\n if (!suiAddresses) {\n throw new SdkError(\"SUI token must contain 'suiAddresses'\");\n }\n setAddress(suiAddresses.bridgeAddress, suiAddresses.bridgeAddressOrigin);\n setUtilsAddress(suiAddresses.utilsAddress);\n\n switch (messenger) {\n case Messenger.ALLBRIDGE:\n return this.buildRawTransactionAllbridgeSend(txSendParams, suiAddresses, tx, inputCoin);\n case Messenger.WORMHOLE:\n return this.buildRawTransactionWormholeSend(txSendParams, suiAddresses, tx, inputCoin);\n case Messenger.CCTP:\n case Messenger.CCTP_V2:\n return this.buildRawTransactionCctpSend(params, txSendParams, suiAddresses, tx, inputCoin);\n case Messenger.OFT:\n throw new OFTDoesNotSupportedError(\"Messenger OFT is not supported yet.\");\n }\n }\n\n private async buildRawTransactionAllbridgeSend(\n txSendParams: TxSendParamsSui,\n suiAddresses: SuiAddresses,\n tx: Transaction,\n inputCoin?: TransactionResult\n ): Promise<RawSuiTransaction> {\n const {\n amount,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n fee,\n gasFeePaymentMethod,\n extraGas,\n } = txSendParams;\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n\n tx.setSender(fromAccountAddress);\n\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n const totalFeeCoin =\n totalFee === \"0\"\n ? coinWithBalance({ balance: BigInt(totalFee), useGasCoin: false })\n : coinWithBalance({ balance: BigInt(totalFee) });\n const args = {\n bridge: suiAddresses.bridgeObjectAddress,\n messenger: suiAddresses.allbridgeMessengerObjectAddress,\n amount: inputCoin ?? coinWithBalance({ balance: BigInt(amount), type: fromTokenAddress }),\n destinationChainId: toChainId,\n nonce: getNonceBigInt(),\n recipient: fromHex(tx, normalizeSuiHex(toAccountAddress)),\n receiveToken: fromHex(tx, normalizeSuiHex(toTokenAddress)),\n gasOracle: suiAddresses.gasOracleObjectAddress,\n feeTokenCoin: coinWithBalance({ balance: BigInt(0), type: fromTokenAddress }),\n feeSuiCoin: totalFeeCoin,\n };\n swapAndBridge(tx, fromTokenAddress, args);\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n const amountWithoutFee = BigInt(amount) - BigInt(totalFee);\n\n let amountCoin, feeTokenCoin;\n if (inputCoin) {\n const [feeTokenCoinS] = tx.splitCoins(inputCoin, [totalFee]);\n amountCoin = inputCoin;\n feeTokenCoin = feeTokenCoinS;\n } else {\n amountCoin = coinWithBalance({ balance: amountWithoutFee, type: fromTokenAddress });\n feeTokenCoin = coinWithBalance({ balance: BigInt(totalFee), type: fromTokenAddress });\n }\n\n const args = {\n bridge: suiAddresses.bridgeObjectAddress,\n messenger: suiAddresses.allbridgeMessengerObjectAddress,\n amount: amountCoin,\n destinationChainId: toChainId,\n nonce: getNonceBigInt(),\n recipient: fromHex(tx, normalizeSuiHex(toAccountAddress)),\n receiveToken: fromHex(tx, normalizeSuiHex(toTokenAddress)),\n gasOracle: suiAddresses.gasOracleObjectAddress,\n feeTokenCoin: feeTokenCoin,\n feeSuiCoin: coinWithBalance({ balance: BigInt(0), useGasCoin: false }),\n };\n swapAndBridge(tx, fromTokenAddress, args);\n break;\n }\n case FeePaymentMethod.WITH_ARB:\n throw new SdkError(\"SUI bridge does not support ARB0 payment method\");\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n\n return await tx.toJSON({ client: this.client });\n }\n\n private async buildRawTransactionWormholeSend(\n txSendParams: TxSendParamsSui,\n suiAddresses: SuiAddresses,\n tx: Transaction,\n inputCoin?: TransactionResult\n ): Promise<RawSuiTransaction> {\n const {\n amount,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n fee,\n gasFeePaymentMethod,\n extraGas,\n } = txSendParams;\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n\n tx.setSender(fromAccountAddress);\n\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n const totalFeeCoin =\n totalFee === \"0\"\n ? coinWithBalance({ balance: BigInt(totalFee), useGasCoin: false })\n : coinWithBalance({ balance: BigInt(totalFee) });\n const args = {\n bridge: suiAddresses.bridgeObjectAddress,\n messenger: suiAddresses.wormholeMessengerObjectAddress,\n wormholeState: suiAddresses.wormholeStateObjectAddress,\n theClock: SUI_CLOCK_OBJECT_ID,\n amount: inputCoin ?? coinWithBalance({ balance: BigInt(amount), type: fromTokenAddress }),\n destinationChainId: toChainId,\n nonce: getNonceBigInt(),\n recipient: fromHex(tx, normalizeSuiHex(toAccountAddress)),\n receiveToken: fromHex(tx, normalizeSuiHex(toTokenAddress)),\n gasOracle: suiAddresses.gasOracleObjectAddress,\n feeTokenCoin: coinWithBalance({ balance: BigInt(0), type: fromTokenAddress }),\n feeSuiCoin: totalFeeCoin,\n };\n swapAndBridgeWormhole(tx, fromTokenAddress, args);\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n const amountWithoutFee = BigInt(amount) - BigInt(totalFee);\n\n let amountCoin, feeTokenCoin;\n if (inputCoin) {\n const [feeTokenCoinS] = tx.splitCoins(inputCoin, [totalFee]);\n amountCoin = inputCoin;\n feeTokenCoin = feeTokenCoinS;\n } else {\n amountCoin = coinWithBalance({ balance: amountWithoutFee, type: fromTokenAddress });\n feeTokenCoin = coinWithBalance({ balance: BigInt(totalFee), type: fromTokenAddress });\n }\n\n const args = {\n bridge: suiAddresses.bridgeObjectAddress,\n messenger: suiAddresses.wormholeMessengerObjectAddress,\n wormholeState: suiAddresses.wormholeStateObjectAddress,\n theClock: SUI_CLOCK_OBJECT_ID,\n amount: amountCoin,\n destinationChainId: toChainId,\n nonce: getNonceBigInt(),\n recipient: fromHex(tx, normalizeSuiHex(toAccountAddress)),\n receiveToken: fromHex(tx, normalizeSuiHex(toTokenAddress)),\n gasOracle: suiAddresses.gasOracleObjectAddress,\n feeTokenCoin: feeTokenCoin,\n feeSuiCoin: coinWithBalance({ balance: BigInt(0), useGasCoin: false }),\n };\n swapAndBridgeWormhole(tx, fromTokenAddress, args);\n break;\n }\n case FeePaymentMethod.WITH_ARB:\n throw new SdkError(\"SUI bridge does not support ARB0 payment method\");\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n return await tx.toJSON({ client: this.client });\n }\n\n private async buildRawTransactionCctpSend(\n params: SendParams,\n txSendParams: TxSendParamsSui,\n suiAddresses: SuiAddresses,\n tx: Transaction,\n inputCoin?: TransactionResult\n ): Promise<RawSuiTransaction> {\n const {\n amount,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n fee,\n gasFeePaymentMethod,\n extraGas,\n } = txSendParams;\n\n setCctpAddress(suiAddresses.cctpAddress, suiAddresses.cctpAddressOrigin);\n\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n\n tx.setSender(fromAccountAddress);\n\n const recipientWalletAddress = fromHex(tx, normalizeSuiHex(toAccountAddress));\n let recipient: TransactionResult;\n if (params.destinationToken.chainType === ChainType.SOLANA) {\n const recipientStr = await getCctpSolTokenRecipientAddress(\n this.chainType,\n params.toAccountAddress,\n params.destinationToken.tokenAddress,\n this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SOL)\n );\n recipient = fromHex(tx, normalizeSuiHex(recipientStr));\n } else {\n recipient = recipientWalletAddress;\n }\n\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n const totalFeeCoin =\n totalFee === \"0\"\n ? coinWithBalance({ balance: BigInt(totalFee), useGasCoin: false })\n : coinWithBalance({ balance: BigInt(totalFee) });\n const args = {\n cctpBridge: suiAddresses.cctpObjectAddress,\n tokenMessengerMinterState: suiAddresses.cctpTokenMessengerMinterStateObjectAddress,\n messageTransmitterState: suiAddresses.cctpMessageTransmitterStateObjectAddress,\n treasury: suiAddresses.cctpTreasuryObjectAddress,\n denyList: suiAddresses.cctpDenyListObjectAddress,\n amount: inputCoin ?? coinWithBalance({ balance: BigInt(amount), type: fromTokenAddress }),\n destinationChainId: toChainId,\n recipient: recipient,\n recipientWalletAddress: recipientWalletAddress,\n gasOracle: suiAddresses.gasOracleObjectAddress,\n feeTokenCoin: coinWithBalance({ balance: BigInt(0), type: fromTokenAddress }),\n feeSuiCoin: totalFeeCoin,\n };\n bridge(tx, fromTokenAddress, args);\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n const amountWithoutFee = BigInt(amount) - BigInt(totalFee);\n\n let amountCoin, feeTokenCoin;\n if (inputCoin) {\n const [feeTokenCoinS] = tx.splitCoins(inputCoin, [totalFee]);\n amountCoin = inputCoin;\n feeTokenCoin = feeTokenCoinS;\n } else {\n amountCoin = coinWithBalance({ balance: amountWithoutFee, type: fromTokenAddress });\n feeTokenCoin = coinWithBalance({ balance: BigInt(totalFee), type: fromTokenAddress });\n }\n\n const args = {\n cctpBridge: suiAddresses.cctpObjectAddress,\n tokenMessengerMinterState: suiAddresses.cctpTokenMessengerMinterStateObjectAddress,\n messageTransmitterState: suiAddresses.cctpMessageTransmitterStateObjectAddress,\n treasury: suiAddresses.cctpTreasuryObjectAddress,\n denyList: suiAddresses.cctpDenyListObjectAddress,\n amount: amountCoin,\n destinationChainId: toChainId,\n recipient: recipient,\n recipientWalletAddress: recipientWalletAddress,\n gasOracle: suiAddresses.gasOracleObjectAddress,\n feeTokenCoin: feeTokenCoin,\n feeSuiCoin: coinWithBalance({ balance: BigInt(0), useGasCoin: false }),\n };\n bridge(tx, fromTokenAddress, args);\n break;\n }\n case FeePaymentMethod.WITH_ARB:\n throw new SdkError(\"SUI bridge does not support ARB0 payment method\");\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n\n return await tx.toJSON({ client: this.client });\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/sui/index.ts"],"names":[],"mappings":";;;AAAA,+CAA+C;AAE/C,2DAA2F;AAC3F,6CAAwD;AACxD,mCAA6B;AAE7B,4CAUyB;AAGzB,oDAAqD;AACrD,kFAAgH;AAChH,8DAA4E;AAC5E,4FAAsF;AACtF,kDAAuE;AACvE,wEAAmE;AACnE,yDAAmE;AACnE,kGAA0F;AAC1F,sCAA6F;AAC7F,oCAAqG;AAErG,MAAa,gBAAiB,SAAQ,2BAAkB;IAO5C;IACD;IAPT,SAAS,GAAkB,kBAAS,CAAC,GAAG,CAAC;IACzC,WAAW,GAAoB,oBAAW,CAAC,GAAG,CAAC;IAE9B,MAAM,CAAY;IAEnC,YACU,iBAAoC,EACrC,GAAwB;QAE/B,KAAK,EAAE,CAAC;QAHA,sBAAiB,GAAjB,iBAAiB,CAAmB;QACrC,QAAG,GAAH,GAAG,CAAqB;QAG/B,IAAI,CAAC,MAAM,GAAG,IAAI,kBAAS,CAAC;YAC1B,GAAG,EAAE,iBAAiB,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC;SACvD,CAAC,CAAC;IACL,CAAC;IAED,IAAI;QACF,MAAM,IAAI,iBAAQ,CAAC,8BAA8B,CAAC,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,M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OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC;gBAC7E,UAAU,EAAE,YAAY;aACzB,CAAC;YACF,IAAA,kBAAM,EAAC,EAAE,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC;QACrC,CAAC;QACD,OAAO,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAClD,CAAC;CACF;AArVD,4CAqVC","sourcesContent":["import { SuiClient } from \"@mysten/sui/client\";\nimport { CoinStruct } from \"@mysten/sui/src/client/types/generated\";\nimport { coinWithBalance, Transaction, TransactionResult } from \"@mysten/sui/transactions\";\nimport { SUI_CLOCK_OBJECT_ID } from \"@mysten/sui/utils\";\nimport { Big } from \"big.js\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport {\n ChainSymbol,\n ChainType,\n FeePaymentMethod,\n Messenger,\n OFTDoesNotSupportedError,\n RawSuiTransaction,\n SdkError,\n SwapParams,\n TransactionResponse,\n} from \"../../../models\";\nimport { SuiAddresses } from \"../../../tokens-info\";\nimport { NodeRpcUrlsConfig } from \"../../index\";\nimport { setAddress } from \"../../models/sui/bridge\";\nimport { swap, swapAndBridge, swapAndBridgeWormhole } from \"../../models/sui/bridge/bridge-interface/functions\";\nimport { setAddress as setCctpAddress } from \"../../models/sui/cctp-bridge\";\nimport { bridge } from \"../../models/sui/cctp-bridge/cctp-bridge-interface/functions\";\nimport { setAddress as setUtilsAddress } from \"../../models/sui/utils\";\nimport { fromHex } from \"../../models/sui/utils/bytes32/functions\";\nimport { fetchAllPagesRecursive } from \"../../utils/sui/paginated\";\nimport { getCctpSolTokenRecipientAddress } from \"../get-cctp-sol-token-recipient-address\";\nimport { ChainBridgeService, SendParams, TxSendParamsSui, TxSwapParamsSui } from \"../models\";\nimport { getNonceBigInt, normalizeSuiHex, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class SuiBridgeService extends ChainBridgeService {\n chainType: ChainType.SUI = ChainType.SUI;\n chainSymbol: ChainSymbol.SUI = ChainSymbol.SUI;\n\n private readonly client: SuiClient;\n\n constructor(\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n public api: AllbridgeCoreClient\n ) {\n super();\n this.client = new SuiClient({\n url: nodeRpcUrlsConfig.getNodeRpcUrl(this.chainSymbol),\n });\n }\n\n send(): Promise<TransactionResponse> {\n throw new SdkError(\"Method send not implemented.\");\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawSuiTransaction> {\n const suiAddresses = params.sourceToken.suiAddresses;\n if (!suiAddresses) {\n throw new SdkError(\"SUI token must contain 'suiAddresses'\");\n }\n setAddress(suiAddresses.bridgeAddress, suiAddresses.bridgeAddressOrigin);\n\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n return await this.buildRawTransactionSwapFromParams(txSwapParams, suiAddresses);\n }\n\n private async buildRawTransactionSwapFromParams(\n params: TxSwapParamsSui,\n suiAddresses: SuiAddresses\n ): Promise<RawSuiTransaction> {\n const { amount, fromAccountAddress, fromTokenAddress, toTokenAddress, minimumReceiveAmount } = params;\n\n const tx = new Transaction();\n tx.setSender(fromAccountAddress);\n\n const args = {\n bridge: suiAddresses.bridgeObjectAddress,\n coin: coinWithBalance({ balance: BigInt(amount), type: fromTokenAddress }),\n receiveAmountMin: BigInt(minimumReceiveAmount),\n };\n const swapResult = swap(tx, [fromTokenAddress, toTokenAddress], args);\n\n const coins: CoinStruct[] = await fetchAllPagesRecursive((cursor: string | null | undefined) =>\n this.client.getCoins({\n owner: params.toAccountAddress,\n coinType: toTokenAddress,\n cursor,\n })\n );\n if (coins.length === 0 || !coins[0]) {\n tx.transferObjects([swapResult], params.toAccountAddress);\n } else {\n tx.mergeCoins(coins[0].coinObjectId, [swapResult]);\n }\n return await tx.toJSON({ client: this.client });\n }\n\n async buildRawTransactionSendFromCustomTx(\n baseTx: string | Uint8Array | Transaction,\n inputCoin: TransactionResult,\n params: SendParams\n ): Promise<RawSuiTransaction> {\n const transaction = Transaction.from(baseTx);\n return this.buildRawTransactionSendFromTx(params, transaction, inputCoin);\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawSuiTransaction> {\n return this.buildRawTransactionSendFromTx(params, new Transaction());\n }\n\n private async buildRawTransactionSendFromTx(\n params: SendParams,\n tx: Transaction,\n inputCoin?: TransactionResult\n ): Promise<RawSuiTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n const { messenger } = txSendParams;\n\n const suiAddresses = params.sourceToken.suiAddresses;\n if (!suiAddresses) {\n throw new SdkError(\"SUI token must contain 'suiAddresses'\");\n }\n setAddress(suiAddresses.bridgeAddress, suiAddresses.bridgeAddressOrigin);\n setUtilsAddress(suiAddresses.utilsAddress);\n\n switch (messenger) {\n case Messenger.ALLBRIDGE:\n return this.buildRawTransactionAllbridgeSend(txSendParams, suiAddresses, tx, inputCoin);\n case Messenger.WORMHOLE:\n return this.buildRawTransactionWormholeSend(txSendParams, suiAddresses, tx, inputCoin);\n case Messenger.CCTP:\n case Messenger.CCTP_V2:\n return this.buildRawTransactionCctpSend(params, txSendParams, suiAddresses, tx, inputCoin);\n case Messenger.OFT:\n throw new OFTDoesNotSupportedError(\"Messenger OFT is not supported yet.\");\n }\n }\n\n private async buildRawTransactionAllbridgeSend(\n txSendParams: TxSendParamsSui,\n suiAddresses: SuiAddresses,\n tx: Transaction,\n inputCoin?: TransactionResult\n ): Promise<RawSuiTransaction> {\n const {\n amount,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n fee,\n gasFeePaymentMethod,\n extraGas,\n } = txSendParams;\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n\n tx.setSender(fromAccountAddress);\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n const amountWithoutFee = BigInt(amount) - BigInt(totalFee);\n\n let amountCoin, feeTokenCoin;\n if (inputCoin) {\n const [feeTokenCoinS] = tx.splitCoins(inputCoin, [totalFee]);\n amountCoin = inputCoin;\n feeTokenCoin = feeTokenCoinS;\n } else {\n amountCoin = coinWithBalance({ balance: amountWithoutFee, type: fromTokenAddress });\n feeTokenCoin = coinWithBalance({ balance: BigInt(totalFee), type: fromTokenAddress });\n }\n\n const args = {\n bridge: suiAddresses.bridgeObjectAddress,\n messenger: suiAddresses.allbridgeMessengerObjectAddress,\n amount: amountCoin,\n destinationChainId: toChainId,\n nonce: getNonceBigInt(),\n recipient: fromHex(tx, normalizeSuiHex(toAccountAddress)),\n receiveToken: fromHex(tx, normalizeSuiHex(toTokenAddress)),\n gasOracle: suiAddresses.gasOracleObjectAddress,\n feeTokenCoin: feeTokenCoin,\n feeSuiCoin: coinWithBalance({ balance: BigInt(0), useGasCoin: false }),\n };\n swapAndBridge(tx, fromTokenAddress, args);\n } else {\n const totalFeeCoin =\n totalFee === \"0\"\n ? coinWithBalance({ balance: BigInt(totalFee), useGasCoin: false })\n : coinWithBalance({ balance: BigInt(totalFee) });\n const args = {\n bridge: suiAddresses.bridgeObjectAddress,\n messenger: suiAddresses.allbridgeMessengerObjectAddress,\n amount: inputCoin ?? coinWithBalance({ balance: BigInt(amount), type: fromTokenAddress }),\n destinationChainId: toChainId,\n nonce: getNonceBigInt(),\n recipient: fromHex(tx, normalizeSuiHex(toAccountAddress)),\n receiveToken: fromHex(tx, normalizeSuiHex(toTokenAddress)),\n gasOracle: suiAddresses.gasOracleObjectAddress,\n feeTokenCoin: coinWithBalance({ balance: BigInt(0), type: fromTokenAddress }),\n feeSuiCoin: totalFeeCoin,\n };\n swapAndBridge(tx, fromTokenAddress, args);\n }\n return await tx.toJSON({ client: this.client });\n }\n\n private async buildRawTransactionWormholeSend(\n txSendParams: TxSendParamsSui,\n suiAddresses: SuiAddresses,\n tx: Transaction,\n inputCoin?: TransactionResult\n ): Promise<RawSuiTransaction> {\n const {\n amount,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n fee,\n gasFeePaymentMethod,\n extraGas,\n } = txSendParams;\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n\n tx.setSender(fromAccountAddress);\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n const amountWithoutFee = BigInt(amount) - BigInt(totalFee);\n\n let amountCoin, feeTokenCoin;\n if (inputCoin) {\n const [feeTokenCoinS] = tx.splitCoins(inputCoin, [totalFee]);\n amountCoin = inputCoin;\n feeTokenCoin = feeTokenCoinS;\n } else {\n amountCoin = coinWithBalance({ balance: amountWithoutFee, type: fromTokenAddress });\n feeTokenCoin = coinWithBalance({ balance: BigInt(totalFee), type: fromTokenAddress });\n }\n\n const args = {\n bridge: suiAddresses.bridgeObjectAddress,\n messenger: suiAddresses.wormholeMessengerObjectAddress,\n wormholeState: suiAddresses.wormholeStateObjectAddress,\n theClock: SUI_CLOCK_OBJECT_ID,\n amount: amountCoin,\n destinationChainId: toChainId,\n nonce: getNonceBigInt(),\n recipient: fromHex(tx, normalizeSuiHex(toAccountAddress)),\n receiveToken: fromHex(tx, normalizeSuiHex(toTokenAddress)),\n gasOracle: suiAddresses.gasOracleObjectAddress,\n feeTokenCoin: feeTokenCoin,\n feeSuiCoin: coinWithBalance({ balance: BigInt(0), useGasCoin: false }),\n };\n swapAndBridgeWormhole(tx, fromTokenAddress, args);\n } else {\n const totalFeeCoin =\n totalFee === \"0\"\n ? coinWithBalance({ balance: BigInt(totalFee), useGasCoin: false })\n : coinWithBalance({ balance: BigInt(totalFee) });\n const args = {\n bridge: suiAddresses.bridgeObjectAddress,\n messenger: suiAddresses.wormholeMessengerObjectAddress,\n wormholeState: suiAddresses.wormholeStateObjectAddress,\n theClock: SUI_CLOCK_OBJECT_ID,\n amount: inputCoin ?? coinWithBalance({ balance: BigInt(amount), type: fromTokenAddress }),\n destinationChainId: toChainId,\n nonce: getNonceBigInt(),\n recipient: fromHex(tx, normalizeSuiHex(toAccountAddress)),\n receiveToken: fromHex(tx, normalizeSuiHex(toTokenAddress)),\n gasOracle: suiAddresses.gasOracleObjectAddress,\n feeTokenCoin: coinWithBalance({ balance: BigInt(0), type: fromTokenAddress }),\n feeSuiCoin: totalFeeCoin,\n };\n swapAndBridgeWormhole(tx, fromTokenAddress, args);\n }\n return await tx.toJSON({ client: this.client });\n }\n\n private async buildRawTransactionCctpSend(\n params: SendParams,\n txSendParams: TxSendParamsSui,\n suiAddresses: SuiAddresses,\n tx: Transaction,\n inputCoin?: TransactionResult\n ): Promise<RawSuiTransaction> {\n const {\n amount,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n fee,\n gasFeePaymentMethod,\n extraGas,\n } = txSendParams;\n\n setCctpAddress(suiAddresses.cctpAddress, suiAddresses.cctpAddressOrigin);\n\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n\n tx.setSender(fromAccountAddress);\n\n const recipientWalletAddress = fromHex(tx, normalizeSuiHex(toAccountAddress));\n let recipient: TransactionResult;\n if (params.destinationToken.chainType === ChainType.SOLANA) {\n const recipientStr = await getCctpSolTokenRecipientAddress(\n this.chainType,\n params.toAccountAddress,\n params.destinationToken.tokenAddress,\n this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SOL)\n );\n recipient = fromHex(tx, normalizeSuiHex(recipientStr));\n } else {\n recipient = recipientWalletAddress;\n }\n\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n const amountWithoutFee = BigInt(amount) - BigInt(totalFee);\n\n let amountCoin, feeTokenCoin;\n if (inputCoin) {\n const [feeTokenCoinS] = tx.splitCoins(inputCoin, [totalFee]);\n amountCoin = inputCoin;\n feeTokenCoin = feeTokenCoinS;\n } else {\n amountCoin = coinWithBalance({ balance: amountWithoutFee, type: fromTokenAddress });\n feeTokenCoin = coinWithBalance({ balance: BigInt(totalFee), type: fromTokenAddress });\n }\n\n const args = {\n cctpBridge: suiAddresses.cctpObjectAddress,\n tokenMessengerMinterState: suiAddresses.cctpTokenMessengerMinterStateObjectAddress,\n messageTransmitterState: suiAddresses.cctpMessageTransmitterStateObjectAddress,\n treasury: suiAddresses.cctpTreasuryObjectAddress,\n denyList: suiAddresses.cctpDenyListObjectAddress,\n amount: amountCoin,\n destinationChainId: toChainId,\n recipient: recipient,\n recipientWalletAddress: recipientWalletAddress,\n gasOracle: suiAddresses.gasOracleObjectAddress,\n feeTokenCoin: feeTokenCoin,\n feeSuiCoin: coinWithBalance({ balance: BigInt(0), useGasCoin: false }),\n };\n bridge(tx, fromTokenAddress, args);\n } else {\n const totalFeeCoin =\n totalFee === \"0\"\n ? coinWithBalance({ balance: BigInt(totalFee), useGasCoin: false })\n : coinWithBalance({ balance: BigInt(totalFee) });\n const args = {\n cctpBridge: suiAddresses.cctpObjectAddress,\n tokenMessengerMinterState: suiAddresses.cctpTokenMessengerMinterStateObjectAddress,\n messageTransmitterState: suiAddresses.cctpMessageTransmitterStateObjectAddress,\n treasury: suiAddresses.cctpTreasuryObjectAddress,\n denyList: suiAddresses.cctpDenyListObjectAddress,\n amount: inputCoin ?? coinWithBalance({ balance: BigInt(amount), type: fromTokenAddress }),\n destinationChainId: toChainId,\n recipient: recipient,\n recipientWalletAddress: recipientWalletAddress,\n gasOracle: suiAddresses.gasOracleObjectAddress,\n feeTokenCoin: coinWithBalance({ balance: BigInt(0), type: fromTokenAddress }),\n feeSuiCoin: totalFeeCoin,\n };\n bridge(tx, fromTokenAddress, args);\n }\n return await tx.toJSON({ client: this.client });\n }\n}\n"]}