@allbridge/bridge-core-sdk 3.27.0-beta.7 → 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.
- package/dist/browser/index.js +1 -6
- package/dist/browser/index.js.map +4 -4
- package/dist/cjs/index.js +1 -6
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +1 -6
- package/dist/esm/index.js.map +4 -4
- package/dist/src/chains/chain.enums.d.ts +2 -12
- package/dist/src/chains/chain.enums.js +0 -10
- package/dist/src/chains/chain.enums.js.map +1 -1
- package/dist/src/chains/index.js +0 -12
- package/dist/src/chains/index.js.map +1 -1
- package/dist/src/client/core-api/api-client.js +0 -1
- package/dist/src/client/core-api/api-client.js.map +1 -1
- package/dist/src/client/core-api/core-api-mapper.js +0 -33
- package/dist/src/client/core-api/core-api-mapper.js.map +1 -1
- package/dist/src/client/core-api/core-api.model.d.ts +2 -14
- package/dist/src/client/core-api/core-api.model.js.map +1 -1
- package/dist/src/configs/mainnet.js +0 -1
- package/dist/src/configs/mainnet.js.map +1 -1
- package/dist/src/index.d.ts +4 -12
- package/dist/src/index.js +11 -11
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/index.d.ts +4 -12
- package/dist/src/models/index.js +0 -4
- package/dist/src/models/index.js.map +1 -1
- package/dist/src/services/bridge/evm/index.d.ts +0 -1
- package/dist/src/services/bridge/evm/index.js +33 -103
- package/dist/src/services/bridge/evm/index.js.map +1 -1
- package/dist/src/services/bridge/index.d.ts +2 -2
- package/dist/src/services/bridge/index.js +4 -31
- package/dist/src/services/bridge/index.js.map +1 -1
- package/dist/src/services/bridge/models/bridge.model.d.ts +4 -13
- package/dist/src/services/bridge/models/bridge.model.js.map +1 -1
- package/dist/src/services/bridge/raw-bridge-transaction-builder.js +1 -1
- package/dist/src/services/bridge/raw-bridge-transaction-builder.js.map +1 -1
- package/dist/src/services/bridge/srb/index.js +28 -36
- package/dist/src/services/bridge/srb/index.js.map +1 -1
- package/dist/src/services/bridge/sui/index.js +138 -166
- package/dist/src/services/bridge/sui/index.js.map +1 -1
- package/dist/src/services/bridge/trx/index.js +70 -98
- package/dist/src/services/bridge/trx/index.js.map +1 -1
- package/dist/src/services/bridge/utils.d.ts +1 -5
- package/dist/src/services/bridge/utils.js +23 -164
- package/dist/src/services/bridge/utils.js.map +1 -1
- package/dist/src/services/liquidity-pool/index.js +0 -21
- package/dist/src/services/liquidity-pool/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/sui/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/trx/index.js.map +1 -1
- package/dist/src/services/models/index.d.ts +5 -7
- package/dist/src/services/models/index.js.map +1 -1
- package/dist/src/services/token/index.js +2 -23
- package/dist/src/services/token/index.js.map +1 -1
- package/dist/src/services/token/models/token.model.d.ts +4 -4
- package/dist/src/services/token/models/token.model.js.map +1 -1
- package/dist/src/services/token/sui/index.js.map +1 -1
- package/dist/src/services/utils/trx/index.js.map +1 -1
- package/dist/src/services/yield/index.js +0 -8
- package/dist/src/services/yield/index.js.map +1 -1
- package/dist/src/tokens-info/tokens-info.model.d.ts +0 -25
- package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
- package/dist/src/utils/index.d.ts +0 -3
- package/dist/src/utils/index.js +0 -3
- package/dist/src/utils/index.js.map +1 -1
- package/dist/src/utils/utils.d.ts +0 -2
- package/dist/src/utils/utils.js +0 -11
- package/dist/src/utils/utils.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/package.json +2 -9
- package/dist/src/services/bridge/alg/index.d.ts +0 -16
- package/dist/src/services/bridge/alg/index.js +0 -191
- package/dist/src/services/bridge/alg/index.js.map +0 -1
- package/dist/src/services/bridge/stx/index.d.ts +0 -16
- package/dist/src/services/bridge/stx/index.js +0 -136
- package/dist/src/services/bridge/stx/index.js.map +0 -1
- package/dist/src/services/liquidity-pool/alg/index.d.ts +0 -19
- package/dist/src/services/liquidity-pool/alg/index.js +0 -135
- package/dist/src/services/liquidity-pool/alg/index.js.map +0 -1
- package/dist/src/services/liquidity-pool/stx/index.d.ts +0 -21
- package/dist/src/services/liquidity-pool/stx/index.js +0 -141
- package/dist/src/services/liquidity-pool/stx/index.js.map +0 -1
- package/dist/src/services/models/abi/PayerWithAbr.d.ts +0 -203
- package/dist/src/services/models/abi/PayerWithAbr.js +0 -266
- package/dist/src/services/models/abi/PayerWithAbr.js.map +0 -1
- package/dist/src/services/models/alg/BridgeClient.d.ts +0 -2751
- package/dist/src/services/models/alg/BridgeClient.js +0 -2685
- package/dist/src/services/models/alg/BridgeClient.js.map +0 -1
- package/dist/src/services/models/alg/PaddingUtilClient.d.ts +0 -654
- package/dist/src/services/models/alg/PaddingUtilClient.js +0 -425
- package/dist/src/services/models/alg/PaddingUtilClient.js.map +0 -1
- package/dist/src/services/models/alg/PoolClient.d.ts +0 -2276
- package/dist/src/services/models/alg/PoolClient.js +0 -2195
- package/dist/src/services/models/alg/PoolClient.js.map +0 -1
- package/dist/src/services/models/stx/clarigen-types.d.ts +0 -657
- package/dist/src/services/models/stx/clarigen-types.js +0 -2296
- package/dist/src/services/models/stx/clarigen-types.js.map +0 -1
- package/dist/src/services/token/alg/index.d.ts +0 -17
- package/dist/src/services/token/alg/index.js +0 -47
- package/dist/src/services/token/alg/index.js.map +0 -1
- package/dist/src/services/token/stx/index.d.ts +0 -20
- package/dist/src/services/token/stx/index.js +0 -59
- package/dist/src/services/token/stx/index.js.map +0 -1
- package/dist/src/services/utils/alg/index.d.ts +0 -9
- package/dist/src/services/utils/alg/index.js +0 -74
- package/dist/src/services/utils/alg/index.js.map +0 -1
- package/dist/src/services/utils/stx/get-token-name.d.ts +0 -2
- package/dist/src/services/utils/stx/get-token-name.js +0 -15
- package/dist/src/services/utils/stx/get-token-name.js.map +0 -1
- package/dist/src/services/utils/stx/post-conditions.d.ts +0 -3
- package/dist/src/services/utils/stx/post-conditions.js +0 -27
- package/dist/src/services/utils/stx/post-conditions.js.map +0 -1
- package/dist/src/utils/alg/index.d.ts +0 -21
- package/dist/src/utils/alg/index.js +0 -71
- package/dist/src/utils/alg/index.js.map +0 -1
|
@@ -5,10 +5,9 @@ const big_js_1 = require("big.js");
|
|
|
5
5
|
const chain_enums_1 = require("../../../chains/chain.enums");
|
|
6
6
|
const exceptions_1 = require("../../../exceptions");
|
|
7
7
|
const models_1 = require("../../../models");
|
|
8
|
-
const utils_1 = require("../../../utils/utils");
|
|
9
8
|
const trx_1 = require("../../utils/trx");
|
|
10
9
|
const bridge_1 = require("../models/bridge");
|
|
11
|
-
const
|
|
10
|
+
const utils_1 = require("../utils");
|
|
12
11
|
class TronBridgeService extends bridge_1.ChainBridgeService {
|
|
13
12
|
tronWeb;
|
|
14
13
|
api;
|
|
@@ -19,12 +18,12 @@ class TronBridgeService extends bridge_1.ChainBridgeService {
|
|
|
19
18
|
this.api = api;
|
|
20
19
|
}
|
|
21
20
|
async send(params) {
|
|
22
|
-
const txSendParams = await (0,
|
|
21
|
+
const txSendParams = await (0, utils_1.prepareTxSendParams)(this.chainType, params, this.api);
|
|
23
22
|
const rawTransaction = await this.buildRawTransactionSendFromParams(params, txSendParams);
|
|
24
23
|
return await (0, trx_1.sendRawTransaction)(this.tronWeb, rawTransaction);
|
|
25
24
|
}
|
|
26
25
|
async buildRawTransactionSwap(params) {
|
|
27
|
-
const txSwapParams = (0,
|
|
26
|
+
const txSwapParams = (0, utils_1.prepareTxSwapParams)(this.chainType, params);
|
|
28
27
|
return await this.buildRawTransactionSwapFromParams(txSwapParams);
|
|
29
28
|
}
|
|
30
29
|
async buildRawTransactionSwapFromParams(params) {
|
|
@@ -40,7 +39,7 @@ class TronBridgeService extends bridge_1.ChainBridgeService {
|
|
|
40
39
|
return this.buildRawTransaction(contractAddress, methodSignature, parameters, "0", fromAccountAddress);
|
|
41
40
|
}
|
|
42
41
|
async buildRawTransactionSend(params) {
|
|
43
|
-
const txSendParams = await (0,
|
|
42
|
+
const txSendParams = await (0, utils_1.prepareTxSendParams)(this.chainType, params, this.api);
|
|
44
43
|
return this.buildRawTransactionSendFromParams(params, txSendParams);
|
|
45
44
|
}
|
|
46
45
|
async buildRawTransactionSendFromParams(sendParams, params) {
|
|
@@ -49,114 +48,87 @@ class TronBridgeService extends bridge_1.ChainBridgeService {
|
|
|
49
48
|
if (extraGas) {
|
|
50
49
|
totalFee = (0, big_js_1.Big)(totalFee).plus(extraGas).toFixed();
|
|
51
50
|
}
|
|
52
|
-
const nonce = (0,
|
|
51
|
+
const nonce = (0, utils_1.getNonceBigInt)().toString();
|
|
53
52
|
let parameters;
|
|
54
53
|
let value;
|
|
55
54
|
let methodSignature;
|
|
56
55
|
switch (messenger) {
|
|
57
56
|
case models_1.Messenger.CCTP:
|
|
58
57
|
case models_1.Messenger.CCTP_V2:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
];
|
|
77
|
-
value = "0";
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
case models_1.FeePaymentMethod.WITH_ARB:
|
|
81
|
-
throw new exceptions_1.SdkError("TRX bridge does not support ARB0 payment method");
|
|
82
|
-
default: {
|
|
83
|
-
return (0, utils_1.assertNever)(gasFeePaymentMethod, "Unhandled FeePaymentMethod");
|
|
84
|
-
}
|
|
58
|
+
if (gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN) {
|
|
59
|
+
parameters = [
|
|
60
|
+
{ type: "uint256", value: amount },
|
|
61
|
+
{ type: "bytes32", value: toAccountAddress },
|
|
62
|
+
{ type: "uint256", value: toChainId },
|
|
63
|
+
{ type: "uint256", value: totalFee },
|
|
64
|
+
];
|
|
65
|
+
value = "0";
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
parameters = [
|
|
69
|
+
{ type: "uint256", value: amount },
|
|
70
|
+
{ type: "bytes32", value: toAccountAddress },
|
|
71
|
+
{ type: "uint256", value: toChainId },
|
|
72
|
+
{ type: "uint256", value: 0 },
|
|
73
|
+
];
|
|
74
|
+
value = totalFee;
|
|
85
75
|
}
|
|
86
76
|
methodSignature = "bridge(uint256,bytes32,uint256,uint256)";
|
|
87
77
|
break;
|
|
88
78
|
case models_1.Messenger.OFT:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
];
|
|
113
|
-
value = "0";
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
case models_1.FeePaymentMethod.WITH_ARB:
|
|
117
|
-
throw new exceptions_1.SdkError("TRX bridge does not support ARB0 payment method");
|
|
118
|
-
default: {
|
|
119
|
-
return (0, utils_1.assertNever)(gasFeePaymentMethod, "Unhandled FeePaymentMethod");
|
|
120
|
-
}
|
|
79
|
+
if (gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN) {
|
|
80
|
+
parameters = [
|
|
81
|
+
{ type: "address", value: sendParams.sourceToken.tokenAddress },
|
|
82
|
+
{ type: "uint256", value: amount },
|
|
83
|
+
{ type: "bytes32", value: toAccountAddress },
|
|
84
|
+
{ type: "uint256", value: toChainId },
|
|
85
|
+
{ type: "uint256", value: totalFee },
|
|
86
|
+
{ type: "uint256", value: extraGasDest ?? "0" },
|
|
87
|
+
{ type: "uint256", value: "10" },
|
|
88
|
+
];
|
|
89
|
+
value = "0";
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
parameters = [
|
|
93
|
+
{ type: "address", value: sendParams.sourceToken.tokenAddress },
|
|
94
|
+
{ type: "uint256", value: amount },
|
|
95
|
+
{ type: "bytes32", value: toAccountAddress },
|
|
96
|
+
{ type: "uint256", value: toChainId },
|
|
97
|
+
{ type: "uint256", value: 0 },
|
|
98
|
+
{ type: "uint256", value: extraGasDest ?? "0" },
|
|
99
|
+
{ type: "uint256", value: "10" },
|
|
100
|
+
];
|
|
101
|
+
value = totalFee;
|
|
121
102
|
}
|
|
122
103
|
methodSignature = "bridge(address,uint256,bytes32,uint256,uint256,uint256,uint256)";
|
|
123
104
|
break;
|
|
124
105
|
case models_1.Messenger.ALLBRIDGE:
|
|
125
106
|
case models_1.Messenger.WORMHOLE:
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
];
|
|
152
|
-
value = "0";
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
case models_1.FeePaymentMethod.WITH_ARB:
|
|
156
|
-
throw new exceptions_1.SdkError("TRX bridge does not support ARB0 payment method");
|
|
157
|
-
default: {
|
|
158
|
-
return (0, utils_1.assertNever)(gasFeePaymentMethod, "Unhandled FeePaymentMethod");
|
|
159
|
-
}
|
|
107
|
+
if (gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN) {
|
|
108
|
+
parameters = [
|
|
109
|
+
{ type: "bytes32", value: fromTokenAddress },
|
|
110
|
+
{ type: "uint256", value: amount },
|
|
111
|
+
{ type: "bytes32", value: toAccountAddress },
|
|
112
|
+
{ type: "uint256", value: toChainId },
|
|
113
|
+
{ type: "bytes32", value: toTokenAddress },
|
|
114
|
+
{ type: "uint256", value: nonce },
|
|
115
|
+
{ type: "uint8", value: messenger },
|
|
116
|
+
{ type: "uint256", value: totalFee },
|
|
117
|
+
];
|
|
118
|
+
value = "0";
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
parameters = [
|
|
122
|
+
{ type: "bytes32", value: fromTokenAddress },
|
|
123
|
+
{ type: "uint256", value: amount },
|
|
124
|
+
{ type: "bytes32", value: toAccountAddress },
|
|
125
|
+
{ type: "uint256", value: toChainId },
|
|
126
|
+
{ type: "bytes32", value: toTokenAddress },
|
|
127
|
+
{ type: "uint256", value: nonce },
|
|
128
|
+
{ type: "uint8", value: messenger },
|
|
129
|
+
{ type: "uint256", value: 0 },
|
|
130
|
+
];
|
|
131
|
+
value = totalFee;
|
|
160
132
|
}
|
|
161
133
|
methodSignature = "swapAndBridge(bytes32,uint256,bytes32,uint256,bytes32,uint256,uint8,uint256)";
|
|
162
134
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/trx/index.ts"],"names":[],"mappings":";;;AAAA,mCAA6B;AAE7B,6DAAwD;AAExD,oDAA+C;AAC/C,4CAA+F;AAC/F,gDAAmD;AAEnD,yCAAqD;AAErD,6CAAsD;AACtD,oCAAoF;AAEpF,MAAa,iBAAkB,SAAQ,2BAAkB;IAI9C;IACA;IAJT,SAAS,GAAkB,uBAAS,CAAC,GAAG,CAAC;IAEzC,YACS,OAAgB,EAChB,GAAwB;QAE/B,KAAK,EAAE,CAAC;QAHD,YAAO,GAAP,OAAO,CAAS;QAChB,QAAG,GAAH,GAAG,CAAqB;IAGjC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAkB;QAC3B,MAAM,YAAY,GAAG,MAAM,IAAA,2BAAmB,EAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,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BACxE,CAAC;gBACH,CAAC;gBACD,eAAe,GAAG,8EAA8E,CAAC;gBACjG,MAAM;QACV,CAAC;QACD,OAAO,IAAI,CAAC,mBAAmB,CAAC,eAAe,EAAE,eAAe,EAAE,UAAU,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC;IAC3G,CAAC;IAEO,KAAK,CAAC,mBAAmB,CAC/B,eAAuB,EACvB,eAAuB,EACvB,UAA0C,EAC1C,KAAa,EACb,WAAmB;QAEnB,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,oBAAoB,CAClF,eAAe,EACf,eAAe,EACf;YACE,SAAS,EAAE,CAAC,KAAK;SAClB,EACD,UAAU,EACV,WAAW,CACZ,CAAC;QACF,IAAI,CAAC,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;YACvC,MAAM,IAAI,qBAAQ,CAAC,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACrF,CAAC;QACD,OAAO,iBAAiB,CAAC,WAAW,CAAC;IACvC,CAAC;CACF;AA7MD,8CA6MC","sourcesContent":["import { Big } from \"big.js\";\nimport { TronWeb } from \"tronweb\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { SdkError } from \"../../../exceptions\";\nimport { FeePaymentMethod, Messenger, SwapParams, TransactionResponse } from \"../../../models\";\nimport { assertNever } from \"../../../utils/utils\";\nimport { RawTransaction, SmartContractMethodParameter } from \"../../models\";\nimport { sendRawTransaction } from \"../../utils/trx\";\nimport { SendParams, TxSendParamsTrx, TxSwapParamsTrx } from \"../models\";\nimport { ChainBridgeService } from \"../models/bridge\";\nimport { getNonceBigInt, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class TronBridgeService extends ChainBridgeService {\n chainType: ChainType.TRX = ChainType.TRX;\n\n constructor(\n public tronWeb: TronWeb,\n public api: AllbridgeCoreClient\n ) {\n super();\n }\n\n async send(params: SendParams): Promise<TransactionResponse> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n const rawTransaction = await this.buildRawTransactionSendFromParams(params, txSendParams);\n return await sendRawTransaction(this.tronWeb, rawTransaction);\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: TxSwapParamsTrx): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toAccountAddress,\n toTokenAddress,\n minimumReceiveAmount,\n } = params;\n\n const parameters = [\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: fromTokenAddress },\n { type: \"bytes32\", value: toTokenAddress },\n { type: \"address\", value: toAccountAddress },\n { type: \"uint256\", value: minimumReceiveAmount },\n ];\n const methodSignature = \"swap(uint256,bytes32,bytes32,address,uint256)\";\n return this.buildRawTransaction(contractAddress, methodSignature, parameters, \"0\", fromAccountAddress);\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n return this.buildRawTransactionSendFromParams(params, txSendParams);\n }\n\n async buildRawTransactionSendFromParams(sendParams: SendParams, params: TxSendParamsTrx): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n messenger,\n fee,\n gasFeePaymentMethod,\n extraGas,\n extraGasDest,\n } = params;\n\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n\n const nonce = getNonceBigInt().toString();\n let parameters;\n let value: string;\n let methodSignature: string;\n switch (messenger) {\n case Messenger.CCTP:\n case Messenger.CCTP_V2:\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n parameters = [\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"uint256\", value: 0 },\n ];\n value = totalFee;\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n parameters = [\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"uint256\", value: totalFee },\n ];\n value = \"0\";\n break;\n }\n case FeePaymentMethod.WITH_ARB:\n throw new SdkError(\"TRX bridge does not support ARB0 payment method\");\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n methodSignature = \"bridge(uint256,bytes32,uint256,uint256)\";\n break;\n case Messenger.OFT:\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n parameters = [\n { type: \"address\", value: sendParams.sourceToken.tokenAddress },\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"uint256\", value: 0 },\n { type: \"uint256\", value: extraGasDest ?? \"0\" },\n { type: \"uint256\", value: \"10\" },\n ];\n value = totalFee;\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n parameters = [\n { type: \"address\", value: sendParams.sourceToken.tokenAddress },\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"uint256\", value: totalFee },\n { type: \"uint256\", value: extraGasDest ?? \"0\" },\n { type: \"uint256\", value: \"10\" },\n ];\n value = \"0\";\n break;\n }\n case FeePaymentMethod.WITH_ARB:\n throw new SdkError(\"TRX bridge does not support ARB0 payment method\");\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n methodSignature = \"bridge(address,uint256,bytes32,uint256,uint256,uint256,uint256)\";\n break;\n case Messenger.ALLBRIDGE:\n case Messenger.WORMHOLE:\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n parameters = [\n { type: \"bytes32\", value: fromTokenAddress },\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"bytes32\", value: toTokenAddress },\n { type: \"uint256\", value: nonce },\n { type: \"uint8\", value: messenger },\n { type: \"uint256\", value: 0 },\n ];\n value = totalFee;\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n parameters = [\n { type: \"bytes32\", value: fromTokenAddress },\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"bytes32\", value: toTokenAddress },\n { type: \"uint256\", value: nonce },\n { type: \"uint8\", value: messenger },\n { type: \"uint256\", value: totalFee },\n ];\n value = \"0\";\n break;\n }\n case FeePaymentMethod.WITH_ARB:\n throw new SdkError(\"TRX bridge does not support ARB0 payment method\");\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n methodSignature = \"swapAndBridge(bytes32,uint256,bytes32,uint256,bytes32,uint256,uint8,uint256)\";\n break;\n }\n return this.buildRawTransaction(contractAddress, methodSignature, parameters, value, fromAccountAddress);\n }\n\n private async buildRawTransaction(\n contractAddress: string,\n methodSignature: string,\n parameters: SmartContractMethodParameter[],\n value: string,\n fromAddress: string\n ): Promise<RawTransaction> {\n const transactionObject = await this.tronWeb.transactionBuilder.triggerSmartContract(\n contractAddress,\n methodSignature,\n {\n callValue: +value,\n },\n parameters,\n fromAddress\n );\n if (!transactionObject?.result?.result) {\n throw new SdkError(\"Unknown error: \" + JSON.stringify(transactionObject, null, 2));\n }\n return transactionObject.transaction;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/trx/index.ts"],"names":[],"mappings":";;;AAAA,mCAA6B;AAE7B,6DAAwD;AAExD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,CAAC,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;YACvC,MAAM,IAAI,qBAAQ,CAAC,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACrF,CAAC;QACD,OAAO,iBAAiB,CAAC,WAAW,CAAC;IACvC,CAAC;CACF;AA/KD,8CA+KC","sourcesContent":["import { Big } from \"big.js\";\nimport { TronWeb } from \"tronweb\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { SdkError } from \"../../../exceptions\";\nimport { FeePaymentMethod, Messenger, SwapParams, TransactionResponse } from \"../../../models\";\nimport { RawTransaction, SmartContractMethodParameter } from \"../../models\";\nimport { sendRawTransaction } from \"../../utils/trx\";\nimport { SendParams, TxSendParamsTrx, TxSwapParamsTrx } from \"../models\";\nimport { ChainBridgeService } from \"../models/bridge\";\nimport { getNonceBigInt, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class TronBridgeService extends ChainBridgeService {\n chainType: ChainType.TRX = ChainType.TRX;\n\n constructor(\n public tronWeb: TronWeb,\n public api: AllbridgeCoreClient\n ) {\n super();\n }\n\n async send(params: SendParams): Promise<TransactionResponse> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n const rawTransaction = await this.buildRawTransactionSendFromParams(params, txSendParams);\n return await sendRawTransaction(this.tronWeb, rawTransaction);\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: TxSwapParamsTrx): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toAccountAddress,\n toTokenAddress,\n minimumReceiveAmount,\n } = params;\n\n const parameters = [\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: fromTokenAddress },\n { type: \"bytes32\", value: toTokenAddress },\n { type: \"address\", value: toAccountAddress },\n { type: \"uint256\", value: minimumReceiveAmount },\n ];\n const methodSignature = \"swap(uint256,bytes32,bytes32,address,uint256)\";\n return this.buildRawTransaction(contractAddress, methodSignature, parameters, \"0\", fromAccountAddress);\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n return this.buildRawTransactionSendFromParams(params, txSendParams);\n }\n\n async buildRawTransactionSendFromParams(sendParams: SendParams, params: TxSendParamsTrx): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n messenger,\n fee,\n gasFeePaymentMethod,\n extraGas,\n extraGasDest,\n } = params;\n\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n\n const nonce = getNonceBigInt().toString();\n let parameters;\n let value: string;\n let methodSignature: string;\n switch (messenger) {\n case Messenger.CCTP:\n case Messenger.CCTP_V2:\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n parameters = [\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"uint256\", value: totalFee },\n ];\n value = \"0\";\n } else {\n parameters = [\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"uint256\", value: 0 },\n ];\n value = totalFee;\n }\n methodSignature = \"bridge(uint256,bytes32,uint256,uint256)\";\n break;\n case Messenger.OFT:\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n parameters = [\n { type: \"address\", value: sendParams.sourceToken.tokenAddress },\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"uint256\", value: totalFee },\n { type: \"uint256\", value: extraGasDest ?? \"0\" },\n { type: \"uint256\", value: \"10\" },\n ];\n value = \"0\";\n } else {\n parameters = [\n { type: \"address\", value: sendParams.sourceToken.tokenAddress },\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"uint256\", value: 0 },\n { type: \"uint256\", value: extraGasDest ?? \"0\" },\n { type: \"uint256\", value: \"10\" },\n ];\n value = totalFee;\n }\n methodSignature = \"bridge(address,uint256,bytes32,uint256,uint256,uint256,uint256)\";\n break;\n case Messenger.ALLBRIDGE:\n case Messenger.WORMHOLE:\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n parameters = [\n { type: \"bytes32\", value: fromTokenAddress },\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"bytes32\", value: toTokenAddress },\n { type: \"uint256\", value: nonce },\n { type: \"uint8\", value: messenger },\n { type: \"uint256\", value: totalFee },\n ];\n value = \"0\";\n } else {\n parameters = [\n { type: \"bytes32\", value: fromTokenAddress },\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"bytes32\", value: toTokenAddress },\n { type: \"uint256\", value: nonce },\n { type: \"uint8\", value: messenger },\n { type: \"uint256\", value: 0 },\n ];\n value = totalFee;\n }\n methodSignature = \"swapAndBridge(bytes32,uint256,bytes32,uint256,bytes32,uint256,uint8,uint256)\";\n break;\n }\n return this.buildRawTransaction(contractAddress, methodSignature, parameters, value, fromAccountAddress);\n }\n\n private async buildRawTransaction(\n contractAddress: string,\n methodSignature: string,\n parameters: SmartContractMethodParameter[],\n value: string,\n fromAddress: string\n ): Promise<RawTransaction> {\n const transactionObject = await this.tronWeb.transactionBuilder.triggerSmartContract(\n contractAddress,\n methodSignature,\n {\n callValue: +value,\n },\n parameters,\n fromAddress\n );\n if (!transactionObject?.result?.result) {\n throw new SdkError(\"Unknown error: \" + JSON.stringify(transactionObject, null, 2));\n }\n return transactionObject.transaction;\n }\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import { Messenger } from "../../client/core-api/core-api.model";
|
|
|
2
2
|
import { AllbridgeCoreClient } from "../../client/core-api/core-client-base";
|
|
3
3
|
import { ChainType, ExtraGasMaxLimitResponse, GasFeeOptions, SwapParams } from "../../models";
|
|
4
4
|
import { ChainDetailsMap, TokenWithChainDetails } from "../../tokens-info";
|
|
5
|
-
import { SendParams, TxSendParams,
|
|
5
|
+
import { SendParams, TxSendParams, TxSendParamsEvm, TxSendParamsSol, TxSendParamsSrb, TxSendParamsSui, TxSendParamsTrx, TxSwapParams, TxSwapParamsEvm, TxSwapParamsSol, TxSwapParamsSrb, TxSwapParamsSui, TxSwapParamsTrx } from "./models";
|
|
6
6
|
export declare function formatAddress(address: string, from: ChainType, to: ChainType.EVM | ChainType.SUI): string;
|
|
7
7
|
export declare function formatAddress(address: string, from: ChainType, to: ChainType.TRX): Buffer;
|
|
8
8
|
export declare function formatAddress(address: string, from: ChainType, to: ChainType.SOLANA | ChainType.SRB): number[];
|
|
@@ -10,8 +10,6 @@ export declare function formatAddress(address: string, from: ChainType, to: Chai
|
|
|
10
10
|
export declare function normalizeSuiHex(hex: string): string;
|
|
11
11
|
export declare function hexToBuffer(hex: string): Buffer;
|
|
12
12
|
export declare function evmAddressToBuffer32(address: string): Buffer;
|
|
13
|
-
export declare function algAddressToBuffer32(address: string): Buffer;
|
|
14
|
-
export declare function stxAddressToBuffer32(address: string): Buffer;
|
|
15
13
|
export declare function tronAddressToBuffer32(address: string): Buffer;
|
|
16
14
|
export declare function tronAddressToEthAddress(address: string): string;
|
|
17
15
|
export declare function getTokenByTokenAddress(chainDetailsMap: ChainDetailsMap, chainSymbol: string, tokenAddress: string): TokenWithChainDetails;
|
|
@@ -23,8 +21,6 @@ export declare function prepareTxSwapParams(bridgeChainType: ChainType.SOLANA |
|
|
|
23
21
|
export declare function prepareTxSwapParams(bridgeChainType: ChainType, params: SwapParams): TxSwapParams;
|
|
24
22
|
export declare function prepareTxSendParams(bridgeChainType: ChainType.EVM | ChainType.SUI, params: SendParams, api: AllbridgeCoreClient): Promise<TxSendParamsEvm | TxSendParamsSui>;
|
|
25
23
|
export declare function prepareTxSendParams(bridgeChainType: ChainType.TRX, params: SendParams, api: AllbridgeCoreClient): Promise<TxSendParamsTrx>;
|
|
26
|
-
export declare function prepareTxSendParams(bridgeChainType: ChainType.ALG, params: SendParams, api: AllbridgeCoreClient): Promise<TxSendParamsAlg>;
|
|
27
|
-
export declare function prepareTxSendParams(bridgeChainType: ChainType.STX, params: SendParams, api: AllbridgeCoreClient): Promise<TxSendParamsStx>;
|
|
28
24
|
export declare function prepareTxSendParams(bridgeChainType: ChainType.SOLANA | ChainType.SRB, params: SendParams, api: AllbridgeCoreClient): Promise<TxSendParamsSol | TxSendParamsSrb>;
|
|
29
25
|
export declare function prepareTxSendParams(bridgeChainType: ChainType, params: SendParams, api: AllbridgeCoreClient): Promise<TxSendParams>;
|
|
30
26
|
export declare function getGasFeeOptions(sourceChainToken: TokenWithChainDetails, destinationAllbridgeChainId: number, messenger: Messenger, api: AllbridgeCoreClient): Promise<GasFeeOptions>;
|
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
@@ -30,8 +7,6 @@ exports.formatAddress = formatAddress;
|
|
|
30
7
|
exports.normalizeSuiHex = normalizeSuiHex;
|
|
31
8
|
exports.hexToBuffer = hexToBuffer;
|
|
32
9
|
exports.evmAddressToBuffer32 = evmAddressToBuffer32;
|
|
33
|
-
exports.algAddressToBuffer32 = algAddressToBuffer32;
|
|
34
|
-
exports.stxAddressToBuffer32 = stxAddressToBuffer32;
|
|
35
10
|
exports.tronAddressToBuffer32 = tronAddressToBuffer32;
|
|
36
11
|
exports.tronAddressToEthAddress = tronAddressToEthAddress;
|
|
37
12
|
exports.getTokenByTokenAddress = getTokenByTokenAddress;
|
|
@@ -43,19 +18,15 @@ exports.getGasFeeOptions = getGasFeeOptions;
|
|
|
43
18
|
exports.getExtraGasMaxLimits = getExtraGasMaxLimits;
|
|
44
19
|
exports.isSendParams = isSendParams;
|
|
45
20
|
const web3_js_1 = require("@solana/web3.js");
|
|
46
|
-
const transactions_1 = require("@stacks/transactions");
|
|
47
21
|
const stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
48
|
-
const algosdk_1 = __importStar(require("algosdk"));
|
|
49
22
|
const big_js_1 = require("big.js");
|
|
50
23
|
const randombytes_1 = __importDefault(require("randombytes"));
|
|
51
24
|
const tronweb_1 = require("tronweb");
|
|
52
|
-
const web3_1 = require("web3");
|
|
53
25
|
const chains_1 = require("../../chains");
|
|
54
26
|
const core_api_model_1 = require("../../client/core-api/core-api.model");
|
|
55
27
|
const exceptions_1 = require("../../exceptions");
|
|
56
28
|
const models_1 = require("../../models");
|
|
57
29
|
const calculation_1 = require("../../utils/calculation");
|
|
58
|
-
const utils_1 = require("../../utils/utils");
|
|
59
30
|
// 2. COMMON Realization
|
|
60
31
|
function formatAddress(address, from, to) {
|
|
61
32
|
let buffer;
|
|
@@ -80,14 +51,6 @@ function formatAddress(address, from, to) {
|
|
|
80
51
|
buffer = evmAddressToBuffer32(address);
|
|
81
52
|
break;
|
|
82
53
|
}
|
|
83
|
-
case models_1.ChainType.ALG: {
|
|
84
|
-
buffer = algAddressToBuffer32(address);
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
case models_1.ChainType.STX: {
|
|
88
|
-
buffer = stxAddressToBuffer32(address);
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
54
|
}
|
|
92
55
|
switch (to) {
|
|
93
56
|
case models_1.ChainType.EVM: {
|
|
@@ -105,12 +68,6 @@ function formatAddress(address, from, to) {
|
|
|
105
68
|
case models_1.ChainType.SUI: {
|
|
106
69
|
return "0x" + buffer.toString("hex");
|
|
107
70
|
}
|
|
108
|
-
case models_1.ChainType.ALG: {
|
|
109
|
-
return buffer;
|
|
110
|
-
}
|
|
111
|
-
case models_1.ChainType.STX: {
|
|
112
|
-
return buffer;
|
|
113
|
-
}
|
|
114
71
|
}
|
|
115
72
|
}
|
|
116
73
|
function normalizeSuiHex(hex) {
|
|
@@ -124,30 +81,6 @@ function evmAddressToBuffer32(address) {
|
|
|
124
81
|
const buff = hexToBuffer(address);
|
|
125
82
|
return Buffer.concat([Buffer.alloc(length - buff.length, 0), buff], length);
|
|
126
83
|
}
|
|
127
|
-
function algAddressToBuffer32(address) {
|
|
128
|
-
if (algosdk_1.default.isValidAddress(address)) {
|
|
129
|
-
return Buffer.from(algosdk_1.Address.fromString(address).publicKey);
|
|
130
|
-
}
|
|
131
|
-
if (/^\d+$/.test(address)) {
|
|
132
|
-
let hex = BigInt(address).toString(16);
|
|
133
|
-
hex = hex.padStart(64, "0");
|
|
134
|
-
return Buffer.from(hex, "hex");
|
|
135
|
-
}
|
|
136
|
-
throw new exceptions_1.SdkError(`Unexpected Alg address: ${address}`);
|
|
137
|
-
}
|
|
138
|
-
function stxAddressToBuffer32(address) {
|
|
139
|
-
if (address.includes(".")) {
|
|
140
|
-
const [addr, name] = (0, transactions_1.parseContractId)(address);
|
|
141
|
-
if (!addr || !name) {
|
|
142
|
-
throw new exceptions_1.SdkError(`Unexpected Alg address: ${address}`);
|
|
143
|
-
}
|
|
144
|
-
const hashBytes = Buffer.from((0, transactions_1.createAddress)(addr).hash160, "hex");
|
|
145
|
-
const hash = web3_1.Web3.utils.keccak256(Buffer.concat([hashBytes, Buffer.from(name)]));
|
|
146
|
-
return hexToBuffer(hash);
|
|
147
|
-
}
|
|
148
|
-
const hashBytes = Buffer.from((0, transactions_1.createAddress)(address).hash160, "hex");
|
|
149
|
-
return bufferToSize(hashBytes, 32);
|
|
150
|
-
}
|
|
151
84
|
function tronAddressToBuffer32(address) {
|
|
152
85
|
const ethAddress = tronAddressToEthAddress(address);
|
|
153
86
|
const buffer = hexToBuffer(ethAddress);
|
|
@@ -195,38 +128,24 @@ function prepareTxSwapParams(bridgeChainType, params) {
|
|
|
195
128
|
txSwapParams.amount = (0, calculation_1.convertFloatAmountToInt)(params.amount, sourceToken.decimals).toFixed();
|
|
196
129
|
txSwapParams.contractAddress = sourceToken.bridgeAddress;
|
|
197
130
|
txSwapParams.fromAccountAddress = params.fromAccountAddress;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
throw new exceptions_1.SdkError("SUI sourceToken must contain 'originTokenAddress'");
|
|
202
|
-
}
|
|
203
|
-
txSwapParams.fromTokenAddress = sourceToken.originTokenAddress;
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
case models_1.ChainType.ALG: {
|
|
207
|
-
txSwapParams.fromTokenAddress = sourceToken.tokenAddress;
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
default: {
|
|
211
|
-
txSwapParams.fromTokenAddress = formatAddress(sourceToken.tokenAddress, bridgeChainType, bridgeChainType);
|
|
131
|
+
if (bridgeChainType === models_1.ChainType.SUI) {
|
|
132
|
+
if (!sourceToken.originTokenAddress) {
|
|
133
|
+
throw new exceptions_1.SdkError("SUI sourceToken must contain 'originTokenAddress'");
|
|
212
134
|
}
|
|
135
|
+
txSwapParams.fromTokenAddress = sourceToken.originTokenAddress;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
txSwapParams.fromTokenAddress = formatAddress(sourceToken.tokenAddress, bridgeChainType, bridgeChainType);
|
|
213
139
|
}
|
|
214
140
|
txSwapParams.toAccountAddress = params.toAccountAddress;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
throw new exceptions_1.SdkError("SUI destinationToken must contain 'originTokenAddress'");
|
|
219
|
-
}
|
|
220
|
-
txSwapParams.toTokenAddress = params.destinationToken.originTokenAddress;
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
case models_1.ChainType.ALG: {
|
|
224
|
-
txSwapParams.toTokenAddress = params.destinationToken.tokenAddress;
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
default: {
|
|
228
|
-
txSwapParams.toTokenAddress = formatAddress(params.destinationToken.tokenAddress, bridgeChainType, bridgeChainType);
|
|
141
|
+
if (bridgeChainType === models_1.ChainType.SUI) {
|
|
142
|
+
if (!params.destinationToken.originTokenAddress) {
|
|
143
|
+
throw new exceptions_1.SdkError("SUI destinationToken must contain 'originTokenAddress'");
|
|
229
144
|
}
|
|
145
|
+
txSwapParams.toTokenAddress = params.destinationToken.originTokenAddress;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
txSwapParams.toTokenAddress = formatAddress(params.destinationToken.tokenAddress, bridgeChainType, bridgeChainType);
|
|
230
149
|
}
|
|
231
150
|
txSwapParams.minimumReceiveAmount = params.minimumReceiveAmount
|
|
232
151
|
? (0, calculation_1.convertFloatAmountToInt)(params.minimumReceiveAmount, params.destinationToken.decimals).toFixed()
|
|
@@ -250,11 +169,12 @@ async function prepareTxSendParams(bridgeChainType, params, api) {
|
|
|
250
169
|
}
|
|
251
170
|
txSendParams.toChainId = params.destinationToken.allbridgeChainId;
|
|
252
171
|
txSendParams.toTokenAddress = params.destinationToken.tokenAddress;
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
172
|
+
if (params.gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN) {
|
|
173
|
+
txSendParams.gasFeePaymentMethod = models_1.FeePaymentMethod.WITH_STABLECOIN;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
// default FeePaymentMethod.WITH_NATIVE_CURRENCY
|
|
177
|
+
txSendParams.gasFeePaymentMethod = models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY;
|
|
258
178
|
}
|
|
259
179
|
const sourceToken = params.sourceToken;
|
|
260
180
|
switch (params.messenger) {
|
|
@@ -305,15 +225,6 @@ async function prepareTxSendParams(bridgeChainType, params, api) {
|
|
|
305
225
|
case models_1.FeePaymentMethod.WITH_STABLECOIN:
|
|
306
226
|
txSendParams.fee = (0, calculation_1.convertFloatAmountToInt)(fee, sourceToken.decimals).toFixed(0);
|
|
307
227
|
break;
|
|
308
|
-
case models_1.FeePaymentMethod.WITH_ARB:
|
|
309
|
-
if (!sourceToken.abrPayer) {
|
|
310
|
-
throw new exceptions_1.SdkError("Source token must contain 'abrPayer' for ARB0 payment method");
|
|
311
|
-
}
|
|
312
|
-
txSendParams.fee = (0, calculation_1.convertFloatAmountToInt)(fee, sourceToken.abrPayer.abrToken.decimals).toFixed(0);
|
|
313
|
-
break;
|
|
314
|
-
default: {
|
|
315
|
-
return (0, utils_1.assertNever)(txSendParams.gasFeePaymentMethod, "Unhandled FeePaymentMethod");
|
|
316
|
-
}
|
|
317
228
|
}
|
|
318
229
|
}
|
|
319
230
|
else {
|
|
@@ -334,19 +245,6 @@ async function prepareTxSendParams(bridgeChainType, params, api) {
|
|
|
334
245
|
extraGasDecimals = sourceToken.decimals;
|
|
335
246
|
extraGasDestRate = (0, big_js_1.Big)(extraGasLimits.exchangeRate).div(extraGasLimits.sourceNativeTokenPrice);
|
|
336
247
|
break;
|
|
337
|
-
case models_1.FeePaymentMethod.WITH_ARB:
|
|
338
|
-
if (!sourceToken.abrPayer) {
|
|
339
|
-
throw new exceptions_1.SdkError("Source token must contain 'abrPayer' for ARB0 payment method");
|
|
340
|
-
}
|
|
341
|
-
if (!extraGasLimits.abrExchangeRate) {
|
|
342
|
-
throw new exceptions_1.SdkError("Cannot transfer WITH_ARB option");
|
|
343
|
-
}
|
|
344
|
-
extraGasDecimals = sourceToken.abrPayer.abrToken.decimals;
|
|
345
|
-
extraGasDestRate = (0, big_js_1.Big)(extraGasLimits.exchangeRate).div(extraGasLimits.abrExchangeRate);
|
|
346
|
-
break;
|
|
347
|
-
default: {
|
|
348
|
-
return (0, utils_1.assertNever)(txSendParams.gasFeePaymentMethod, "Unhandled FeePaymentMethod");
|
|
349
|
-
}
|
|
350
248
|
}
|
|
351
249
|
switch (extraGasFormat ?? models_1.AmountFormat.INT) {
|
|
352
250
|
case models_1.AmountFormat.FLOAT: {
|
|
@@ -365,29 +263,13 @@ async function prepareTxSendParams(bridgeChainType, params, api) {
|
|
|
365
263
|
}
|
|
366
264
|
validateExtraGasNotExceeded(txSendParams.extraGas, txSendParams.gasFeePaymentMethod, extraGasLimits);
|
|
367
265
|
}
|
|
368
|
-
if (
|
|
266
|
+
if (bridgeChainType !== models_1.ChainType.SUI) {
|
|
369
267
|
txSendParams.fromTokenAddress = formatAddress(txSendParams.fromTokenAddress, bridgeChainType, bridgeChainType);
|
|
370
268
|
}
|
|
371
269
|
txSendParams.toAccountAddress = formatAddress(params.toAccountAddress, toChainType, bridgeChainType);
|
|
372
270
|
txSendParams.toTokenAddress = formatAddress(txSendParams.toTokenAddress, toChainType, bridgeChainType);
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
break;
|
|
376
|
-
case models_1.FeePaymentMethod.WITH_STABLECOIN:
|
|
377
|
-
validateAmountEnough(txSendParams.amount, sourceToken.decimals, txSendParams.fee, txSendParams.extraGas);
|
|
378
|
-
break;
|
|
379
|
-
case models_1.FeePaymentMethod.WITH_ARB: {
|
|
380
|
-
const { abrExchangeRate } = await api.getReceiveTransactionCost({
|
|
381
|
-
sourceChainId: txSendParams.fromChainId,
|
|
382
|
-
destinationChainId: txSendParams.toChainId,
|
|
383
|
-
messenger: txSendParams.messenger,
|
|
384
|
-
sourceToken: params.sourceToken.tokenAddress,
|
|
385
|
-
});
|
|
386
|
-
txSendParams.abrExchangeRate = abrExchangeRate;
|
|
387
|
-
break;
|
|
388
|
-
}
|
|
389
|
-
default:
|
|
390
|
-
return (0, utils_1.assertNever)(txSendParams.gasFeePaymentMethod, "Unhandled FeePaymentMethod");
|
|
271
|
+
if (txSendParams.gasFeePaymentMethod == models_1.FeePaymentMethod.WITH_STABLECOIN) {
|
|
272
|
+
validateAmountEnough(txSendParams.amount, sourceToken.decimals, txSendParams.fee, txSendParams.extraGas);
|
|
391
273
|
}
|
|
392
274
|
return txSendParams;
|
|
393
275
|
}
|
|
@@ -420,15 +302,6 @@ async function getGasFeeOptions(sourceChainToken, destinationAllbridgeChainId, m
|
|
|
420
302
|
[models_1.AmountFormat.FLOAT]: (0, calculation_1.convertIntAmountToFloat)(gasFeeIntWithStables, sourceChainToken.decimals).toFixed(),
|
|
421
303
|
};
|
|
422
304
|
}
|
|
423
|
-
if (transactionCostResponse.abrExchangeRate &&
|
|
424
|
-
sourceChainToken.abrPayer &&
|
|
425
|
-
sourceChainToken.abrPayer.payerAvailability[messenger]) {
|
|
426
|
-
const gasFeeIntWithStables = (0, calculation_1.convertAmountPrecision)(new big_js_1.Big(transactionCostResponse.fee).mul(transactionCostResponse.abrExchangeRate), chains_1.Chains.getChainDecimalsByType(sourceChainToken.chainType), sourceChainToken.abrPayer.abrToken.decimals).toFixed(0, big_js_1.Big.roundUp);
|
|
427
|
-
gasFeeOptions[models_1.FeePaymentMethod.WITH_ARB] = {
|
|
428
|
-
[models_1.AmountFormat.INT]: gasFeeIntWithStables,
|
|
429
|
-
[models_1.AmountFormat.FLOAT]: (0, calculation_1.convertIntAmountToFloat)(gasFeeIntWithStables, sourceChainToken.abrPayer.abrToken.decimals).toFixed(),
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
305
|
return gasFeeOptions;
|
|
433
306
|
}
|
|
434
307
|
function validateExtraGasNotExceeded(extraGasInt, gasFeePaymentMethod, extraGasLimits) {
|
|
@@ -468,19 +341,6 @@ async function getExtraGasMaxLimits(sourceChainToken, destinationChainToken, mes
|
|
|
468
341
|
[models_1.AmountFormat.FLOAT]: maxAmountFloatInStable,
|
|
469
342
|
};
|
|
470
343
|
}
|
|
471
|
-
let abrAvailable;
|
|
472
|
-
if (transactionCostResponse.abrExchangeRate &&
|
|
473
|
-
sourceChainToken.abrPayer &&
|
|
474
|
-
sourceChainToken.abrPayer.payerAvailability[messenger]) {
|
|
475
|
-
abrAvailable = true;
|
|
476
|
-
const maxAmountFloatInStable = (0, big_js_1.Big)(maxAmountFloatInSourceNative)
|
|
477
|
-
.mul(transactionCostResponse.abrExchangeRate)
|
|
478
|
-
.toFixed(sourceChainToken.abrPayer.abrToken.decimals, big_js_1.Big.roundDown);
|
|
479
|
-
extraGasMaxLimits[models_1.FeePaymentMethod.WITH_ARB] = {
|
|
480
|
-
[models_1.AmountFormat.INT]: (0, calculation_1.convertFloatAmountToInt)(maxAmountFloatInStable, sourceChainToken.abrPayer.abrToken.decimals).toFixed(0),
|
|
481
|
-
[models_1.AmountFormat.FLOAT]: maxAmountFloatInStable,
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
344
|
return {
|
|
485
345
|
extraGasMax: extraGasMaxLimits,
|
|
486
346
|
destinationChain: {
|
|
@@ -498,7 +358,6 @@ async function getExtraGasMaxLimits(sourceChainToken, destinationChainToken, mes
|
|
|
498
358
|
},
|
|
499
359
|
},
|
|
500
360
|
exchangeRate: transactionCostResponse.exchangeRate,
|
|
501
|
-
abrExchangeRate: abrAvailable ? transactionCostResponse.abrExchangeRate : undefined,
|
|
502
361
|
sourceNativeTokenPrice: transactionCostResponse.sourceNativeTokenPrice,
|
|
503
362
|
};
|
|
504
363
|
}
|