@allbridge/bridge-core-sdk 3.27.0-alpha.2 → 3.27.0-alpha.20
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 +3 -3
- package/dist/browser/index.js.map +4 -4
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +4 -4
- package/dist/src/chains/chain.enums.d.ts +7 -2
- package/dist/src/chains/chain.enums.js +5 -0
- package/dist/src/chains/chain.enums.js.map +1 -1
- package/dist/src/chains/index.js +6 -0
- package/dist/src/chains/index.js.map +1 -1
- package/dist/src/client/core-api/api-client.js +1 -0
- package/dist/src/client/core-api/api-client.js.map +1 -1
- package/dist/src/client/core-api/core-api-mapper.js +32 -0
- package/dist/src/client/core-api/core-api-mapper.js.map +1 -1
- package/dist/src/client/core-api/core-api.model.d.ts +13 -2
- package/dist/src/client/core-api/core-api.model.js.map +1 -1
- package/dist/src/configs/mainnet.js +1 -0
- package/dist/src/configs/mainnet.js.map +1 -1
- package/dist/src/index.d.ts +6 -4
- package/dist/src/index.js +5 -11
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/index.d.ts +12 -4
- package/dist/src/models/index.js +4 -0
- package/dist/src/models/index.js.map +1 -1
- package/dist/src/services/bridge/alg/index.d.ts +1 -0
- package/dist/src/services/bridge/alg/index.js +79 -43
- package/dist/src/services/bridge/alg/index.js.map +1 -1
- package/dist/src/services/bridge/evm/index.d.ts +1 -0
- package/dist/src/services/bridge/evm/index.js +103 -33
- 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 +15 -4
- package/dist/src/services/bridge/index.js.map +1 -1
- package/dist/src/services/bridge/models/bridge.model.d.ts +12 -4
- 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 +36 -28
- package/dist/src/services/bridge/srb/index.js.map +1 -1
- package/dist/src/services/bridge/stx/index.d.ts +16 -0
- package/dist/src/services/bridge/stx/index.js +136 -0
- package/dist/src/services/bridge/stx/index.js.map +1 -0
- package/dist/src/services/bridge/sui/index.js +166 -138
- package/dist/src/services/bridge/sui/index.js.map +1 -1
- package/dist/src/services/bridge/trx/index.js +98 -70
- package/dist/src/services/bridge/trx/index.js.map +1 -1
- package/dist/src/services/bridge/utils.d.ts +3 -1
- package/dist/src/services/bridge/utils.js +92 -8
- package/dist/src/services/bridge/utils.js.map +1 -1
- package/dist/src/services/liquidity-pool/alg/index.js +10 -17
- package/dist/src/services/liquidity-pool/alg/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/index.js +5 -0
- package/dist/src/services/liquidity-pool/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/stx/index.d.ts +21 -0
- package/dist/src/services/liquidity-pool/stx/index.js +141 -0
- package/dist/src/services/liquidity-pool/stx/index.js.map +1 -0
- package/dist/src/services/models/abi/PayerWithAbr.d.ts +203 -0
- package/dist/src/services/models/abi/PayerWithAbr.js +266 -0
- package/dist/src/services/models/abi/PayerWithAbr.js.map +1 -0
- package/dist/src/services/models/alg/BridgeClient.d.ts +158 -133
- package/dist/src/services/models/alg/BridgeClient.js +182 -130
- package/dist/src/services/models/alg/BridgeClient.js.map +1 -1
- package/dist/src/services/models/alg/PaddingUtilClient.d.ts +639 -0
- package/dist/src/services/models/alg/PaddingUtilClient.js +425 -0
- package/dist/src/services/models/alg/PaddingUtilClient.js.map +1 -0
- package/dist/src/services/models/alg/PoolClient.d.ts +204 -201
- package/dist/src/services/models/alg/PoolClient.js +234 -215
- package/dist/src/services/models/alg/PoolClient.js.map +1 -1
- package/dist/src/services/models/index.d.ts +2 -1
- package/dist/src/services/models/index.js.map +1 -1
- package/dist/src/services/models/stx/clarigen-types.d.ts +657 -0
- package/dist/src/services/models/stx/clarigen-types.js +2296 -0
- package/dist/src/services/models/stx/clarigen-types.js.map +1 -0
- package/dist/src/services/token/index.js +7 -2
- 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/stx/index.d.ts +20 -0
- package/dist/src/services/token/stx/index.js +59 -0
- package/dist/src/services/token/stx/index.js.map +1 -0
- package/dist/src/services/utils/alg/index.d.ts +1 -10
- package/dist/src/services/utils/alg/index.js +0 -20
- package/dist/src/services/utils/alg/index.js.map +1 -1
- package/dist/src/services/utils/stx/get-token-name.d.ts +2 -0
- package/dist/src/services/utils/stx/get-token-name.js +15 -0
- package/dist/src/services/utils/stx/get-token-name.js.map +1 -0
- package/dist/src/services/utils/stx/post-conditions.d.ts +3 -0
- package/dist/src/services/utils/stx/post-conditions.js +27 -0
- package/dist/src/services/utils/stx/post-conditions.js.map +1 -0
- package/dist/src/services/yield/index.js +4 -0
- package/dist/src/services/yield/index.js.map +1 -1
- package/dist/src/tokens-info/tokens-info.model.d.ts +21 -0
- package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
- package/dist/src/utils/utils.d.ts +2 -0
- package/dist/src/utils/utils.js +11 -0
- 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 +6 -2
|
@@ -5,9 +5,10 @@ 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");
|
|
8
9
|
const trx_1 = require("../../utils/trx");
|
|
9
10
|
const bridge_1 = require("../models/bridge");
|
|
10
|
-
const
|
|
11
|
+
const utils_2 = require("../utils");
|
|
11
12
|
class TronBridgeService extends bridge_1.ChainBridgeService {
|
|
12
13
|
tronWeb;
|
|
13
14
|
api;
|
|
@@ -18,12 +19,12 @@ class TronBridgeService extends bridge_1.ChainBridgeService {
|
|
|
18
19
|
this.api = api;
|
|
19
20
|
}
|
|
20
21
|
async send(params) {
|
|
21
|
-
const txSendParams = await (0,
|
|
22
|
+
const txSendParams = await (0, utils_2.prepareTxSendParams)(this.chainType, params, this.api);
|
|
22
23
|
const rawTransaction = await this.buildRawTransactionSendFromParams(params, txSendParams);
|
|
23
24
|
return await (0, trx_1.sendRawTransaction)(this.tronWeb, rawTransaction);
|
|
24
25
|
}
|
|
25
26
|
async buildRawTransactionSwap(params) {
|
|
26
|
-
const txSwapParams = (0,
|
|
27
|
+
const txSwapParams = (0, utils_2.prepareTxSwapParams)(this.chainType, params);
|
|
27
28
|
return await this.buildRawTransactionSwapFromParams(txSwapParams);
|
|
28
29
|
}
|
|
29
30
|
async buildRawTransactionSwapFromParams(params) {
|
|
@@ -39,7 +40,7 @@ class TronBridgeService extends bridge_1.ChainBridgeService {
|
|
|
39
40
|
return this.buildRawTransaction(contractAddress, methodSignature, parameters, "0", fromAccountAddress);
|
|
40
41
|
}
|
|
41
42
|
async buildRawTransactionSend(params) {
|
|
42
|
-
const txSendParams = await (0,
|
|
43
|
+
const txSendParams = await (0, utils_2.prepareTxSendParams)(this.chainType, params, this.api);
|
|
43
44
|
return this.buildRawTransactionSendFromParams(params, txSendParams);
|
|
44
45
|
}
|
|
45
46
|
async buildRawTransactionSendFromParams(sendParams, params) {
|
|
@@ -48,87 +49,114 @@ class TronBridgeService extends bridge_1.ChainBridgeService {
|
|
|
48
49
|
if (extraGas) {
|
|
49
50
|
totalFee = (0, big_js_1.Big)(totalFee).plus(extraGas).toFixed();
|
|
50
51
|
}
|
|
51
|
-
const nonce = (0,
|
|
52
|
+
const nonce = (0, utils_2.getNonceBigInt)().toString();
|
|
52
53
|
let parameters;
|
|
53
54
|
let value;
|
|
54
55
|
let methodSignature;
|
|
55
56
|
switch (messenger) {
|
|
56
57
|
case models_1.Messenger.CCTP:
|
|
57
58
|
case models_1.Messenger.CCTP_V2:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
59
|
+
switch (gasFeePaymentMethod) {
|
|
60
|
+
case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY: {
|
|
61
|
+
parameters = [
|
|
62
|
+
{ type: "uint256", value: amount },
|
|
63
|
+
{ type: "bytes32", value: toAccountAddress },
|
|
64
|
+
{ type: "uint256", value: toChainId },
|
|
65
|
+
{ type: "uint256", value: 0 },
|
|
66
|
+
];
|
|
67
|
+
value = totalFee;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case models_1.FeePaymentMethod.WITH_STABLECOIN: {
|
|
71
|
+
parameters = [
|
|
72
|
+
{ type: "uint256", value: amount },
|
|
73
|
+
{ type: "bytes32", value: toAccountAddress },
|
|
74
|
+
{ type: "uint256", value: toChainId },
|
|
75
|
+
{ type: "uint256", value: totalFee },
|
|
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
|
+
}
|
|
75
85
|
}
|
|
76
86
|
methodSignature = "bridge(uint256,bytes32,uint256,uint256)";
|
|
77
87
|
break;
|
|
78
88
|
case models_1.Messenger.OFT:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
89
|
+
switch (gasFeePaymentMethod) {
|
|
90
|
+
case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY: {
|
|
91
|
+
parameters = [
|
|
92
|
+
{ type: "address", value: sendParams.sourceToken.tokenAddress },
|
|
93
|
+
{ type: "uint256", value: amount },
|
|
94
|
+
{ type: "bytes32", value: toAccountAddress },
|
|
95
|
+
{ type: "uint256", value: toChainId },
|
|
96
|
+
{ type: "uint256", value: 0 },
|
|
97
|
+
{ type: "uint256", value: extraGasDest ?? "0" },
|
|
98
|
+
{ type: "uint256", value: "10" },
|
|
99
|
+
];
|
|
100
|
+
value = totalFee;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case models_1.FeePaymentMethod.WITH_STABLECOIN: {
|
|
104
|
+
parameters = [
|
|
105
|
+
{ type: "address", value: sendParams.sourceToken.tokenAddress },
|
|
106
|
+
{ type: "uint256", value: amount },
|
|
107
|
+
{ type: "bytes32", value: toAccountAddress },
|
|
108
|
+
{ type: "uint256", value: toChainId },
|
|
109
|
+
{ type: "uint256", value: totalFee },
|
|
110
|
+
{ type: "uint256", value: extraGasDest ?? "0" },
|
|
111
|
+
{ type: "uint256", value: "10" },
|
|
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
|
+
}
|
|
102
121
|
}
|
|
103
122
|
methodSignature = "bridge(address,uint256,bytes32,uint256,uint256,uint256,uint256)";
|
|
104
123
|
break;
|
|
105
124
|
case models_1.Messenger.ALLBRIDGE:
|
|
106
125
|
case models_1.Messenger.WORMHOLE:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
126
|
+
switch (gasFeePaymentMethod) {
|
|
127
|
+
case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY: {
|
|
128
|
+
parameters = [
|
|
129
|
+
{ type: "bytes32", value: fromTokenAddress },
|
|
130
|
+
{ type: "uint256", value: amount },
|
|
131
|
+
{ type: "bytes32", value: toAccountAddress },
|
|
132
|
+
{ type: "uint256", value: toChainId },
|
|
133
|
+
{ type: "bytes32", value: toTokenAddress },
|
|
134
|
+
{ type: "uint256", value: nonce },
|
|
135
|
+
{ type: "uint8", value: messenger },
|
|
136
|
+
{ type: "uint256", value: 0 },
|
|
137
|
+
];
|
|
138
|
+
value = totalFee;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
case models_1.FeePaymentMethod.WITH_STABLECOIN: {
|
|
142
|
+
parameters = [
|
|
143
|
+
{ type: "bytes32", value: fromTokenAddress },
|
|
144
|
+
{ type: "uint256", value: amount },
|
|
145
|
+
{ type: "bytes32", value: toAccountAddress },
|
|
146
|
+
{ type: "uint256", value: toChainId },
|
|
147
|
+
{ type: "bytes32", value: toTokenAddress },
|
|
148
|
+
{ type: "uint256", value: nonce },
|
|
149
|
+
{ type: "uint8", value: messenger },
|
|
150
|
+
{ type: "uint256", value: totalFee },
|
|
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
|
+
}
|
|
132
160
|
}
|
|
133
161
|
methodSignature = "swapAndBridge(bytes32,uint256,bytes32,uint256,bytes32,uint256,uint8,uint256)";
|
|
134
162
|
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;AAE/F,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,CAAC,CAAC;QACjF,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,iCAAiC,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAC1F,OAAO,MAAM,IAAA,wBAAkB,EAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,MAAkB;QAC9C,MAAM,YAAY,GAAG,IAAA,2BAAmB,EAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QACjE,OAAO,MAAM,IAAI,C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,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;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"]}
|
|
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,CAAC,CAAC;QACjF,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,iCAAiC,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAC1F,OAAO,MAAM,I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AAe,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"]}
|
|
@@ -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, TxSendParamsAlg, TxSendParamsEvm, TxSendParamsSol, TxSendParamsSrb, TxSendParamsSui, TxSendParamsTrx, TxSwapParams, TxSwapParamsEvm, TxSwapParamsSol, TxSwapParamsSrb, TxSwapParamsSui, TxSwapParamsTrx } from "./models";
|
|
5
|
+
import { SendParams, TxSendParams, TxSendParamsAlg, TxSendParamsEvm, TxSendParamsSol, TxSendParamsSrb, TxSendParamsStx, 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[];
|
|
@@ -11,6 +11,7 @@ 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
13
|
export declare function algAddressToBuffer32(address: string): Buffer;
|
|
14
|
+
export declare function stxAddressToBuffer32(address: string): Buffer;
|
|
14
15
|
export declare function tronAddressToBuffer32(address: string): Buffer;
|
|
15
16
|
export declare function tronAddressToEthAddress(address: string): string;
|
|
16
17
|
export declare function getTokenByTokenAddress(chainDetailsMap: ChainDetailsMap, chainSymbol: string, tokenAddress: string): TokenWithChainDetails;
|
|
@@ -23,6 +24,7 @@ export declare function prepareTxSwapParams(bridgeChainType: ChainType, params:
|
|
|
23
24
|
export declare function prepareTxSendParams(bridgeChainType: ChainType.EVM | ChainType.SUI, params: SendParams, api: AllbridgeCoreClient): Promise<TxSendParamsEvm | TxSendParamsSui>;
|
|
24
25
|
export declare function prepareTxSendParams(bridgeChainType: ChainType.TRX, params: SendParams, api: AllbridgeCoreClient): Promise<TxSendParamsTrx>;
|
|
25
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>;
|
|
26
28
|
export declare function prepareTxSendParams(bridgeChainType: ChainType.SOLANA | ChainType.SRB, params: SendParams, api: AllbridgeCoreClient): Promise<TxSendParamsSol | TxSendParamsSrb>;
|
|
27
29
|
export declare function prepareTxSendParams(bridgeChainType: ChainType, params: SendParams, api: AllbridgeCoreClient): Promise<TxSendParams>;
|
|
28
30
|
export declare function getGasFeeOptions(sourceChainToken: TokenWithChainDetails, destinationAllbridgeChainId: number, messenger: Messenger, api: AllbridgeCoreClient): Promise<GasFeeOptions>;
|
|
@@ -31,6 +31,7 @@ exports.normalizeSuiHex = normalizeSuiHex;
|
|
|
31
31
|
exports.hexToBuffer = hexToBuffer;
|
|
32
32
|
exports.evmAddressToBuffer32 = evmAddressToBuffer32;
|
|
33
33
|
exports.algAddressToBuffer32 = algAddressToBuffer32;
|
|
34
|
+
exports.stxAddressToBuffer32 = stxAddressToBuffer32;
|
|
34
35
|
exports.tronAddressToBuffer32 = tronAddressToBuffer32;
|
|
35
36
|
exports.tronAddressToEthAddress = tronAddressToEthAddress;
|
|
36
37
|
exports.getTokenByTokenAddress = getTokenByTokenAddress;
|
|
@@ -42,16 +43,19 @@ exports.getGasFeeOptions = getGasFeeOptions;
|
|
|
42
43
|
exports.getExtraGasMaxLimits = getExtraGasMaxLimits;
|
|
43
44
|
exports.isSendParams = isSendParams;
|
|
44
45
|
const web3_js_1 = require("@solana/web3.js");
|
|
46
|
+
const transactions_1 = require("@stacks/transactions");
|
|
45
47
|
const stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
46
48
|
const algosdk_1 = __importStar(require("algosdk"));
|
|
47
49
|
const big_js_1 = require("big.js");
|
|
48
50
|
const randombytes_1 = __importDefault(require("randombytes"));
|
|
49
51
|
const tronweb_1 = require("tronweb");
|
|
52
|
+
const web3_1 = require("web3");
|
|
50
53
|
const chains_1 = require("../../chains");
|
|
51
54
|
const core_api_model_1 = require("../../client/core-api/core-api.model");
|
|
52
55
|
const exceptions_1 = require("../../exceptions");
|
|
53
56
|
const models_1 = require("../../models");
|
|
54
57
|
const calculation_1 = require("../../utils/calculation");
|
|
58
|
+
const utils_1 = require("../../utils/utils");
|
|
55
59
|
// 2. COMMON Realization
|
|
56
60
|
function formatAddress(address, from, to) {
|
|
57
61
|
let buffer;
|
|
@@ -80,6 +84,10 @@ function formatAddress(address, from, to) {
|
|
|
80
84
|
buffer = algAddressToBuffer32(address);
|
|
81
85
|
break;
|
|
82
86
|
}
|
|
87
|
+
case models_1.ChainType.STX: {
|
|
88
|
+
buffer = stxAddressToBuffer32(address);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
83
91
|
}
|
|
84
92
|
switch (to) {
|
|
85
93
|
case models_1.ChainType.EVM: {
|
|
@@ -100,6 +108,9 @@ function formatAddress(address, from, to) {
|
|
|
100
108
|
case models_1.ChainType.ALG: {
|
|
101
109
|
return buffer;
|
|
102
110
|
}
|
|
111
|
+
case models_1.ChainType.STX: {
|
|
112
|
+
return buffer;
|
|
113
|
+
}
|
|
103
114
|
}
|
|
104
115
|
}
|
|
105
116
|
function normalizeSuiHex(hex) {
|
|
@@ -124,6 +135,19 @@ function algAddressToBuffer32(address) {
|
|
|
124
135
|
}
|
|
125
136
|
throw new exceptions_1.SdkError(`Unexpected Alg address: ${address}`);
|
|
126
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
|
+
}
|
|
127
151
|
function tronAddressToBuffer32(address) {
|
|
128
152
|
const ethAddress = tronAddressToEthAddress(address);
|
|
129
153
|
const buffer = hexToBuffer(ethAddress);
|
|
@@ -226,12 +250,11 @@ async function prepareTxSendParams(bridgeChainType, params, api) {
|
|
|
226
250
|
}
|
|
227
251
|
txSendParams.toChainId = params.destinationToken.allbridgeChainId;
|
|
228
252
|
txSendParams.toTokenAddress = params.destinationToken.tokenAddress;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
txSendParams.gasFeePaymentMethod = models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY;
|
|
253
|
+
txSendParams.gasFeePaymentMethod = params.gasFeePaymentMethod ?? models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY;
|
|
254
|
+
if (txSendParams.gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_ARB) {
|
|
255
|
+
if (!params.sourceToken.abrPayer) {
|
|
256
|
+
throw new exceptions_1.SdkError("Source token must contain 'abrPayer' for ARB0 payment method");
|
|
257
|
+
}
|
|
235
258
|
}
|
|
236
259
|
const sourceToken = params.sourceToken;
|
|
237
260
|
switch (params.messenger) {
|
|
@@ -282,6 +305,15 @@ async function prepareTxSendParams(bridgeChainType, params, api) {
|
|
|
282
305
|
case models_1.FeePaymentMethod.WITH_STABLECOIN:
|
|
283
306
|
txSendParams.fee = (0, calculation_1.convertFloatAmountToInt)(fee, sourceToken.decimals).toFixed(0);
|
|
284
307
|
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
|
+
}
|
|
285
317
|
}
|
|
286
318
|
}
|
|
287
319
|
else {
|
|
@@ -302,6 +334,19 @@ async function prepareTxSendParams(bridgeChainType, params, api) {
|
|
|
302
334
|
extraGasDecimals = sourceToken.decimals;
|
|
303
335
|
extraGasDestRate = (0, big_js_1.Big)(extraGasLimits.exchangeRate).div(extraGasLimits.sourceNativeTokenPrice);
|
|
304
336
|
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
|
+
}
|
|
305
350
|
}
|
|
306
351
|
switch (extraGasFormat ?? models_1.AmountFormat.INT) {
|
|
307
352
|
case models_1.AmountFormat.FLOAT: {
|
|
@@ -325,8 +370,24 @@ async function prepareTxSendParams(bridgeChainType, params, api) {
|
|
|
325
370
|
}
|
|
326
371
|
txSendParams.toAccountAddress = formatAddress(params.toAccountAddress, toChainType, bridgeChainType);
|
|
327
372
|
txSendParams.toTokenAddress = formatAddress(txSendParams.toTokenAddress, toChainType, bridgeChainType);
|
|
328
|
-
|
|
329
|
-
|
|
373
|
+
switch (txSendParams.gasFeePaymentMethod) {
|
|
374
|
+
case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY:
|
|
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");
|
|
330
391
|
}
|
|
331
392
|
return txSendParams;
|
|
332
393
|
}
|
|
@@ -359,6 +420,15 @@ async function getGasFeeOptions(sourceChainToken, destinationAllbridgeChainId, m
|
|
|
359
420
|
[models_1.AmountFormat.FLOAT]: (0, calculation_1.convertIntAmountToFloat)(gasFeeIntWithStables, sourceChainToken.decimals).toFixed(),
|
|
360
421
|
};
|
|
361
422
|
}
|
|
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
|
+
}
|
|
362
432
|
return gasFeeOptions;
|
|
363
433
|
}
|
|
364
434
|
function validateExtraGasNotExceeded(extraGasInt, gasFeePaymentMethod, extraGasLimits) {
|
|
@@ -398,6 +468,19 @@ async function getExtraGasMaxLimits(sourceChainToken, destinationChainToken, mes
|
|
|
398
468
|
[models_1.AmountFormat.FLOAT]: maxAmountFloatInStable,
|
|
399
469
|
};
|
|
400
470
|
}
|
|
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
|
+
}
|
|
401
484
|
return {
|
|
402
485
|
extraGasMax: extraGasMaxLimits,
|
|
403
486
|
destinationChain: {
|
|
@@ -415,6 +498,7 @@ async function getExtraGasMaxLimits(sourceChainToken, destinationChainToken, mes
|
|
|
415
498
|
},
|
|
416
499
|
},
|
|
417
500
|
exchangeRate: transactionCostResponse.exchangeRate,
|
|
501
|
+
abrExchangeRate: abrAvailable ? transactionCostResponse.abrExchangeRate : undefined,
|
|
418
502
|
sourceNativeTokenPrice: transactionCostResponse.sourceNativeTokenPrice,
|
|
419
503
|
};
|
|
420
504
|
}
|