Skip to content

Commit 0ba3252

Browse files
committed
fix: address PR review comments
- Add hexAddress to deployment files (mainnet.json and nile.json) - Move tron/nile chain definitions from declarative to tron folder - Update DeclarativeChainName type to remove tron/nile - Use erc20FeeProxyArtifact.getDeploymentInformation() instead of hardcoded values - Rename tron-fee-proxy.ts to trc20-fee-proxy.ts for clarity - Make fee limit configurable in utils-tron.ts with defaults
1 parent 5775865 commit 0ba3252

12 files changed

Lines changed: 27 additions & 20 deletions

File tree

packages/currency/src/chains/declarative/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { CurrencyTypes } from '@requestnetwork/types';
22

3-
import * as TronDefinition from './data/tron';
4-
import * as NileDefinition from './data/nile';
53
import * as SolanaDefinition from './data/solana';
64
import * as StarknetDefinition from './data/starknet';
75
import * as TonDefinition from './data/ton';
@@ -11,8 +9,6 @@ import * as SuiDefinition from './data/sui';
119
export type DeclarativeChain = CurrencyTypes.Chain;
1210

1311
export const chains: Record<CurrencyTypes.DeclarativeChainName, DeclarativeChain> = {
14-
tron: TronDefinition,
15-
nile: NileDefinition,
1612
solana: SolanaDefinition,
1713
starknet: StarknetDefinition,
1814
ton: TonDefinition,
File renamed without changes.
File renamed without changes.

packages/currency/src/chains/tron/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CurrencyTypes } from '@requestnetwork/types';
22

3-
import * as TronDefinition from '../declarative/data/tron';
4-
import * as NileDefinition from '../declarative/data/nile';
3+
import * as TronDefinition from './data/tron';
4+
import * as NileDefinition from './data/nile';
55

66
export type TronChain = CurrencyTypes.Chain;
77

packages/payment-detection/src/tron/tron-fee-proxy-detector.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,8 @@ export class TronERC20FeeProxyPaymentDetector extends ERC20FeeProxyPaymentDetect
5050
_paymentNetworkVersion?: string,
5151
): { address: string; creationBlockNumber: number } {
5252
void _paymentNetworkVersion; // Parameter kept for API compatibility
53-
// For TRON, we use the 'tron' version of the artifact
54-
const address = erc20FeeProxyArtifact.getAddress(network, 'tron');
55-
const creationBlockNumber =
56-
network === 'tron'
57-
? 79216121 // TRON mainnet
58-
: 63208782; // Nile testnet
59-
60-
return { address, creationBlockNumber };
53+
// For TRON, we use the 'tron' version of the artifact which contains Tron-specific deployments
54+
return erc20FeeProxyArtifact.getDeploymentInformation(network, 'tron');
6155
}
6256

6357
/**

packages/payment-processor/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export * as Escrow from './payment/erc20-escrow-payment';
2929
export * from './payment/prepared-transaction';
3030
export * from './payment/utils-near';
3131
export * from './payment/utils-tron';
32-
export * from './payment/tron-fee-proxy';
32+
export * from './payment/trc20-fee-proxy';
3333
export * from './payment/single-request-forwarder';
3434
export * from './payment/erc20-recurring-payment-proxy';
3535
export * from './payment/erc20-commerce-escrow-wrapper';

packages/payment-processor/src/payment/tron-fee-proxy.ts renamed to packages/payment-processor/src/payment/trc20-fee-proxy.ts

File renamed without changes.

packages/payment-processor/src/payment/utils-tron.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,30 @@ export const getTronAllowance = async (
137137
}
138138
};
139139

140+
/** Default fee limit for TRC20 approval (100 TRX in SUN) */
141+
export const DEFAULT_APPROVAL_FEE_LIMIT = 100_000_000;
142+
143+
/** Default fee limit for TRC20 fee proxy payment (150 TRX in SUN) */
144+
export const DEFAULT_PAYMENT_FEE_LIMIT = 150_000_000;
145+
140146
/**
141147
* Approves the ERC20FeeProxy contract to spend TRC20 tokens
148+
* @param feeLimit - Optional fee limit in SUN (1 TRX = 1,000,000 SUN). Defaults to 100 TRX.
142149
*/
143150
export const approveTrc20 = async (
144151
tronWeb: TronWeb,
145152
tokenAddress: string,
146153
network: CurrencyTypes.TronChainName,
147154
amount: BigNumberish,
148155
callback?: ITronTransactionCallback,
156+
feeLimit: number = DEFAULT_APPROVAL_FEE_LIMIT,
149157
): Promise<string> => {
150158
const proxyAddress = getERC20FeeProxyAddress(network);
151159
const contract = await tronWeb.contract(TRC20_ABI, tokenAddress);
152160

153161
try {
154162
const result = await contract.approve(proxyAddress, amount.toString()).send({
155-
feeLimit: 100000000, // 100 TRX fee limit
163+
feeLimit,
156164
shouldPollResponse: true,
157165
});
158166

@@ -168,6 +176,7 @@ export const approveTrc20 = async (
168176

169177
/**
170178
* Processes a TRC20 fee proxy payment on Tron
179+
* @param feeLimit - Optional fee limit in SUN (1 TRX = 1,000,000 SUN). Defaults to 150 TRX.
171180
*/
172181
export const processTronFeeProxyPayment = async (
173182
tronWeb: TronWeb,
@@ -179,6 +188,7 @@ export const processTronFeeProxyPayment = async (
179188
feeAmount: BigNumberish,
180189
feeAddress: string,
181190
callback?: ITronTransactionCallback,
191+
feeLimit: number = DEFAULT_PAYMENT_FEE_LIMIT,
182192
): Promise<string> => {
183193
// Validate addresses
184194
if (!isValidTronAddress(to)) {
@@ -213,7 +223,7 @@ export const processTronFeeProxyPayment = async (
213223
feeAddress,
214224
)
215225
.send({
216-
feeLimit: 150000000, // 150 TRX fee limit for proxy call
226+
feeLimit,
217227
shouldPollResponse: true,
218228
});
219229

packages/payment-processor/test/payment/tron-fee-proxy.test.ts renamed to packages/payment-processor/test/payment/trc20-fee-proxy.test.ts

File renamed without changes.

packages/smart-contracts/deployments/tron/mainnet.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"contracts": {
88
"ERC20FeeProxy": {
99
"address": "TCUDPYnS9dH3WvFEaE7wN7vnDa51J4R4fd",
10+
"hexAddress": "411b6ca35d39842cf8fbe49000653a1505412da659",
1011
"creationBlockNumber": 79216121
1112
}
1213
}

0 commit comments

Comments
 (0)