Skip to content

Conversation

@tanapl
Copy link
Collaborator

@tanapl tanapl commented Dec 20, 2025

  • 内部関数 _calculateDistribution と _executeDistribution を実装し、基金・バー
    ン・受取人への分配計算と送金処理を共通化。
  • 事前承認を前提に分配送金を実行する transferWithDistribution を追加し、適切な分
    配を保証。
  • transferWithDistribution の包括的テストを追加(正常系・異常系・エッジケースを
    網羅)。
  • 分配合計が送金総額と一致することを検証・保証。
  • すべてのテストがパス。

関連 Issue

Closes #48
Related: #15

変更内容

  • packages/contract/contracts/Router.sol
    • 内部関数 _calculateDistribution(uint256) を追加(分配額の計算)。
    • 内部関数 _executeDistribution(address,address,uint256,uint256,uint256) を
      追加(3 宛先への transferFrom 実行)。
    • transferWithPermit を内部関数でリファクタし、ロジック共通化。
    • transferWithDistribution(address from, address recipient, uint256 amount)
      を実装(whenNotPaused/nonReentrant、入力検証、イベント発行)。
  • packages/contract/test/Router.transferWithDistribution.ts
    • 正常系(標準比率、0/100%、50/50%)、分配検証(合計=総額、端数処理)、異常
      系(ゼロ額、ゼロアドレス、許可不足、Paused)、エッジケース(from==recipient、大
      きな額、イベント発行)を追加。

動作確認

  • ローカル環境で動作確認済み
  • テストが通ることを確認済み(Hardhat: Solidity + node:test すべてパス)
  • ビルドが成功することを確認済み(pnpm -C packages/contract build)

スクリーンショット(該当する場合)

該当なし

その他

  • 互換性: 既存イベント・ストレージに破壊的変更なし。新規関数追加のみ。
  • AA ユースケース: 1 UserOperation で approve + transferWithDistribution をバッ
    チ実行可能。
  • 参考実装(フロント/SDK):
    • EOA: 可能なら transferWithPermit を優先。事前承認フローでも利用可。
    • AA: approve(router, amount) → transferWithDistribution(from, recipient,
      amount) をバッチ実行。
  • 今後: Ignition の Router モジュール引数(initialAdmin/forToken)の補完は別PRで
    対応可能です。

- Implemented _calculateDistribution and _executeDistribution internal functions for calculating and executing fund, burn, and recipient amounts.
- Introduced transferWithDistribution function to facilitate token transfers with pre-approved amounts, ensuring proper distribution.
- Added comprehensive tests for transferWithDistribution, covering various scenarios including edge cases and error handling.
- Ensured that the sum of distributed amounts equals the total transferred amount.

All tests passing.
@tanapl tanapl marked this pull request as ready for review December 20, 2025 07:38
@tanapl tanapl requested review from aowheel and yu23ki14 December 20, 2025 07:38
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.

Routerコントラクト: 事前承認ベースの分配送金実装(AA対応)

2 participants