@across-protocol/sdk 4.3.165-beta.1 → 4.3.166-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/cjs/src/arch/tvm/MessageUtils.d.ts +6 -0
  2. package/dist/cjs/src/arch/tvm/MessageUtils.js +27 -0
  3. package/dist/cjs/src/arch/tvm/MessageUtils.js.map +1 -0
  4. package/dist/cjs/src/arch/tvm/index.d.ts +1 -0
  5. package/dist/cjs/src/arch/tvm/index.js +1 -0
  6. package/dist/cjs/src/arch/tvm/index.js.map +1 -1
  7. package/dist/cjs/src/relayFeeCalculator/chain-queries/factory.js +3 -1
  8. package/dist/cjs/src/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  9. package/dist/cjs/src/relayFeeCalculator/chain-queries/index.d.ts +1 -0
  10. package/dist/cjs/src/relayFeeCalculator/chain-queries/index.js +1 -0
  11. package/dist/cjs/src/relayFeeCalculator/chain-queries/index.js.map +1 -1
  12. package/dist/cjs/src/relayFeeCalculator/chain-queries/tvmQuery.d.ts +6 -0
  13. package/dist/cjs/src/relayFeeCalculator/chain-queries/tvmQuery.js +12 -0
  14. package/dist/cjs/src/relayFeeCalculator/chain-queries/tvmQuery.js.map +1 -0
  15. package/dist/cjs/src/utils/abi/typechain/TronMulticallHandler.d.ts +153 -0
  16. package/dist/cjs/src/utils/abi/typechain/TronMulticallHandler.js +3 -0
  17. package/dist/cjs/src/utils/abi/typechain/TronMulticallHandler.js.map +1 -0
  18. package/dist/cjs/src/utils/abi/typechain/factories/TronMulticallHandler__factory.d.ts +231 -0
  19. package/dist/cjs/src/utils/abi/typechain/factories/TronMulticallHandler__factory.js +306 -0
  20. package/dist/cjs/src/utils/abi/typechain/factories/TronMulticallHandler__factory.js.map +1 -0
  21. package/dist/cjs/src/utils/abi/typechain/factories/index.d.ts +1 -0
  22. package/dist/cjs/src/utils/abi/typechain/factories/index.js +4 -2
  23. package/dist/cjs/src/utils/abi/typechain/factories/index.js.map +1 -1
  24. package/dist/cjs/src/utils/abi/typechain/index.d.ts +2 -0
  25. package/dist/cjs/src/utils/abi/typechain/index.js +4 -2
  26. package/dist/cjs/src/utils/abi/typechain/index.js.map +1 -1
  27. package/dist/esm/src/arch/tvm/MessageUtils.d.ts +22 -0
  28. package/dist/esm/src/arch/tvm/MessageUtils.js +61 -0
  29. package/dist/esm/src/arch/tvm/MessageUtils.js.map +1 -0
  30. package/dist/esm/src/arch/tvm/index.d.ts +1 -0
  31. package/dist/esm/src/arch/tvm/index.js +1 -0
  32. package/dist/esm/src/arch/tvm/index.js.map +1 -1
  33. package/dist/esm/src/relayFeeCalculator/chain-queries/factory.js +8 -2
  34. package/dist/esm/src/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  35. package/dist/esm/src/relayFeeCalculator/chain-queries/index.d.ts +1 -0
  36. package/dist/esm/src/relayFeeCalculator/chain-queries/index.js +1 -0
  37. package/dist/esm/src/relayFeeCalculator/chain-queries/index.js.map +1 -1
  38. package/dist/esm/src/relayFeeCalculator/chain-queries/tvmQuery.d.ts +16 -0
  39. package/dist/esm/src/relayFeeCalculator/chain-queries/tvmQuery.js +18 -0
  40. package/dist/esm/src/relayFeeCalculator/chain-queries/tvmQuery.js.map +1 -0
  41. package/dist/esm/src/utils/abi/typechain/TronMulticallHandler.d.ts +153 -0
  42. package/dist/esm/src/utils/abi/typechain/TronMulticallHandler.js +2 -0
  43. package/dist/esm/src/utils/abi/typechain/TronMulticallHandler.js.map +1 -0
  44. package/dist/esm/src/utils/abi/typechain/factories/TronMulticallHandler__factory.d.ts +231 -0
  45. package/dist/esm/src/utils/abi/typechain/factories/TronMulticallHandler__factory.js +305 -0
  46. package/dist/esm/src/utils/abi/typechain/factories/TronMulticallHandler__factory.js.map +1 -0
  47. package/dist/esm/src/utils/abi/typechain/factories/index.d.ts +1 -0
  48. package/dist/esm/src/utils/abi/typechain/factories/index.js +1 -0
  49. package/dist/esm/src/utils/abi/typechain/factories/index.js.map +1 -1
  50. package/dist/esm/src/utils/abi/typechain/index.d.ts +2 -0
  51. package/dist/esm/src/utils/abi/typechain/index.js +1 -0
  52. package/dist/esm/src/utils/abi/typechain/index.js.map +1 -1
  53. package/dist/types/src/arch/tvm/MessageUtils.d.ts +23 -0
  54. package/dist/types/src/arch/tvm/MessageUtils.d.ts.map +1 -0
  55. package/dist/types/src/arch/tvm/index.d.ts +1 -0
  56. package/dist/types/src/arch/tvm/index.d.ts.map +1 -1
  57. package/dist/types/src/relayFeeCalculator/chain-queries/factory.d.ts.map +1 -1
  58. package/dist/types/src/relayFeeCalculator/chain-queries/index.d.ts +1 -0
  59. package/dist/types/src/relayFeeCalculator/chain-queries/index.d.ts.map +1 -1
  60. package/dist/types/src/relayFeeCalculator/chain-queries/tvmQuery.d.ts +17 -0
  61. package/dist/types/src/relayFeeCalculator/chain-queries/tvmQuery.d.ts.map +1 -0
  62. package/dist/types/src/utils/abi/typechain/TronMulticallHandler.d.ts +154 -0
  63. package/dist/types/src/utils/abi/typechain/TronMulticallHandler.d.ts.map +1 -0
  64. package/dist/types/src/utils/abi/typechain/factories/TronMulticallHandler__factory.d.ts +232 -0
  65. package/dist/types/src/utils/abi/typechain/factories/TronMulticallHandler__factory.d.ts.map +1 -0
  66. package/dist/types/src/utils/abi/typechain/factories/index.d.ts +1 -0
  67. package/dist/types/src/utils/abi/typechain/factories/index.d.ts.map +1 -1
  68. package/dist/types/src/utils/abi/typechain/index.d.ts +2 -0
  69. package/dist/types/src/utils/abi/typechain/index.d.ts.map +1 -1
  70. package/package.json +2 -2
  71. package/src/arch/tvm/MessageUtils.ts +72 -0
  72. package/src/arch/tvm/index.ts +1 -0
  73. package/src/relayFeeCalculator/chain-queries/factory.ts +8 -2
  74. package/src/relayFeeCalculator/chain-queries/index.ts +1 -0
  75. package/src/relayFeeCalculator/chain-queries/tvmQuery.ts +20 -0
  76. package/src/utils/abi/contracts/TronMulticallHandler.json +291 -0
  77. package/src/utils/abi/typechain/TronMulticallHandler.ts +327 -0
  78. package/src/utils/abi/typechain/factories/TronMulticallHandler__factory.ts +319 -0
  79. package/src/utils/abi/typechain/factories/index.ts +1 -0
  80. package/src/utils/abi/typechain/index.ts +2 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@across-protocol/sdk",
3
3
  "author": "UMA Team",
4
- "version": "4.3.165-beta.1",
4
+ "version": "4.3.166-alpha.0",
5
5
  "license": "AGPL-3.0",
6
6
  "homepage": "https://docs.across.to/reference/sdk",
7
7
  "repository": {
@@ -81,7 +81,7 @@
81
81
  },
82
82
  "dependencies": {
83
83
  "@across-protocol/constants": "^3.1.110",
84
- "@across-protocol/contracts": "5.0.12-alpha.2",
84
+ "@across-protocol/contracts": "5.0.15",
85
85
  "@coral-xyz/anchor": "^0.30.1",
86
86
  "@eth-optimism/sdk": "^3.3.1",
87
87
  "@ethersproject/bignumber": "^5.7.0",
@@ -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;
@@ -1,2 +1,3 @@
1
1
  export * from "./SpokeUtils";
2
2
  export * from "./TransactionUtils";
3
+ export * from "./MessageUtils";
@@ -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
- return new CustomGasTokenQueries({
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,
@@ -2,3 +2,4 @@ export * from "./baseQuery";
2
2
  export * from "./factory";
3
3
  export * from "./customGasToken";
4
4
  export * from "./svmQuery";
5
+ export * from "./tvmQuery";
@@ -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
+ }
@@ -0,0 +1,291 @@
1
+ [
2
+ {
3
+ "type": "receive",
4
+ "stateMutability": "payable"
5
+ },
6
+ {
7
+ "type": "function",
8
+ "name": "attemptCalls",
9
+ "inputs": [
10
+ {
11
+ "name": "calls",
12
+ "type": "tuple[]",
13
+ "internalType": "struct MulticallHandler.Call[]",
14
+ "components": [
15
+ {
16
+ "name": "target",
17
+ "type": "address",
18
+ "internalType": "address"
19
+ },
20
+ {
21
+ "name": "callData",
22
+ "type": "bytes",
23
+ "internalType": "bytes"
24
+ },
25
+ {
26
+ "name": "value",
27
+ "type": "uint256",
28
+ "internalType": "uint256"
29
+ }
30
+ ]
31
+ }
32
+ ],
33
+ "outputs": [],
34
+ "stateMutability": "nonpayable"
35
+ },
36
+ {
37
+ "type": "function",
38
+ "name": "drainLeftoverTokens",
39
+ "inputs": [
40
+ {
41
+ "name": "token",
42
+ "type": "address",
43
+ "internalType": "address"
44
+ },
45
+ {
46
+ "name": "destination",
47
+ "type": "address",
48
+ "internalType": "address payable"
49
+ }
50
+ ],
51
+ "outputs": [],
52
+ "stateMutability": "nonpayable"
53
+ },
54
+ {
55
+ "type": "function",
56
+ "name": "handleV3AcrossMessage",
57
+ "inputs": [
58
+ {
59
+ "name": "token",
60
+ "type": "address",
61
+ "internalType": "address"
62
+ },
63
+ {
64
+ "name": "",
65
+ "type": "uint256",
66
+ "internalType": "uint256"
67
+ },
68
+ {
69
+ "name": "",
70
+ "type": "address",
71
+ "internalType": "address"
72
+ },
73
+ {
74
+ "name": "message",
75
+ "type": "bytes",
76
+ "internalType": "bytes"
77
+ }
78
+ ],
79
+ "outputs": [],
80
+ "stateMutability": "nonpayable"
81
+ },
82
+ {
83
+ "type": "function",
84
+ "name": "makeCallWithBalance",
85
+ "inputs": [
86
+ {
87
+ "name": "target",
88
+ "type": "address",
89
+ "internalType": "address"
90
+ },
91
+ {
92
+ "name": "callData",
93
+ "type": "bytes",
94
+ "internalType": "bytes"
95
+ },
96
+ {
97
+ "name": "value",
98
+ "type": "uint256",
99
+ "internalType": "uint256"
100
+ },
101
+ {
102
+ "name": "replacement",
103
+ "type": "tuple[]",
104
+ "internalType": "struct MulticallHandler.Replacement[]",
105
+ "components": [
106
+ {
107
+ "name": "token",
108
+ "type": "address",
109
+ "internalType": "address"
110
+ },
111
+ {
112
+ "name": "offset",
113
+ "type": "uint256",
114
+ "internalType": "uint256"
115
+ }
116
+ ]
117
+ }
118
+ ],
119
+ "outputs": [],
120
+ "stateMutability": "nonpayable"
121
+ },
122
+ {
123
+ "type": "event",
124
+ "name": "CallsFailed",
125
+ "inputs": [
126
+ {
127
+ "name": "calls",
128
+ "type": "tuple[]",
129
+ "indexed": false,
130
+ "internalType": "struct MulticallHandler.Call[]",
131
+ "components": [
132
+ {
133
+ "name": "target",
134
+ "type": "address",
135
+ "internalType": "address"
136
+ },
137
+ {
138
+ "name": "callData",
139
+ "type": "bytes",
140
+ "internalType": "bytes"
141
+ },
142
+ {
143
+ "name": "value",
144
+ "type": "uint256",
145
+ "internalType": "uint256"
146
+ }
147
+ ]
148
+ },
149
+ {
150
+ "name": "fallbackRecipient",
151
+ "type": "address",
152
+ "indexed": true,
153
+ "internalType": "address"
154
+ }
155
+ ],
156
+ "anonymous": false
157
+ },
158
+ {
159
+ "type": "event",
160
+ "name": "DrainedTokens",
161
+ "inputs": [
162
+ {
163
+ "name": "recipient",
164
+ "type": "address",
165
+ "indexed": true,
166
+ "internalType": "address"
167
+ },
168
+ {
169
+ "name": "token",
170
+ "type": "address",
171
+ "indexed": true,
172
+ "internalType": "address"
173
+ },
174
+ {
175
+ "name": "amount",
176
+ "type": "uint256",
177
+ "indexed": true,
178
+ "internalType": "uint256"
179
+ }
180
+ ],
181
+ "anonymous": false
182
+ },
183
+ {
184
+ "type": "error",
185
+ "name": "CallReverted",
186
+ "inputs": [
187
+ {
188
+ "name": "index",
189
+ "type": "uint256",
190
+ "internalType": "uint256"
191
+ },
192
+ {
193
+ "name": "calls",
194
+ "type": "tuple[]",
195
+ "internalType": "struct MulticallHandler.Call[]",
196
+ "components": [
197
+ {
198
+ "name": "target",
199
+ "type": "address",
200
+ "internalType": "address"
201
+ },
202
+ {
203
+ "name": "callData",
204
+ "type": "bytes",
205
+ "internalType": "bytes"
206
+ },
207
+ {
208
+ "name": "value",
209
+ "type": "uint256",
210
+ "internalType": "uint256"
211
+ }
212
+ ]
213
+ }
214
+ ]
215
+ },
216
+ {
217
+ "type": "error",
218
+ "name": "CalldataTooShort",
219
+ "inputs": [
220
+ {
221
+ "name": "callDataLength",
222
+ "type": "uint256",
223
+ "internalType": "uint256"
224
+ },
225
+ {
226
+ "name": "offset",
227
+ "type": "uint256",
228
+ "internalType": "uint256"
229
+ }
230
+ ]
231
+ },
232
+ {
233
+ "type": "error",
234
+ "name": "InvalidCall",
235
+ "inputs": [
236
+ {
237
+ "name": "index",
238
+ "type": "uint256",
239
+ "internalType": "uint256"
240
+ },
241
+ {
242
+ "name": "calls",
243
+ "type": "tuple[]",
244
+ "internalType": "struct MulticallHandler.Call[]",
245
+ "components": [
246
+ {
247
+ "name": "target",
248
+ "type": "address",
249
+ "internalType": "address"
250
+ },
251
+ {
252
+ "name": "callData",
253
+ "type": "bytes",
254
+ "internalType": "bytes"
255
+ },
256
+ {
257
+ "name": "value",
258
+ "type": "uint256",
259
+ "internalType": "uint256"
260
+ }
261
+ ]
262
+ }
263
+ ]
264
+ },
265
+ {
266
+ "type": "error",
267
+ "name": "NotSelf",
268
+ "inputs": []
269
+ },
270
+ {
271
+ "type": "error",
272
+ "name": "ReplacementCallFailed",
273
+ "inputs": [
274
+ {
275
+ "name": "callData",
276
+ "type": "bytes",
277
+ "internalType": "bytes"
278
+ }
279
+ ]
280
+ },
281
+ {
282
+ "type": "error",
283
+ "name": "TronTransferBalanceMismatch",
284
+ "inputs": []
285
+ },
286
+ {
287
+ "type": "error",
288
+ "name": "TronTransferCallReverted",
289
+ "inputs": []
290
+ }
291
+ ]