-
Notifications
You must be signed in to change notification settings - Fork 16
feat: add Greenfield API endpoints for EVM USDt chains #31
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
Open
learntheropes
wants to merge
15
commits into
btcpayserver-tether:develop
Choose a base branch
from
learntheropes:feature/evm-greenfield
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ae8e958
feat: add Ethereum ERC20 USDt support
rockstardev 60d87ba
refactor: tweaks and improvements
rockstardev 9e637af
fix: resolve build problems
rockstardev fb37031
feat: add wallet settings for USDT ETH
rockstardev 1ee7b55
fix: resolve USDT ETH listening problems
rockstardev cafec7c
feat: add logo
rockstardev c7f18df
feat: add server settings for USDT ETH
rockstardev a8b875e
fix: resolve navigation to server and store pages
rockstardev 6d847b9
fix: adjust naming convention
b0l0k 0c123ff
ci: handle rc flow
b0l0k eb40e5f
feat: add Polygon PoS (USDT-POLYGON) support
learntheropes df6554c
chore: migrate to .NET 10
learntheropes 28da4ae
feat: add Greenfield API endpoints for EVM USDt chains
learntheropes 36d4f03
feat: accept array of addresses in EVM POST endpoint
learntheropes 0574e0f
fix: persist store after address changes in EVM endpoints
learntheropes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,5 @@ | |
| .idea | ||
| Plugins/packed | ||
| .vs/ | ||
| *.DotSettings | ||
| *.DotSettings.user | ||
2 changes: 1 addition & 1 deletion
2
BTCPayServer.Plugins.USDt.Tests/BTCPayServer.Plugins.USDt.Tests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
BTCPayServer.Plugins.USDt/Configuration/Ethereum/EthUSDtLikeConfigurationItem.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using System; | ||
|
|
||
| namespace BTCPayServer.Plugins.USDt.Configuration.Ethereum; | ||
|
|
||
| public record EthUSDtLikeConfigurationItem(string Chain) : USDtPluginConfigurationItem | ||
| { | ||
| public required Uri JsonRpcUri { get; init; } | ||
| public required string SmartContractAddress { get; init; } | ||
| public override string Chain { get; } = Chain; | ||
| public override required string Currency { get; init; } | ||
| public required string DisplayName { get; init; } | ||
| public required int Divisibility { get; init; } | ||
| public required string CryptoImagePath { get; init; } | ||
| public required string BlockExplorerLink { get; init; } | ||
| public required string[] DefaultRateRules { get; init; } | ||
| public required string CurrencyDisplayName { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// Average block time in seconds. Used to compute the sync lag threshold. | ||
| /// Ethereum mainnet ≈ 12s, Polygon PoS ≈ 2s. | ||
| /// </summary> | ||
| public double BlockTimeSeconds { get; init; } = 12.0; | ||
|
|
||
| /// <summary> | ||
| /// EIP-155 chain ID. Used in EIP-681 payment links so wallets select the correct network. | ||
| /// Ethereum mainnet = 1, Polygon = 137. | ||
| /// </summary> | ||
| public int ChainId { get; init; } = 1; | ||
| } |
9 changes: 9 additions & 0 deletions
9
BTCPayServer.Plugins.USDt/Configuration/Ethereum/EthUSDtLikeServerSettings.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| using System; | ||
|
|
||
| namespace BTCPayServer.Plugins.USDt.Configuration.Ethereum; | ||
|
|
||
| public class EthUSDtLikeServerSettings | ||
| { | ||
| public Uri? JsonRpcUri { get; init; } | ||
| public string? SmartContractAddress { get; init; } | ||
| } |
4 changes: 3 additions & 1 deletion
4
BTCPayServer.Plugins.USDt/Configuration/USDtPluginConfiguration.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| using System.Collections.Generic; | ||
| using BTCPayServer.Payments; | ||
| using BTCPayServer.Plugins.USDt.Configuration.Tron; | ||
| using BTCPayServer.Plugins.USDt.Configuration.Ethereum; | ||
|
|
||
| namespace BTCPayServer.Plugins.USDt.Configuration; | ||
|
|
||
| public class USDtPluginConfiguration | ||
| { | ||
| public Dictionary<PaymentMethodId, TronUSDtLikeConfigurationItem> TronUSDtLikeConfigurationItems { get; init; } = []; | ||
| public Dictionary<PaymentMethodId, TronUSDtLikeConfigurationItem> TronUSDtLikeConfigurationItems { get; init; } = new(); | ||
| public Dictionary<PaymentMethodId, EthUSDtLikeConfigurationItem> EVMUSDtLikeConfigurationItems { get; init; } = new(); | ||
| } |
104 changes: 104 additions & 0 deletions
104
BTCPayServer.Plugins.USDt/Controllers/GreenfieldEthUSDtLikeStoreController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using BTCPayServer.Abstractions.Constants; | ||
| using BTCPayServer.Client; | ||
| using BTCPayServer.Data; | ||
| using BTCPayServer.Payments; | ||
| using BTCPayServer.Plugins.USDt.Configuration; | ||
| using BTCPayServer.Plugins.USDt.Controllers.Models; | ||
| using BTCPayServer.Plugins.USDt.Services; | ||
| using BTCPayServer.Plugins.USDt.Services.Payments; | ||
| using BTCPayServer.Services.Invoices; | ||
| using Microsoft.AspNetCore.Authorization; | ||
| using Microsoft.AspNetCore.Cors; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace BTCPayServer.Plugins.USDt.Controllers; | ||
|
|
||
| [ApiController] | ||
| [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)] | ||
| [EnableCors(CorsPolicies.All)] | ||
| public class GreenfieldEthUSDtLikeStoreController( | ||
| EthUSDtRPCProvider ethUSDtRpcProvider, | ||
| PaymentMethodHandlerDictionary handlers, | ||
| InvoiceRepository invoiceRepository, | ||
| USDtPluginConfiguration pluginConfiguration) : ControllerBase | ||
| { | ||
| private StoreData StoreData => HttpContext.GetStoreDataOrNull()!; | ||
|
|
||
| [Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)] | ||
| [HttpGet("~/api/v1/stores/{storeId}/evmUSDtlike/{paymentMethodId}")] | ||
| public async Task<IActionResult> GetStoreInformation(PaymentMethodId paymentMethodId) | ||
| { | ||
| if (!pluginConfiguration.EVMUSDtLikeConfigurationItems.ContainsKey(paymentMethodId)) | ||
| return NotFound(); | ||
|
|
||
| var excludeFilters = StoreData.GetStoreBlob().GetExcludedPaymentMethods(); | ||
| var matchedPaymentMethodConfig = | ||
| StoreData.GetPaymentMethodConfig<EthUSDtPaymentMethodConfig>(paymentMethodId, handlers); | ||
|
|
||
| if (matchedPaymentMethodConfig == null) | ||
| return NotFound(); | ||
|
|
||
| var balances = | ||
| await ethUSDtRpcProvider.GetBalances(paymentMethodId, [.. matchedPaymentMethodConfig.Addresses]); | ||
| var reservedAddresses = | ||
| await EthUSDtPaymentMethodConfig.GetReservedAddresses(paymentMethodId, invoiceRepository); | ||
|
|
||
| return Ok(new EthUSDtPaymentMethodInformation | ||
| { | ||
| StoreId = StoreData.Id, | ||
| PaymentMethodId = paymentMethodId.ToString(), | ||
| Enabled = !excludeFilters.Match(paymentMethodId), | ||
| Addresses = matchedPaymentMethodConfig.Addresses.Select(s => | ||
| new EthUSDtPaymentMethodInformation.EthUSDtPaymentMethodAddressInformation | ||
| { | ||
| Available = !reservedAddresses.Contains(s), | ||
| Balance = balances.Single(x => x.Item1 == s).Item2, | ||
| Value = s | ||
| }).ToArray() | ||
| }); | ||
| } | ||
|
|
||
| [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)] | ||
| [HttpPost("~/api/v1/stores/{storeId}/evmUSDtlike/{paymentMethodId}/addresses")] | ||
| public IActionResult AddAddress(PaymentMethodId paymentMethodId, [FromBody] EthUSDtAddAddressRequest request) | ||
| { | ||
| if (!pluginConfiguration.EVMUSDtLikeConfigurationItems.ContainsKey(paymentMethodId)) | ||
| return NotFound(); | ||
|
|
||
| if (!EthAddressHelper.IsValid(request.Address)) | ||
| return BadRequest(new { message = "Invalid EVM address." }); | ||
|
|
||
| var address = request.Address.ToLowerInvariant(); | ||
| var store = StoreData; | ||
| var currentConfig = store.GetPaymentMethodConfig<EthUSDtPaymentMethodConfig>(paymentMethodId, handlers) | ||
| ?? new EthUSDtPaymentMethodConfig(); | ||
|
|
||
| if (currentConfig.Addresses.Contains(address)) | ||
| return BadRequest(new { message = "Address already exists." }); | ||
|
|
||
| currentConfig.Addresses = [.. currentConfig.Addresses, address]; | ||
| store.SetPaymentMethodConfig(handlers[paymentMethodId], currentConfig); | ||
| return Ok(); | ||
| } | ||
|
|
||
| [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)] | ||
| [HttpDelete("~/api/v1/stores/{storeId}/evmUSDtlike/{paymentMethodId}/addresses/{address}")] | ||
| public IActionResult DeleteAddress(PaymentMethodId paymentMethodId, string address) | ||
| { | ||
| if (!pluginConfiguration.EVMUSDtLikeConfigurationItems.ContainsKey(paymentMethodId)) | ||
| return NotFound(); | ||
|
|
||
| var store = StoreData; | ||
| var currentConfig = store.GetPaymentMethodConfig<EthUSDtPaymentMethodConfig>(paymentMethodId, handlers); | ||
| var normalized = address.ToLowerInvariant(); | ||
|
|
||
| if (currentConfig == null || !currentConfig.Addresses.Contains(normalized)) | ||
| return NotFound(); | ||
|
|
||
| currentConfig.Addresses = currentConfig.Addresses.Where(a => a != normalized).ToArray(); | ||
| store.SetPaymentMethodConfig(handlers[paymentMethodId], currentConfig); | ||
| return Ok(); | ||
|
learntheropes marked this conversation as resolved.
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
BTCPayServer.Plugins.USDt/Controllers/Models/EthUSDtPaymentMethodInformation.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| namespace BTCPayServer.Plugins.USDt.Controllers.Models; | ||
|
|
||
| public class EthUSDtPaymentMethodInformation | ||
| { | ||
| public required string StoreId { get; init; } | ||
| public required string PaymentMethodId { get; init; } | ||
| public required bool Enabled { get; init; } | ||
|
|
||
| public EthUSDtPaymentMethodAddressInformation[] Addresses { get; init; } = []; | ||
|
|
||
| public class EthUSDtPaymentMethodAddressInformation | ||
| { | ||
| public required string Value { get; init; } | ||
| public bool Available { get; init; } | ||
| public required decimal? Balance { get; init; } | ||
| } | ||
| } | ||
|
|
||
| public class EthUSDtAddAddressRequest | ||
| { | ||
| public required string Address { get; init; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.