@across-protocol/sdk 4.3.165 → 4.3.166
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/cjs/src/arch/tvm/MessageUtils.d.ts +6 -0
- package/dist/cjs/src/arch/tvm/MessageUtils.js +27 -0
- package/dist/cjs/src/arch/tvm/MessageUtils.js.map +1 -0
- package/dist/cjs/src/arch/tvm/index.d.ts +1 -0
- package/dist/cjs/src/arch/tvm/index.js +1 -0
- package/dist/cjs/src/arch/tvm/index.js.map +1 -1
- package/dist/cjs/src/relayFeeCalculator/chain-queries/factory.js +3 -1
- package/dist/cjs/src/relayFeeCalculator/chain-queries/factory.js.map +1 -1
- package/dist/cjs/src/relayFeeCalculator/chain-queries/index.d.ts +1 -0
- package/dist/cjs/src/relayFeeCalculator/chain-queries/index.js +1 -0
- package/dist/cjs/src/relayFeeCalculator/chain-queries/index.js.map +1 -1
- package/dist/cjs/src/relayFeeCalculator/chain-queries/tvmQuery.d.ts +6 -0
- package/dist/cjs/src/relayFeeCalculator/chain-queries/tvmQuery.js +12 -0
- package/dist/cjs/src/relayFeeCalculator/chain-queries/tvmQuery.js.map +1 -0
- package/dist/esm/src/arch/tvm/MessageUtils.d.ts +22 -0
- package/dist/esm/src/arch/tvm/MessageUtils.js +61 -0
- package/dist/esm/src/arch/tvm/MessageUtils.js.map +1 -0
- package/dist/esm/src/arch/tvm/index.d.ts +1 -0
- package/dist/esm/src/arch/tvm/index.js +1 -0
- package/dist/esm/src/arch/tvm/index.js.map +1 -1
- package/dist/esm/src/relayFeeCalculator/chain-queries/factory.js +8 -2
- package/dist/esm/src/relayFeeCalculator/chain-queries/factory.js.map +1 -1
- package/dist/esm/src/relayFeeCalculator/chain-queries/index.d.ts +1 -0
- package/dist/esm/src/relayFeeCalculator/chain-queries/index.js +1 -0
- package/dist/esm/src/relayFeeCalculator/chain-queries/index.js.map +1 -1
- package/dist/esm/src/relayFeeCalculator/chain-queries/tvmQuery.d.ts +16 -0
- package/dist/esm/src/relayFeeCalculator/chain-queries/tvmQuery.js +18 -0
- package/dist/esm/src/relayFeeCalculator/chain-queries/tvmQuery.js.map +1 -0
- package/dist/types/src/arch/tvm/MessageUtils.d.ts +23 -0
- package/dist/types/src/arch/tvm/MessageUtils.d.ts.map +1 -0
- package/dist/types/src/arch/tvm/index.d.ts +1 -0
- package/dist/types/src/arch/tvm/index.d.ts.map +1 -1
- package/dist/types/src/relayFeeCalculator/chain-queries/factory.d.ts.map +1 -1
- package/dist/types/src/relayFeeCalculator/chain-queries/index.d.ts +1 -0
- package/dist/types/src/relayFeeCalculator/chain-queries/index.d.ts.map +1 -1
- package/dist/types/src/relayFeeCalculator/chain-queries/tvmQuery.d.ts +17 -0
- package/dist/types/src/relayFeeCalculator/chain-queries/tvmQuery.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/arch/tvm/MessageUtils.ts +72 -0
- package/src/arch/tvm/index.ts +1 -0
- package/src/relayFeeCalculator/chain-queries/factory.ts +8 -2
- package/src/relayFeeCalculator/chain-queries/index.ts +1 -0
- package/src/relayFeeCalculator/chain-queries/tvmQuery.ts +20 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RelayData, SpeedUpCommon } from "../../interfaces";
|
|
2
|
+
import { BigNumber } from "../../utils";
|
|
3
|
+
export declare function getAuxiliaryNativeTokenCost(deposit: RelayData & Partial<SpeedUpCommon> & {
|
|
4
|
+
speedUpSignature?: string;
|
|
5
|
+
}): BigNumber;
|
|
6
|
+
export declare const tvmBandwidthCostZero: BigNumber;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tvmBandwidthCostZero = void 0;
|
|
4
|
+
exports.getAuxiliaryNativeTokenCost = getAuxiliaryNativeTokenCost;
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
const TVM_BANDWIDTH_SUN_PER_BYTE = 1000;
|
|
7
|
+
const TVM_RAW_DATA_OVERHEAD_BYTES = 290;
|
|
8
|
+
const TVM_FILL_RELAY_FIXED_CALLDATA_BYTES = 4 + 96 + 384 + 32;
|
|
9
|
+
const TVM_SPEED_UP_FIXED_CALLDATA_EXTRA_BYTES = 128 + 32 + 32 + 96;
|
|
10
|
+
function paddedMessageByteLength(message) {
|
|
11
|
+
if (!(0, utils_1.isDefined)(message) || (0, utils_1.isMessageEmpty)(message))
|
|
12
|
+
return 0;
|
|
13
|
+
const bytes = Math.max(0, Math.floor((message.length - 2) / 2));
|
|
14
|
+
return Math.ceil(bytes / 32) * 32;
|
|
15
|
+
}
|
|
16
|
+
function getAuxiliaryNativeTokenCost(deposit) {
|
|
17
|
+
const paddedMessageBytes = paddedMessageByteLength(deposit.message);
|
|
18
|
+
let speedUpExtraBytes = 0;
|
|
19
|
+
if ((0, utils_1.isDefined)(deposit.speedUpSignature) && deposit.speedUpSignature !== "0x") {
|
|
20
|
+
speedUpExtraBytes = TVM_SPEED_UP_FIXED_CALLDATA_EXTRA_BYTES + paddedMessageByteLength(deposit.updatedMessage);
|
|
21
|
+
}
|
|
22
|
+
const calldataBytes = TVM_FILL_RELAY_FIXED_CALLDATA_BYTES + paddedMessageBytes + speedUpExtraBytes;
|
|
23
|
+
const txBytes = TVM_RAW_DATA_OVERHEAD_BYTES + calldataBytes;
|
|
24
|
+
return (0, utils_1.toBN)(txBytes).mul(TVM_BANDWIDTH_SUN_PER_BYTE);
|
|
25
|
+
}
|
|
26
|
+
exports.tvmBandwidthCostZero = utils_1.bnZero;
|
|
27
|
+
//# sourceMappingURL=MessageUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageUtils.js","sourceRoot":"","sources":["../../../../../src/arch/tvm/MessageUtils.ts"],"names":[],"mappings":";;;AAsDA,kEAcC;AAnED,uCAAiF;AAKjF,MAAM,0BAA0B,GAAG,IAAI,CAAC;AAKxC,MAAM,2BAA2B,GAAG,GAAG,CAA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ib");
|
|
4
4
|
tslib_1.__exportStar(require("./SpokeUtils"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./TransactionUtils"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./MessageUtils"), exports);
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/arch/tvm/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B;AAC7B,6DAAmC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/arch/tvm/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B;AAC7B,6DAAmC;AACnC,yDAA+B"}
|
|
@@ -12,6 +12,7 @@ const baseQuery_1 = require("./baseQuery");
|
|
|
12
12
|
const relayFeeCalculator_1 = require("../relayFeeCalculator");
|
|
13
13
|
const customGasToken_1 = require("./customGasToken");
|
|
14
14
|
const svmQuery_1 = require("./svmQuery");
|
|
15
|
+
const tvmQuery_1 = require("./tvmQuery");
|
|
15
16
|
const fixedGasPrice = {
|
|
16
17
|
[constants_1.CHAIN_IDs.BOBA]: 1e9,
|
|
17
18
|
};
|
|
@@ -21,7 +22,8 @@ class QueryBase__factory {
|
|
|
21
22
|
const customGasTokenSymbol = constants_2.CUSTOM_GAS_TOKENS[chainId];
|
|
22
23
|
if ((0, utils_1.chainIsEvm)(chainId) && (0, utils_1.isDefined)(customGasTokenSymbol)) {
|
|
23
24
|
(0, assert_1.default)(relayerAddress.isEVM());
|
|
24
|
-
|
|
25
|
+
const QueryCtor = (0, utils_1.chainIsTvm)(chainId) ? tvmQuery_1.TvmQuery : customGasToken_1.CustomGasTokenQueries;
|
|
26
|
+
return new QueryCtor({
|
|
25
27
|
queryBaseArgs: [
|
|
26
28
|
provider,
|
|
27
29
|
symbolMapping,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../src/relayFeeCalculator/chain-queries/factory.ts"],"names":[],"mappings":";;;;AAAA,4DAA4B;AAC5B,0DAA0E;AAC1E,0DAAgE;AAChE,2CAAiD;AAEjD,+CAAoD;AACpD,
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../src/relayFeeCalculator/chain-queries/factory.ts"],"names":[],"mappings":";;;;AAAA,4DAA4B;AAC5B,0DAA0E;AAC1E,0DAAgE;AAChE,2CAAiD;AAEjD,+CAAoD;AACpD,uCAAwG;AACxG,2CAAwC;AAExC,8DAAkF;AAClF,qDAAyD;AACzD,yCAAsC;AACtC,yCAAsC;AAMtC,MAAM,aAAa,GAAG;IACpB,CAAC,qBAAS,CAAC,IAAI,CAAC,EAAE,GAAG;CACtB,CAAC;AAEF,MAAa,kBAAkB;IAC7B,MAAM,CAAC,MAAM,CACX,OAAe,EACf,QAA0C,EAC1C,aAAa,GAAG,6BAAiB,EACjC,gBAAgB,GAAG,IAAA,8BAAkB,EAAC,WAAW,EAAE,OAAO,CAAC,EAC3D,cAAc,GAAG,IAAA,sCAAiB,EAAC,OAAO,CAAC,EAC3C,kBAA2B,EAC3B,SAAiB,mCAAc,EAC/B,qBAAqB,GAAG,KAAK;QAE7B,IAAA,gBAAM,EAAC,IAAA,iBAAS,EAAC,gBAAgB,CAAC,CAAC,CAAC;QAEpC,MAAM,oBAAoB,GAAG,6BAAiB,CAAC,OAAO,CAAC,CAAC;QACxD,IAAI,IAAA,kBAAU,EAAC,OAAO,CAAC,IAAI,IAAA,iBAAS,EAAC,oBAAoB,CAAC,EAAE,CAAC;YAC3D,IAAA,gBAAM,EAAC,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC;YAK/B,MAAM,SAAS,GAAG,IAAA,kBAAU,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,mBAAQ,CAAC,CAAC,CAAC,sCAAqB,CAAC;YACzE,OAAO,IAAI,SAAS,CAAC;gBACnB,aAAa,EAAE;oBACb,QAA8B;oBAC9B,aAAa;oBACb,gBAAgB;oBAChB,cAAc;oBACd,MAAM;oBACN,kBAAkB;oBAClB,aAAa,CAAC,OAAO,CAAC;oBACtB,KAAK;iBACN;gBACD,oBAAoB;aACrB,CAAC,CAAC;QACL,CAAC;QACD,IAAI,IAAA,kBAAU,EAAC,OAAO,CAAC,EAAE,CAAC;YACxB,IAAA,gBAAM,EAAC,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC;YAC/B,OAAO,IAAI,mBAAQ,CACjB,QAAuB,EACvB,aAAa,EACb,kBAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,EACjC,cAAc,EACd,MAAM,EACN,kBAAkB,EAClB,aAAa,CAAC,OAAO,CAAC,EACtB,qBAAqB,CACtB,CAAC;QACJ,CAAC;QAGD,QAAQ,GAAG,IAAA,sBAAc,EAAC,OAAO,CAAC;YAChC,CAAC,CAAC,IAAA,kBAAY,EAAC,QAA8B,CAAC;YAC9C,CAAC,CAAE,QAA+B,CAAC;QAErC,IAAA,gBAAM,EAAC,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC;QAC/B,OAAO,IAAI,qBAAS,CAClB,QAAQ,EACR,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,MAAM,EACN,kBAAkB,EAClB,aAAa,CAAC,OAAO,CAAC,EACtB,qBAAqB,CACtB,CAAC;IACJ,CAAC;CACF;AAlED,gDAkEC"}
|
|
@@ -5,4 +5,5 @@ tslib_1.__exportStar(require("./baseQuery"), exports);
|
|
|
5
5
|
tslib_1.__exportStar(require("./factory"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./customGasToken"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./svmQuery"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./tvmQuery"), exports);
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/relayFeeCalculator/chain-queries/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,oDAA0B;AAC1B,2DAAiC;AACjC,qDAA2B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/relayFeeCalculator/chain-queries/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,oDAA0B;AAC1B,2DAAiC;AACjC,qDAA2B;AAC3B,qDAA2B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RelayData } from "../../interfaces";
|
|
2
|
+
import { BigNumber } from "../../utils";
|
|
3
|
+
import { CustomGasTokenQueries } from "./customGasToken";
|
|
4
|
+
export declare class TvmQuery extends CustomGasTokenQueries {
|
|
5
|
+
getAuxiliaryNativeTokenCost(deposit: RelayData): BigNumber;
|
|
6
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TvmQuery = void 0;
|
|
4
|
+
const __1 = require("../..");
|
|
5
|
+
const customGasToken_1 = require("./customGasToken");
|
|
6
|
+
class TvmQuery extends customGasToken_1.CustomGasTokenQueries {
|
|
7
|
+
getAuxiliaryNativeTokenCost(deposit) {
|
|
8
|
+
return __1.arch.tvm.getAuxiliaryNativeTokenCost(deposit);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.TvmQuery = TvmQuery;
|
|
12
|
+
//# sourceMappingURL=tvmQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tvmQuery.js","sourceRoot":"","sources":["../../../../../src/relayFeeCalculator/chain-queries/tvmQuery.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAG7B,qDAAyD;AAYzD,MAAa,QAAS,SAAQ,sCAAqB;IACxC,2BAA2B,CAAC,OAAkB;QACrD,OAAO,QAAI,CAAC,GAAG,CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;CACF;AAJD,4BAIC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RelayData, SpeedUpCommon } from "../../interfaces";
|
|
2
|
+
import { BigNumber } from "../../utils";
|
|
3
|
+
/**
|
|
4
|
+
* Estimate the bandwidth cost (in SUN) of a Tron fill for `deposit`.
|
|
5
|
+
*
|
|
6
|
+
* On Tron, transaction bytes consume bandwidth — distinct from energy (paid via the tx
|
|
7
|
+
* fee limit and modeled in `nativeGasCost`). When the relayer has no free bandwidth
|
|
8
|
+
* staked, every byte burns 1,000 SUN. For message-bearing fills this is non-trivial:
|
|
9
|
+
* the message dominates calldata size, so the cost scales linearly with message length.
|
|
10
|
+
*
|
|
11
|
+
* Sped-up deposits (those carrying a `speedUpSignature`) are filled via
|
|
12
|
+
* `fillRelayWithUpdatedDeposit`, which carries the original `V3RelayData` *and*
|
|
13
|
+
* `updatedMessage`/`speedUpSignature` as additional ABI args. Both messages are charged.
|
|
14
|
+
*
|
|
15
|
+
* The estimate is conservative — it assumes zero free bandwidth (worst case). Relayers
|
|
16
|
+
* that stake TRX for bandwidth pay 0 onchain; this still represents the true marginal
|
|
17
|
+
* cost of consuming that staked allowance.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getAuxiliaryNativeTokenCost(deposit: RelayData & Partial<SpeedUpCommon> & {
|
|
20
|
+
speedUpSignature?: string;
|
|
21
|
+
}): BigNumber;
|
|
22
|
+
export declare const tvmBandwidthCostZero: BigNumber;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { bnZero, isDefined, isMessageEmpty, toBN } from "../../utils";
|
|
2
|
+
// Tron prices each byte of a transaction's serialized raw_data + signature at this many
|
|
3
|
+
// SUN of bandwidth when the relayer's free bandwidth allowance has been exhausted. The
|
|
4
|
+
// rate is set by Tron governance; refresh from `wallet/getchainparameters` if it drifts.
|
|
5
|
+
const TVM_BANDWIDTH_SUN_PER_BYTE = 1000;
|
|
6
|
+
// Tron raw_data envelope (contract type, ref_block, timestamp, expiration, fee_limit)
|
|
7
|
+
// plus a single ECDSA signature. Measured empirically against `fillRelay` transactions
|
|
8
|
+
// emitted by the production relayer; varies by ~10 bytes between calls.
|
|
9
|
+
const TVM_RAW_DATA_OVERHEAD_BYTES = 290;
|
|
10
|
+
// `fillRelay(V3RelayData, uint256 repaymentChainId, bytes32 repaymentAddress)` ABI
|
|
11
|
+
// encoding, excluding the `message` payload (which is dynamic).
|
|
12
|
+
// 4 selector
|
|
13
|
+
// 96 top-level head: offset(V3RelayData) + repaymentChainId + repaymentAddress
|
|
14
|
+
// 384 V3RelayData struct head: 11 static fields inline + 1 offset(message)
|
|
15
|
+
// 32 message length header
|
|
16
|
+
const TVM_FILL_RELAY_FIXED_CALLDATA_BYTES = 4 + 96 + 384 + 32;
|
|
17
|
+
// Extra ABI footprint when a speed-up signature is present and the relayer must call
|
|
18
|
+
// `fillRelayWithUpdatedDeposit(V3RelayData, ..., uint256 updatedOutputAmount, bytes32
|
|
19
|
+
// updatedRecipient, bytes updatedMessage, bytes speedUpSignature)`. The original
|
|
20
|
+
// `message` still lives inside V3RelayData and is already counted above; this constant
|
|
21
|
+
// captures only what's *additional* to the plain `fillRelay` encoding.
|
|
22
|
+
// 128 4 extra head slots: updatedOutputAmount + updatedRecipient + offset(updatedMessage) + offset(speedUpSignature)
|
|
23
|
+
// 32 updatedMessage length header (the padded body is added per-call below)
|
|
24
|
+
// 32 speedUpSignature length header
|
|
25
|
+
// 96 65-byte ECDSA signature padded to 3 EVM words
|
|
26
|
+
const TVM_SPEED_UP_FIXED_CALLDATA_EXTRA_BYTES = 128 + 32 + 32 + 96;
|
|
27
|
+
function paddedMessageByteLength(message) {
|
|
28
|
+
if (!isDefined(message) || isMessageEmpty(message))
|
|
29
|
+
return 0;
|
|
30
|
+
const bytes = Math.max(0, Math.floor((message.length - 2) / 2));
|
|
31
|
+
return Math.ceil(bytes / 32) * 32;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Estimate the bandwidth cost (in SUN) of a Tron fill for `deposit`.
|
|
35
|
+
*
|
|
36
|
+
* On Tron, transaction bytes consume bandwidth — distinct from energy (paid via the tx
|
|
37
|
+
* fee limit and modeled in `nativeGasCost`). When the relayer has no free bandwidth
|
|
38
|
+
* staked, every byte burns 1,000 SUN. For message-bearing fills this is non-trivial:
|
|
39
|
+
* the message dominates calldata size, so the cost scales linearly with message length.
|
|
40
|
+
*
|
|
41
|
+
* Sped-up deposits (those carrying a `speedUpSignature`) are filled via
|
|
42
|
+
* `fillRelayWithUpdatedDeposit`, which carries the original `V3RelayData` *and*
|
|
43
|
+
* `updatedMessage`/`speedUpSignature` as additional ABI args. Both messages are charged.
|
|
44
|
+
*
|
|
45
|
+
* The estimate is conservative — it assumes zero free bandwidth (worst case). Relayers
|
|
46
|
+
* that stake TRX for bandwidth pay 0 onchain; this still represents the true marginal
|
|
47
|
+
* cost of consuming that staked allowance.
|
|
48
|
+
*/
|
|
49
|
+
export function getAuxiliaryNativeTokenCost(deposit) {
|
|
50
|
+
const paddedMessageBytes = paddedMessageByteLength(deposit.message);
|
|
51
|
+
let speedUpExtraBytes = 0;
|
|
52
|
+
if (isDefined(deposit.speedUpSignature) && deposit.speedUpSignature !== "0x") {
|
|
53
|
+
speedUpExtraBytes = TVM_SPEED_UP_FIXED_CALLDATA_EXTRA_BYTES + paddedMessageByteLength(deposit.updatedMessage);
|
|
54
|
+
}
|
|
55
|
+
const calldataBytes = TVM_FILL_RELAY_FIXED_CALLDATA_BYTES + paddedMessageBytes + speedUpExtraBytes;
|
|
56
|
+
const txBytes = TVM_RAW_DATA_OVERHEAD_BYTES + calldataBytes;
|
|
57
|
+
return toBN(txBytes).mul(TVM_BANDWIDTH_SUN_PER_BYTE);
|
|
58
|
+
}
|
|
59
|
+
// Re-export so other arches can reference the zero default if needed.
|
|
60
|
+
export const tvmBandwidthCostZero = bnZero;
|
|
61
|
+
//# sourceMappingURL=MessageUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageUtils.js","sourceRoot":"","sources":["../../../../../src/arch/tvm/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,CAAC,gBAAgB,CAAC,IAAI,OAAO,CAAC,gBAAgB,KAAK,IAAI,EAAE,CAAC;QAC7E,iBAAiB,GAAG,uCAAuC,GAAG,uBAAuB,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAChH,CAAC;IAED,MAAM,aAAa,GAAG,mCAAmC,GAAG,kBAAkB,GAAG,iBAAiB,CAAC;IACnG,MAAM,OAAO,GAAG,2BAA2B,GAAG,aAAa,CAAC;IAE5D,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AACvD,CAAC;AAED,sEAAsE;AACtE,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/arch/tvm/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/arch/tvm/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC"}
|
|
@@ -3,11 +3,12 @@ import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "@across-protocol/constants";
|
|
|
3
3
|
import { getDeployedAddress } from "@across-protocol/contracts";
|
|
4
4
|
import { asL2Provider } from "@eth-optimism/sdk";
|
|
5
5
|
import { CUSTOM_GAS_TOKENS } from "../../constants";
|
|
6
|
-
import { chainIsEvm, chainIsOPStack, isDefined, chainIsSvm, SvmAddress } from "../../utils";
|
|
6
|
+
import { chainIsEvm, chainIsOPStack, isDefined, chainIsSvm, chainIsTvm, SvmAddress } from "../../utils";
|
|
7
7
|
import { QueryBase } from "./baseQuery";
|
|
8
8
|
import { DEFAULT_LOGGER, getDefaultRelayer } from "../relayFeeCalculator";
|
|
9
9
|
import { CustomGasTokenQueries } from "./customGasToken";
|
|
10
10
|
import { SvmQuery } from "./svmQuery";
|
|
11
|
+
import { TvmQuery } from "./tvmQuery";
|
|
11
12
|
/**
|
|
12
13
|
* Some chains have a fixed gas price that is applied to the gas estimates. We should override
|
|
13
14
|
* the gas markup for these chains.
|
|
@@ -21,7 +22,12 @@ export class QueryBase__factory {
|
|
|
21
22
|
const customGasTokenSymbol = CUSTOM_GAS_TOKENS[chainId];
|
|
22
23
|
if (chainIsEvm(chainId) && isDefined(customGasTokenSymbol)) {
|
|
23
24
|
assert(relayerAddress.isEVM());
|
|
24
|
-
|
|
25
|
+
// TVM chains route through TvmQuery so that bandwidth — a Tron-native cost the
|
|
26
|
+
// EVM compatibility layer's `eth_estimateGas` does not surface — is included in
|
|
27
|
+
// `auxiliaryNativeTokenCost`. Otherwise fall back to the EVM-flavoured custom gas
|
|
28
|
+
// token query.
|
|
29
|
+
const QueryCtor = chainIsTvm(chainId) ? TvmQuery : CustomGasTokenQueries;
|
|
30
|
+
return new QueryCtor({
|
|
25
31
|
queryBaseArgs: [
|
|
26
32
|
provider,
|
|
27
33
|
symbolMapping,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../src/relayFeeCalculator/chain-queries/factory.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../src/relayFeeCalculator/ch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AC3D,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC;YAC/B,+EAA+E;YAC/E,gFAAgF;YAChF,kFAAkF;YAClF,eAAe;YACf,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAAC;YACzE,OAAO,IAAI,SAAS,CAAC;gBACnB,aAAa,EAAE;oBACb,QAA8B;oBAC9B,aAAa;oBACb,gBAAgB;oBAChB,cAAc;oBACd,MAAM;oBACN,kBAAkB;oBAClB,aAAa,CAAC,OAAO,CAAC;oBACtB,KAAK;iBACN;gBACD,oBAAoB;aACrB,CAAC,CAAC;QACL,CAAC;QACD,IAAI,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YACxB,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC;YAC/B,OAAO,IAAI,QAAQ,CACjB,QAAuB,EACvB,aAAa,EACb,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,EACjC,cAAc,EACd,MAAM,EACN,kBAAkB,EAClB,aAAa,CAAC,OAAO,CAAC,EACtB,qBAAqB,CACtB,CAAC;QACJ,CAAC;QAED,oEAAoE;QACpE,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC;YAChC,CAAC,CAAC,YAAY,CAAC,QAA8B,CAAC;YAC9C,CAAC,CAAE,QAA+B,CAAC;QAErC,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC;QAC/B,OAAO,IAAI,SAAS,CAClB,QAAQ,EACR,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,MAAM,EACN,kBAAkB,EAClB,aAAa,CAAC,OAAO,CAAC,EACtB,qBAAqB,CACtB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/relayFeeCalculator/chain-queries/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/relayFeeCalculator/chain-queries/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RelayData } from "../../interfaces";
|
|
2
|
+
import { BigNumber } from "../../utils";
|
|
3
|
+
import { CustomGasTokenQueries } from "./customGasToken";
|
|
4
|
+
/**
|
|
5
|
+
* TVM (TRON) query implementation. Extends `CustomGasTokenQueries` to add bandwidth
|
|
6
|
+
* accounting via `getAuxiliaryNativeTokenCost`, which the base EVM path returns 0 for.
|
|
7
|
+
*
|
|
8
|
+
* Energy (Tron's analogue of gas) is already estimated by `voidSigner.estimateGas`
|
|
9
|
+
* against the EVM-compat RPC and surfaces in `tokenGasCost`. Bandwidth is a separate
|
|
10
|
+
* Tron-native resource that the EVM compatibility layer does not surface, so we
|
|
11
|
+
* estimate it here from the deposit's `message` length and a fixed `fillRelay`
|
|
12
|
+
* calldata footprint.
|
|
13
|
+
*/
|
|
14
|
+
export declare class TvmQuery extends CustomGasTokenQueries {
|
|
15
|
+
getAuxiliaryNativeTokenCost(deposit: RelayData): BigNumber;
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { arch } from "../..";
|
|
2
|
+
import { CustomGasTokenQueries } from "./customGasToken";
|
|
3
|
+
/**
|
|
4
|
+
* TVM (TRON) query implementation. Extends `CustomGasTokenQueries` to add bandwidth
|
|
5
|
+
* accounting via `getAuxiliaryNativeTokenCost`, which the base EVM path returns 0 for.
|
|
6
|
+
*
|
|
7
|
+
* Energy (Tron's analogue of gas) is already estimated by `voidSigner.estimateGas`
|
|
8
|
+
* against the EVM-compat RPC and surfaces in `tokenGasCost`. Bandwidth is a separate
|
|
9
|
+
* Tron-native resource that the EVM compatibility layer does not surface, so we
|
|
10
|
+
* estimate it here from the deposit's `message` length and a fixed `fillRelay`
|
|
11
|
+
* calldata footprint.
|
|
12
|
+
*/
|
|
13
|
+
export class TvmQuery extends CustomGasTokenQueries {
|
|
14
|
+
getAuxiliaryNativeTokenCost(deposit) {
|
|
15
|
+
return arch.tvm.getAuxiliaryNativeTokenCost(deposit);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=tvmQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tvmQuery.js","sourceRoot":"","sources":["../../../../../src/relayFeeCalculator/chain-queries/tvmQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAG7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;;;;;;;GASG;AACH,MAAM,OAAO,QAAS,SAAQ,qBAAqB;IACxC,2BAA2B,CAAC,OAAkB;QACrD,OAAO,IAAI,CAAC,GAAG,CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RelayData, SpeedUpCommon } from "../../interfaces";
|
|
2
|
+
import { BigNumber } from "../../utils";
|
|
3
|
+
/**
|
|
4
|
+
* Estimate the bandwidth cost (in SUN) of a Tron fill for `deposit`.
|
|
5
|
+
*
|
|
6
|
+
* On Tron, transaction bytes consume bandwidth — distinct from energy (paid via the tx
|
|
7
|
+
* fee limit and modeled in `nativeGasCost`). When the relayer has no free bandwidth
|
|
8
|
+
* staked, every byte burns 1,000 SUN. For message-bearing fills this is non-trivial:
|
|
9
|
+
* the message dominates calldata size, so the cost scales linearly with message length.
|
|
10
|
+
*
|
|
11
|
+
* Sped-up deposits (those carrying a `speedUpSignature`) are filled via
|
|
12
|
+
* `fillRelayWithUpdatedDeposit`, which carries the original `V3RelayData` *and*
|
|
13
|
+
* `updatedMessage`/`speedUpSignature` as additional ABI args. Both messages are charged.
|
|
14
|
+
*
|
|
15
|
+
* The estimate is conservative — it assumes zero free bandwidth (worst case). Relayers
|
|
16
|
+
* that stake TRX for bandwidth pay 0 onchain; this still represents the true marginal
|
|
17
|
+
* cost of consuming that staked allowance.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getAuxiliaryNativeTokenCost(deposit: RelayData & Partial<SpeedUpCommon> & {
|
|
20
|
+
speedUpSignature?: string;
|
|
21
|
+
}): BigNumber;
|
|
22
|
+
export declare const tvmBandwidthCostZero: BigNumber;
|
|
23
|
+
//# sourceMappingURL=MessageUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageUtils.d.ts","sourceRoot":"","sources":["../../../../../src/arch/tvm/MessageUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAA2C,MAAM,aAAa,CAAC;AAqCjF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,GAAG;IAAE,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1E,SAAS,CAYX;AAGD,eAAO,MAAM,oBAAoB,WAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/arch/tvm/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/arch/tvm/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../../src/relayFeeCalculator/chain-queries/factory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGnC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,WAAW,IAAI,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAqC,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAElF,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../../src/relayFeeCalculator/chain-queries/factory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGnC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,WAAW,IAAI,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAqC,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAElF,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAWtC,qBAAa,kBAAkB;IAC7B,MAAM,CAAC,MAAM,CACX,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,SAAS,CAAC,QAAQ,GAAG,WAAW,EAC1C,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAAoB,EACjC,gBAAgB,qBAA2C,EAC3D,cAAc,gCAA6B,EAC3C,kBAAkB,CAAC,EAAE,MAAM,EAC3B,MAAM,GAAE,MAAuB,EAC/B,qBAAqB,SAAQ,GAC5B,SAAS,GAAG,QAAQ;CAwDxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/relayFeeCalculator/chain-queries/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/relayFeeCalculator/chain-queries/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RelayData } from "../../interfaces";
|
|
2
|
+
import { BigNumber } from "../../utils";
|
|
3
|
+
import { CustomGasTokenQueries } from "./customGasToken";
|
|
4
|
+
/**
|
|
5
|
+
* TVM (TRON) query implementation. Extends `CustomGasTokenQueries` to add bandwidth
|
|
6
|
+
* accounting via `getAuxiliaryNativeTokenCost`, which the base EVM path returns 0 for.
|
|
7
|
+
*
|
|
8
|
+
* Energy (Tron's analogue of gas) is already estimated by `voidSigner.estimateGas`
|
|
9
|
+
* against the EVM-compat RPC and surfaces in `tokenGasCost`. Bandwidth is a separate
|
|
10
|
+
* Tron-native resource that the EVM compatibility layer does not surface, so we
|
|
11
|
+
* estimate it here from the deposit's `message` length and a fixed `fillRelay`
|
|
12
|
+
* calldata footprint.
|
|
13
|
+
*/
|
|
14
|
+
export declare class TvmQuery extends CustomGasTokenQueries {
|
|
15
|
+
getAuxiliaryNativeTokenCost(deposit: RelayData): BigNumber;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=tvmQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tvmQuery.d.ts","sourceRoot":"","sources":["../../../../../src/relayFeeCalculator/chain-queries/tvmQuery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;;;;;;;GASG;AACH,qBAAa,QAAS,SAAQ,qBAAqB;IACxC,2BAA2B,CAAC,OAAO,EAAE,SAAS,GAAG,SAAS;CAGpE"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { RelayData, SpeedUpCommon } from "../../interfaces";
|
|
2
|
+
import { BigNumber, bnZero, isDefined, isMessageEmpty, toBN } from "../../utils";
|
|
3
|
+
|
|
4
|
+
// Tron prices each byte of a transaction's serialized raw_data + signature at this many
|
|
5
|
+
// SUN of bandwidth when the relayer's free bandwidth allowance has been exhausted. The
|
|
6
|
+
// rate is set by Tron governance; refresh from `wallet/getchainparameters` if it drifts.
|
|
7
|
+
const TVM_BANDWIDTH_SUN_PER_BYTE = 1000;
|
|
8
|
+
|
|
9
|
+
// Tron raw_data envelope (contract type, ref_block, timestamp, expiration, fee_limit)
|
|
10
|
+
// plus a single ECDSA signature. Measured empirically against `fillRelay` transactions
|
|
11
|
+
// emitted by the production relayer; varies by ~10 bytes between calls.
|
|
12
|
+
const TVM_RAW_DATA_OVERHEAD_BYTES = 290;
|
|
13
|
+
|
|
14
|
+
// `fillRelay(V3RelayData, uint256 repaymentChainId, bytes32 repaymentAddress)` ABI
|
|
15
|
+
// encoding, excluding the `message` payload (which is dynamic).
|
|
16
|
+
// 4 selector
|
|
17
|
+
// 96 top-level head: offset(V3RelayData) + repaymentChainId + repaymentAddress
|
|
18
|
+
// 384 V3RelayData struct head: 11 static fields inline + 1 offset(message)
|
|
19
|
+
// 32 message length header
|
|
20
|
+
const TVM_FILL_RELAY_FIXED_CALLDATA_BYTES = 4 + 96 + 384 + 32;
|
|
21
|
+
|
|
22
|
+
// Extra ABI footprint when a speed-up signature is present and the relayer must call
|
|
23
|
+
// `fillRelayWithUpdatedDeposit(V3RelayData, ..., uint256 updatedOutputAmount, bytes32
|
|
24
|
+
// updatedRecipient, bytes updatedMessage, bytes speedUpSignature)`. The original
|
|
25
|
+
// `message` still lives inside V3RelayData and is already counted above; this constant
|
|
26
|
+
// captures only what's *additional* to the plain `fillRelay` encoding.
|
|
27
|
+
// 128 4 extra head slots: updatedOutputAmount + updatedRecipient + offset(updatedMessage) + offset(speedUpSignature)
|
|
28
|
+
// 32 updatedMessage length header (the padded body is added per-call below)
|
|
29
|
+
// 32 speedUpSignature length header
|
|
30
|
+
// 96 65-byte ECDSA signature padded to 3 EVM words
|
|
31
|
+
const TVM_SPEED_UP_FIXED_CALLDATA_EXTRA_BYTES = 128 + 32 + 32 + 96;
|
|
32
|
+
|
|
33
|
+
function paddedMessageByteLength(message: string | undefined): number {
|
|
34
|
+
if (!isDefined(message) || isMessageEmpty(message)) return 0;
|
|
35
|
+
const bytes = Math.max(0, Math.floor((message.length - 2) / 2));
|
|
36
|
+
return Math.ceil(bytes / 32) * 32;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Estimate the bandwidth cost (in SUN) of a Tron fill for `deposit`.
|
|
41
|
+
*
|
|
42
|
+
* On Tron, transaction bytes consume bandwidth — distinct from energy (paid via the tx
|
|
43
|
+
* fee limit and modeled in `nativeGasCost`). When the relayer has no free bandwidth
|
|
44
|
+
* staked, every byte burns 1,000 SUN. For message-bearing fills this is non-trivial:
|
|
45
|
+
* the message dominates calldata size, so the cost scales linearly with message length.
|
|
46
|
+
*
|
|
47
|
+
* Sped-up deposits (those carrying a `speedUpSignature`) are filled via
|
|
48
|
+
* `fillRelayWithUpdatedDeposit`, which carries the original `V3RelayData` *and*
|
|
49
|
+
* `updatedMessage`/`speedUpSignature` as additional ABI args. Both messages are charged.
|
|
50
|
+
*
|
|
51
|
+
* The estimate is conservative — it assumes zero free bandwidth (worst case). Relayers
|
|
52
|
+
* that stake TRX for bandwidth pay 0 onchain; this still represents the true marginal
|
|
53
|
+
* cost of consuming that staked allowance.
|
|
54
|
+
*/
|
|
55
|
+
export function getAuxiliaryNativeTokenCost(
|
|
56
|
+
deposit: RelayData & Partial<SpeedUpCommon> & { speedUpSignature?: string }
|
|
57
|
+
): BigNumber {
|
|
58
|
+
const paddedMessageBytes = paddedMessageByteLength(deposit.message);
|
|
59
|
+
|
|
60
|
+
let speedUpExtraBytes = 0;
|
|
61
|
+
if (isDefined(deposit.speedUpSignature) && deposit.speedUpSignature !== "0x") {
|
|
62
|
+
speedUpExtraBytes = TVM_SPEED_UP_FIXED_CALLDATA_EXTRA_BYTES + paddedMessageByteLength(deposit.updatedMessage);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const calldataBytes = TVM_FILL_RELAY_FIXED_CALLDATA_BYTES + paddedMessageBytes + speedUpExtraBytes;
|
|
66
|
+
const txBytes = TVM_RAW_DATA_OVERHEAD_BYTES + calldataBytes;
|
|
67
|
+
|
|
68
|
+
return toBN(txBytes).mul(TVM_BANDWIDTH_SUN_PER_BYTE);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Re-export so other arches can reference the zero default if needed.
|
|
72
|
+
export const tvmBandwidthCostZero = bnZero;
|
package/src/arch/tvm/index.ts
CHANGED
|
@@ -4,12 +4,13 @@ import { getDeployedAddress } from "@across-protocol/contracts";
|
|
|
4
4
|
import { asL2Provider } from "@eth-optimism/sdk";
|
|
5
5
|
import { providers } from "ethers";
|
|
6
6
|
import { CUSTOM_GAS_TOKENS } from "../../constants";
|
|
7
|
-
import { chainIsEvm, chainIsOPStack, isDefined, chainIsSvm, SvmAddress } from "../../utils";
|
|
7
|
+
import { chainIsEvm, chainIsOPStack, isDefined, chainIsSvm, chainIsTvm, SvmAddress } from "../../utils";
|
|
8
8
|
import { QueryBase } from "./baseQuery";
|
|
9
9
|
import { SVMProvider as svmProvider } from "../../arch/svm";
|
|
10
10
|
import { DEFAULT_LOGGER, getDefaultRelayer, Logger } from "../relayFeeCalculator";
|
|
11
11
|
import { CustomGasTokenQueries } from "./customGasToken";
|
|
12
12
|
import { SvmQuery } from "./svmQuery";
|
|
13
|
+
import { TvmQuery } from "./tvmQuery";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Some chains have a fixed gas price that is applied to the gas estimates. We should override
|
|
@@ -35,7 +36,12 @@ export class QueryBase__factory {
|
|
|
35
36
|
const customGasTokenSymbol = CUSTOM_GAS_TOKENS[chainId];
|
|
36
37
|
if (chainIsEvm(chainId) && isDefined(customGasTokenSymbol)) {
|
|
37
38
|
assert(relayerAddress.isEVM());
|
|
38
|
-
|
|
39
|
+
// TVM chains route through TvmQuery so that bandwidth — a Tron-native cost the
|
|
40
|
+
// EVM compatibility layer's `eth_estimateGas` does not surface — is included in
|
|
41
|
+
// `auxiliaryNativeTokenCost`. Otherwise fall back to the EVM-flavoured custom gas
|
|
42
|
+
// token query.
|
|
43
|
+
const QueryCtor = chainIsTvm(chainId) ? TvmQuery : CustomGasTokenQueries;
|
|
44
|
+
return new QueryCtor({
|
|
39
45
|
queryBaseArgs: [
|
|
40
46
|
provider as providers.Provider,
|
|
41
47
|
symbolMapping,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { arch } from "../..";
|
|
2
|
+
import { RelayData } from "../../interfaces";
|
|
3
|
+
import { BigNumber } from "../../utils";
|
|
4
|
+
import { CustomGasTokenQueries } from "./customGasToken";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* TVM (TRON) query implementation. Extends `CustomGasTokenQueries` to add bandwidth
|
|
8
|
+
* accounting via `getAuxiliaryNativeTokenCost`, which the base EVM path returns 0 for.
|
|
9
|
+
*
|
|
10
|
+
* Energy (Tron's analogue of gas) is already estimated by `voidSigner.estimateGas`
|
|
11
|
+
* against the EVM-compat RPC and surfaces in `tokenGasCost`. Bandwidth is a separate
|
|
12
|
+
* Tron-native resource that the EVM compatibility layer does not surface, so we
|
|
13
|
+
* estimate it here from the deposit's `message` length and a fixed `fillRelay`
|
|
14
|
+
* calldata footprint.
|
|
15
|
+
*/
|
|
16
|
+
export class TvmQuery extends CustomGasTokenQueries {
|
|
17
|
+
override getAuxiliaryNativeTokenCost(deposit: RelayData): BigNumber {
|
|
18
|
+
return arch.tvm.getAuxiliaryNativeTokenCost(deposit);
|
|
19
|
+
}
|
|
20
|
+
}
|