TIP-937: Stepwise Closure of Bancor Trading

未关闭
#937 7 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
blockchain

调研方向

Start with ProposalUtil.java and the validate() methods of ExchangeCreateActuator, ExchangeInjectActuator, ExchangeTransactionActuator, and ExchangeWithdrawActuator. Review the proposal-validation and level-by-contract test cases described in the issue, including transaction build, broadcast, packing, and block validation paths. Done means enforcing the irreversible levels, preserving read-only APIs and parameter-98 behavior, and covering persistence and funds-safety boundaries.

由索引模型根据 Issue 内容生成。

描述

tip: 937
title: Stepwise Closure of Bancor Trading
author: [email protected]
discussions-to: https://github.com/tronprotocol/tips/issues/937
status: Draft
type: Standards Track
category: Core
created: 2026-09-22

Simple Summary

Introduce a new on-chain parameter CLOSE_EXCHANGE to retire the built-in Bancor trading feature (ExchangeCreate / ExchangeInject / ExchangeTransaction / ExchangeWithdraw) in irreversible, stepwise levels.

Abstract

This proposal introduces a new on-chain parameter CLOSE_EXCHANGE to retire the built-in Bancor trading feature in irreversible steps.
The Bancor trading feature consists of four distinct operation contracts:

  • ExchangeCreate: pays the creation fee to create a trading pair, injects the initial pool funds, and sets the initial exchange ratio of the pair
  • ExchangeInject: the pool creator injects one token into the pool and receives the other token in proportion to the pool ratio
  • ExchangeTransaction: trades against a trading pair, computing the receivable amount of the other token with the Bancor formula; rejected since v4.8.0.1 by a hardcoded consensus gate (the reserved parameter 98 of TIP-836 can re-enable it)
  • ExchangeWithdraw: the pool creator withdraws one token from the pool and pays the other token in proportion
    CLOSE_EXCHANGE has three values, the initial value is 0, and it can only be raised one way and never lowered:
  • Value 0: default state, nothing is closed
  • Value 1: closes ExchangeCreate / ExchangeInject / ExchangeTransaction
  • Value 2: on top of value 1, additionally closes ExchangeWithdraw

Motivation

  • ExchangeTransaction has been rejected since v4.8.0.1 by a hardcoded consensus gate due to floating-point precision issues; parameter 98 ALLOW_HARDEN_EXCHANGE_CALCULATION, which controls the re-enable of this contract, has never been touched by any proposal, and there is no schedule on mainnet to enable it.
  • The pair-creation contract ExchangeCreate is functional but long dormant: 186 trading pairs, the latest created on 2024-04-19; a 20-month transaction scan over all 107 existing non-zero-pool creators shows 0 calls of the four Bancor contract types; approximately 940,286 TRX are locked in the pools, controlled solely by the pair creators.
  • The ecosystem has migrated to various on-chain exchanges; the idle write entry means ongoing maintenance/testing cost and revival/regression risk.
  • The graded one-way close allows pair creators to withdraw funds while the new proposal parameter is at value 1, with the committee proposal deciding whether to move up to value 2.

Specification

Parameter values and behavior matrix
  • Value 0 (default): No additional restrictions are introduced; existing validation rules remain unchanged (in particular, ExchangeTransaction remains subject to the v4.8.0.1 gate and parameter 98, and ExchangeCreate still requires EXCHANGE_CREATE_FEE).
  • Value 1 (partial closure): ExchangeCreate, ExchangeInject, ExchangeTransaction are rejected consistently at the three entrances — broadcast, packing, block validation. ExchangeWithdraw is unaffected, creators can still withdraw pool assets.
  • Value 2 (terminal state): On top of value 1, ExchangeWithdraw is additionally rejected (cumulative semantics); all four contracts are closed.
Value ExchangeCreate ExchangeInject ExchangeTransaction ExchangeWithdraw
0 unchanged unchanged unchanged (varies with parameter 98) unchanged
1 rejected rejected rejected accepted
2 rejected rejected rejected rejected

This parameter does not affect the availability of the read-only query APIs (getexchangebyid, listexchanges).

Value constraints and restrictions on other parameters

The CLOSE_EXCHANGE parameter requires a fork gate, rejection of repeated same-value proposals, only +1 steps with the value in [1,2], and no combination constraint: a CLOSE_EXCHANGE proposal may be combined with any other chain parameters (all entries are applied unconditionally, so the result is order-independent). Moreover, once this parameter has been set to 1 or 2, EXCHANGE_CREATE_FEE and ALLOW_HARDEN_EXCHANGE_CALCULATION should no longer be modified.
The +1 stepping is implemented in the validator of ProposalUtil.java:

case CLOSE_EXCHANGE: {
  if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_3)) {
    throw new ContractValidateException("Bad chain parameter id [CLOSE_EXCHANGE]");
  }
  int current = dynamicPropertiesStore.getCloseExchange();
  // Irreversible by design: CLOSE_EXCHANGE only advances one level at a time.
  if (value == current) {
    throw new ContractValidateException(
        "[CLOSE_EXCHANGE] has been set to " + value + ", no need to propose again");
  }
  if (current == 2) {
    throw new ContractValidateException(
        "[CLOSE_EXCHANGE] has reached its terminal value 2; no further change is allowed");
  }
  if (value != current + 1 || value < 1 || value > 2) {
    throw new ContractValidateException(
        "This value[CLOSE_EXCHANGE] must be " + (current + 1) + " and within [1,2]");
  }
  break;
}

Rationale

The transaction-close gate can be implemented in two ways; the actuator validate layer (Option 2 in the Implementation section) is preferred: errors surface at build time, the change is confined to the four actuators, and it follows the precedent of proposals 44/35. The Manager three-entrance option (Option 1) is the same approach as the existing ExchangeTransaction rejection and is therefore kept as a reference; the two are equivalent at the consensus layer and differ in interception timing and change location.

Implementation

Option 1: Manager three-entrance gating (similar to parameter 98)

Rejection at the three transaction entrances in Manager, with a single predicate isClosedExchange + closedExchangeLevelRequired shared by all three, aligned at the same layer as the existing ExchangeTransaction rejection logic:

  • Broadcast (pushTransaction): API response returned to the user; the contract name and level vary with the rejected contract and the current value:
Contract validate error : ExchangeCreateContract is rejected by exchange close level 1
  • Packing (SR generateBlock) silently skips:
// generateBlock: isClosedExchange(tx) -> continue
  • Block validation (processBlock) throws the same rejection message:
ExchangeWithdrawContract is rejected by exchange close level 2

The exception is thrown during block validation; a block containing transactions of closed contracts will be rejected.

Option 2: actuator validate-layer gating (similar to parameters 35/44)

Add the level check to the validate() of each Bancor-trading actuator: ExchangeCreate / ExchangeInject / ExchangeTransaction are rejected at level >= 1, ExchangeWithdraw at level = 2; the error message is the same as in Option 1:

// ExchangeCreateActuator.validate()
if (chainBaseManager.getDynamicPropertiesStore().getCloseExchange() >= 1) {
  throw new ContractValidateException("ExchangeCreateContract is rejected by exchange close level 1");
}

actuator.validate() runs on all three consensus paths — broadcast, packing, block validation (processTransaction -> TransactionTrace -> RuntimeImpl) — so consensus coverage is complete.
The build phase is also covered: Wallet.createTransactionCapsule pre-runs actuator.validate(), so users see the rejection when constructing the transaction instead of waiting until broadcast.
Proposal parameter 44 (parameter: ALLOW_MARKET_TRANSACTION, actuators: MarketSellAssetActuator / MarketCancelOrderActuator) and proposal parameter 35 (parameter: FORBID_TRANSFER_TO_CONTRACT, actuators: TransferActuator / TransferAssetActuator) both use this pattern.

Test Cases

  • Proposal validation: before the fork gate, any CLOSE_EXCHANGE proposal is rejected with Bad chain parameter id [CLOSE_EXCHANGE]; only +1 steps within [1,2] are accepted (0 -> 1, 1 -> 2); same-value, skipped, out-of-range, and downgrade proposals are rejected with the documented error messages; the terminal value 2 rejects any further change; a CLOSE_EXCHANGE proposal may be combined with any other chain parameters, and every entry is applied unconditionally.
  • Level x contract matrix: at level 1, ExchangeCreate/ExchangeInject/ExchangeTransaction are rejected with <ContractType> is rejected by exchange close level 1 while ExchangeWithdraw stays open; at level 2 all four are rejected. Each rejection is asserted identically at transaction build time, broadcast, block packing (the closed transaction is skipped), and block validation (the block is rejected).
  • The legacy parameter-98 rejection of ExchangeTransaction is preserved and cannot bypass the close gate (with harden mode enabled it is still rejected at level >= 1).
  • Persistence and boundaries: the level defaults to 0, applies from the activating maintenance block onward, and survives node restart; read-only APIs getexchangebyid/listexchanges and the chain parameter getCloseExchange remain available at every level.
  • Funds safety: at level 1 creators can still withdraw pool funds via ExchangeWithdraw; blocks containing only open contracts are accepted at every level.

Backwards Compatibility

This proposal can only be submitted through the proposal mechanism; after the parameter has been changed, modifications to EXCHANGE_CREATE_FEE and ALLOW_HARDEN_EXCHANGE_CALCULATION will be restricted.

Copyright

Copyright and related rights waived via CC0.

主要语言
没有语言数据
星标
341
派生
347
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

tronprotocol/tips 的其他 Issue

查看 tronprotocol/tips 的全部 Issue

相似的 Issue

更多 Blockchain Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。