Tanya S b4508dd0d4
Use proxy for token contract (#30)
* Add proxy contract for TST

* Fix token proxy update function to use provided new TST address

* Transfer token proxy contract ownership to deployer

* Add Token Proxy Contract Owner as init input

* Add UUPSUPgradeable to TST

* Formatting

* fix import format

* Add README to explain TST usage

* Linting fix

* Check TST test transfer return val

* Add descriptions in README for TST usage

* Fix linting

* Use TST token deployer in test conrtact, update test README

* USe assertTrue in TST test
2025-08-26 17:34:32 +02:00
..
2025-08-26 17:34:32 +02:00
2024-11-01 16:22:15 -04:00

TestStableToken

The waku-rlnv2-contract spec defines that DAI is to be used to pay for membership registration, with the end-goal being to deploy the contract on mainnet using an existing stable DAI token.

Before this, we need to perform extensive testing on testnet and local environments (such as waku-simulator). During initial testing, we discovered the need to manage token minting in testnet environments to limit membership registrations and enable controlled testing of the contract.

TestStableToken is our custom token implementation designed specifically for testing environments, providing controlled token distribution while mimicking DAI's behaviour.

Requirements

  • Controlled minting: Manage token minting through an allowlist of approved accounts, controlled by the token contract owner
  • ETH burning mechanism: Burn ETH when minting tokens to create economic cost (WIP)
  • Proxy architecture: Use a proxy contract to minimize updates required when the token address changes across other components (e.g., nwaku-compose repo or dogfooding instructions)

Usage

Deploy new TestStableToken with proxy contract

This script deploys both the proxy and the TestStableToken implementation, initializing the proxy to point to the new implementation.

ETH_FROM=$DEPLOYER_ACCOUNT_ADDRESS forge script script/DeployTokenWithProxy.s.sol:DeployTokenWithProxy --rpc-url $RPC_URL --broadcast --private_key $DEPLOYER_ACCOUNT_PRIVATE_KEY

or

MNEMONIC=$TWELVE_WORD_MNEMONIC forge script script/DeployTokenWithProxy.s.sol:DeployTokenWithProxy --rpc-url $RPC_URL --broadcast

Deploy only TestStableToken contract implementation

This script deploys only the TestStableToken implementation, which can then be used to update the proxy contract to point to this new implementation.

forge script test/TestStableToken.sol:TestStableTokenFactory --tc TestStableTokenFactory --rpc-url $RPC_URL --private-key $DEPLOYER_ACCOUNT_PRIVATE_KEY --broadcast

Update the proxy contract to point to the new implementation

# Upgrade the proxy to a new implementation
cast send $TOKEN_PROXY_ADDRESS "upgradeTo(address)" $NEW_IMPLEMENTATION_ADDRESS --rpc-url $RPC_URL --private-key $DEPLOYER_ACCOUNT_PRIVATE_KEY

Add account to the allowlist to enable minting

cast send $TOKEN_PROXY_ADDRESS "addMinter(address)" $ACCOUNT_ADDRESS --rpc-url $RPC_URL --private-key $DEPLOYER_ACCOUNT_PRIVATE_KEY

Mint tokens to the account

cast send $TOKEN_PROXY_ADDRESS "mint(address,uint256)" <TO_ADDRESS> <AMOUNT> --rpc-url $RPC_URL --private-key $MINTER_ACCOUNT_PRIVATE_KEY

Approve the token for the waku-rlnv2-contract to use

cast send $TOKEN_PROXY_ADDRESS "approve(address,uint256)" $TOKEN_SPENDER_ADDRESS <AMOUNT> --rpc-url $RPC_URL --private-key $PRIVATE_KEY

Remove the account from the allowlist to prevent further minting

cast send $TOKEN_PROXY_ADDRESS "removeMinter(address)" $ACCOUNT_ADDRESS --rpc-url $RPC_URL --private-key $DEPLOYER_ACCOUNT_PRIVATE_KEY

Query token information

# Check if an account is a minter
cast call $TOKEN_PROXY_ADDRESS "isMinter(address)" $ACCOUNT_ADDRESS --rpc-url $RPC_URL

# Check token balance
cast call $TOKEN_PROXY_ADDRESS "balanceOf(address)" $ACCOUNT_ADDRESS --rpc-url $RPC_URL

# Check token allowance
cast call $TOKEN_PROXY_ADDRESS "allowance(address,address)" $TOKEN_OWNER_ADDRESS $TOKEN_SPENDER_ADDRESS --rpc-url $RPC_URL