-
Notifications
You must be signed in to change notification settings - Fork 117
Custom Contract Fees Mechanism #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
In my opinion only gas should be used (at least now) it's easier to compute and attach the gas into the transaction in calculateFeeMethod, and it's good for the strength of the network, it make the gas more useful. Also, neo is not divisible, so I think there is no reason to pay one neo for one smart contract call. Also I think we don't need to add any extra syscall, it will be transparent to the user who make the transaction. |
Some projects may have their own tokens that need to be taken into account. |
|
I'd like to see a |
This will add the requirement of do a transfer before (or after) the execution, so it's not transparent to the transaction script. Maybe if we use gas we can do it transparent. |
|
I thought about it and realized that if the contract uses its own token, then it doesn’t really need this API, so I agreed to support only GAS. |
As @ixje said, if we use the same contract we reduce the configuration, the contract can implement the required method and call to another contract if they want. |
I think that the design should be draw to support that in the future. If we really move in a way to have a "native DEX", this can become a possible scenario much easier. Also, it would be interesting if Contracts create a Liquidity Pool only accessible for such cases, maybe the contract owner could provide liquidity himself. So, the pool is just used for such cases. |
roman-khimov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- GAS-only fees can be implemented much easier with #204 (comment)
- Generic token fees are just a specific kind of transfer to me. Contracts can call
transfer(someone, me, amount)and this is guarded with witness scopes, but the mechanism of scopes currently gives permissions for arbitrary changes and that's the thing that can be improved. If we could express a permission to transfer X amount from A to B in scopes I think this all would be solved immediately, contracts would just use regular transfer calls for their needs and it'd not require any ABI changes. Related to #137.
| ```csharp | ||
| public interface IFeeCalculator | ||
| { | ||
| BigInteger CalculateFee(ByteString method, object[] args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Methods are defined using NEP-25 JSON, not using C#, see any other NEP defining methods for example.
|
|
||
| ### 3. **Decorators** | ||
|
|
||
| #### C# Attributes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation detail not relevant to the VM/runtime spec.
| public static UInt160 GetReport(uint userId) { ... } | ||
| ``` | ||
|
|
||
| #### DevPack Export Logic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
NEP: Custom Contract Fees Mechanism
NEP: TBD
Title: Custom Contract Fees with ABI Declaration and Runtime Enforcement
Author: Chris Schuchardt [email protected]
Type: Standard
Status: Draft
Created: 2025-10-27
Abstract
This NEP introduces a standardized mechanism for smart contracts to declare custom execution fees in addition to standard network gas. These fees are paid by the caller to the contract owner (or designated beneficiary) upon successful invocation. The fee structure is declared in the contract's ABI using a new
"fee"metadata field, supported by updated DevPack tooling and enforced by the Neo VM at runtime.Motivation
Many dApps require micro-transactions, subscription models, or usage-based billing directly within smart contracts. While GAS covers network costs, there is no native way to charge contract-level fees in NEO or NEP-17 tokens. This NEP enables:
Specification
1. ABI Extension: Fee Declaration
A new optional
"fee"object is added to method definitions in the ABI.Field Details:
asset"NEO","GAS", or NEP-17 contract hashamountmode=fixed)beneficiarymode"fixed"or"dynamic"dynamicScriptHashmode=dynamic)calculateFee(...)2. Dynamic Fee Computation Interface
Contracts declaring
mode: "dynamic"must reference a fee calculator contract implementing:3. Decorators
C# Attributes
DevPack Export Logic
[Fee]attribute is parsed during ABI generationfeefield in method ABICalculatorimplementsIFeeCalculatorifmode=dynamic4. Runtime Enforcement (Neo VM)
Invocation Flow
Safety Guarantees
ExecutionEnginesnapshotSyscall Additions
5. Contract Owner & Beneficiary
beneficiaryoverrides owner per methodSecurity Considerations
Backwards Compatibility
[Fee]→ no fee chargedAppendix
Example Contract