Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@RubenSousaDinis
Copy link
Member

@RubenSousaDinis RubenSousaDinis commented Oct 16, 2025

PR: Migrate TalentPlus to USDC-Only Payments

Overview

This PR migrates the TalentPlus subscription system from ETH payments to USDC (ERC20) payments only. The changes ensure a more stable payment mechanism using a stablecoin while maintaining all existing functionality including TALENT-based discounts and subscription management features.

Changes Summary

🔄 Contract Changes

1. TalentPlus.sol

  • Removed: ETH payment support (payable modifier and msg.value handling)
  • Added: USDC payment token support via constructor parameter
  • Updated: subscribe() function now accepts tokenAmount parameter instead of ETH
  • Added: SafeERC20 integration for secure token transfers
  • Updated: Event signature changed from finalPrice to pricePaid

Key Changes:

  • Constructor now requires paymentToken address (USDC: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 on Base)
  • Users must approve the contract to spend USDC before subscribing
  • Automatic refund of excess tokens (similar to ETH refunds)

2. TalentPlusSubscription.sol

  • Renamed: priceInEthprice throughout the contract
  • Updated: All price references now indicate USDC (6 decimals)
  • Updated: Function parameters and return values use price instead of priceInEth
  • Updated: Events emit price instead of priceInEth
  • Updated: Documentation comments reference USDC instead of ETH

Key Changes:

  • addSubscriptionModel(): priceInEth parameter → price parameter
  • updateSubscriptionModel(): priceInEth parameter → price parameter
  • getSubscriptionModel(): Returns price instead of priceInEth
  • calculateDiscountedPrice(): Uses model.price instead of model.priceInEth

🧪 Test Updates

1. TalentPlusSubscription.ts

  • ✅ Updated test assertions: model.priceInEthmodel.price (2 occurrences)

2. TalentPlus.ts

  • ✅ Added payment token (USDC mock) deployment in beforeEach
  • ✅ Updated constructor calls to include paymentToken parameter
  • ✅ Replaced all ETH payments ({ value: ... }) with token payments
  • ✅ Updated all subscribe() calls to use tokenAmount parameter
  • ✅ Added token minting and approval setup for test users
  • ✅ Updated event assertions: finalPricepricePaid
  • ✅ Updated error message expectations: "Insufficient ETH payment" → "Insufficient token payment"

📜 Script Updates

1. deployTalentPlus.ts

  • ✅ Added USDC address constant: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
  • ✅ Updated deployTalentPlus() call to include USDC address
  • ✅ Updated verification command to include payment token parameter

2. shared/index.ts

  • ✅ Updated deployTalentPlus() function signature to accept paymentToken parameter

Breaking Changes

⚠️ Contract Interface Changes

  1. TalentPlus Constructor

    // Before
    constructor(address _talentPlusSubscriptionAddress, address _feeReceiver)
    
    // After
    constructor(address _talentPlusSubscriptionAddress, address _feeReceiver, address _paymentToken)
  2. TalentPlus.subscribe()

    // Before
    function subscribe(address wallet, string memory subscriptionSlug) public payable
    
    // After
    function subscribe(address wallet, string memory subscriptionSlug, uint256 tokenAmount) public
  3. TalentPlusSubscription Functions

    // Before
    function addSubscriptionModel(..., uint256 priceInEth, ...)
    function getSubscriptionModel(...) returns (..., uint256 priceInEth, ...)
    
    // After
    function addSubscriptionModel(..., uint256 price, ...)
    function getSubscriptionModel(...) returns (..., uint256 price, ...)

⚠️ Event Changes

TalentPlus.SubscriptionCreated

// Before
event SubscriptionCreated(..., uint256 finalPrice, bool discountApplied);

// After
event SubscriptionCreated(..., uint256 pricePaid, bool discountApplied);

Migration Guide

For Users

  1. Approve USDC Spending

    // Users must approve TalentPlus contract to spend USDC
    usdc.approve(talentPlusAddress, amount);
  2. Subscribe with USDC

    // Before (ETH)
    talentPlus.subscribe(wallet, "premium", { value: parseEther("100") });
    
    // After (USDC)
    talentPlus.subscribe(wallet, "premium", parseUnits("100", 6)); // 100 USDC

Testing

All tests have been updated and are passing:

✅ 60 tests passing
  - TalentPlus: 20 tests
  - TalentPlusSubscription: 40 tests

Run tests with:

npm test -- --grep "TalentPlus"

Security Considerations

  • SafeERC20: Uses OpenZeppelin's SafeERC20 for secure token transfers
  • Reentrancy Protection: Maintains nonReentrant modifier
  • Input Validation: All parameters validated (zero addresses, empty strings, etc.)
  • Automatic Refunds: Excess tokens automatically refunded to users
  • No Exchange Rate Risk: Direct USDC pricing eliminates ETH/USD volatility

Benefits

  1. Price Stability: USDC provides stable pricing without ETH volatility
  2. Better UX: Users can pay with stablecoins instead of volatile ETH
  3. Simpler Pricing: Direct USDC prices eliminate exchange rate complexity
  4. Maintained Features: All existing features (discounts, extensions, etc.) work identically

Deployment Checklist

  • Deploy updated TalentPlusSubscription contract
  • Deploy updated TalentPlus contract with USDC address
  • Add TalentPlus as trusted signer in TalentPlusSubscription
  • Set up subscription models with USDC prices
  • Update frontend to use USDC payments
  • Test subscription flow end-to-end
  • Update documentation

Files Changed

Contracts

  • contracts/talent_plus/TalentPlus.sol
  • contracts/talent_plus/TalentPlusSubscription.sol

Tests

  • test/contracts/talent_plus/TalentPlus.ts
  • test/contracts/talent_plus/TalentPlusSubscription.ts

Scripts

  • scripts/talent_plus/deployTalentPlus.ts
  • scripts/shared/index.ts

Related Issues

  • Migrates payment system from ETH to USDC
  • Improves price stability for subscription payments
  • Maintains backward compatibility for subscription logic

Notes

  • USDC address on Base: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
  • Prices are in USDC units (6 decimals)
  • All discount logic remains unchanged
  • Subscription extension/upgrade logic unchanged

@RubenSousaDinis RubenSousaDinis force-pushed the talent-plus branch 2 times, most recently from b8b8e59 to a015945 Compare October 16, 2025 13:43
@RubenSousaDinis RubenSousaDinis force-pushed the talent-plus branch 4 times, most recently from b60be0a to b3f1007 Compare October 21, 2025 15:38
- Moved calculateDiscountedPrice, getUserTalentHoldings, and vault management methods from TalentPlusSubscription to TalentPlus
- Updated TalentPlus constructor to accept TALENT token address and initial vault addresses
- Fixed refund functionality in subscribe method (contract now receives tokens before distributing)
- Updated price validation to allow price 0 when discount is 100%
- Removed TALENT_TOKEN and vaultAddresses from TalentPlusSubscription
- Updated TalentPlusSubscription constructor to only require owner address
- Added comprehensive tests for new functionality
- Updated deployment scripts to use new constructor signatures

This refactoring allows TalentPlusSubscription to be replaced while keeping existing subscriptions, as payment logic is now decoupled in TalentPlus.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants