# Featured Appの報酬を帰属させる

> 運用のpartyやwalletの利用者がToken Standardのchoiceを呼ぶ時に、Featured Appの印を提供者へ帰属させる代理のコントラクトを、表と2つの図で追います。

- URL: https://cardene.dev/diagrams/canton-featured-proxies
- 公開日: 2026-11-22
- 更新日: 2026-11-22
- トピック: Blockchain
- タグ: Canton
- 親の図解: [Featured Appの報酬](https://cardene.dev/diagrams/canton-featured-rewards.md): アプリの提供者がCanton Coinの報酬を得る条件と、報酬の計り方と制限を、章の中の図解で追います。

前の頁「活動を記録して受益者へ分ける」は、Featured Appが印を作るAPIと、引換券を受益者へ割り当てるAPIを見ました。
この頁は、アプリの運用に別のpartyを使う時と、walletの利用者がToken Standardのchoiceを呼ぶ時に、印を提供者へ帰属させる代理のコントラクトを追います。

`AppRewardBeneficiary`と`FeaturedAppRight_CreateActivityMarkerResult`は、前の頁で見ました。

https://cardene.dev/diagrams/canton-featured-app-rewards

`FeaturedAppRight`と`FeaturedAppActivityMarker`のテンプレートは、頁「活動の印で報酬を得る」で見ました。

https://cardene.dev/diagrams/canton-featured-app

Token Standardは、頁「Canton Coinの役と料金を知る」で見ました。

https://cardene.dev/diagrams/canton-coin-tokenomics

## 3つの代理は2つのパッケージが持つ

`splice-util-featured-app-proxies`は、Featured AppをToken Standardとつなぐのを簡単にする任意のパッケージです。
validatorのノードには、既定ではアップロードされません。
モジュールは`Splice.Util.FeaturedApp.DelegateProxy`と`Splice.Util.FeaturedApp.WalletUserProxy`の2つです。
代理の`DelegateProxy`と代理の`WalletUserProxy`は、Token Standardのchoiceを代わりに呼ぶテンプレートです。

`splice-util-batched-markers`のパッケージは、モジュール`Splice.Util.FeaturedApp.BatchedMarkersProxy`を持ちます。

| 代理 | パッケージ | 使う場面 |
|---|---|---|
| `DelegateProxy` | `splice-util-featured-app-proxies` | 自分の運用に複数のpartyを使うアプリを作る時 |
| `WalletUserProxy` | `splice-util-featured-app-proxies` | walletのアプリを作り、利用者に印を作らせたい時 |
| `BatchedMarkersProxy` | `splice-util-batched-markers` | 1つのViewを持つトランザクションで、印をバッチで作る時 |

`DelegateProxy`と`WalletUserProxy`は、そのまま使うか、別のパッケージ名と別のモジュール名でコードを写して使います。

## `DelegateProxy`は運用のpartyの活動を提供者へ帰属させる

`DelegateProxy`は、アプリの運用に別のpartyを使う時に、印が作られるようToken Standardのchoiceを代わりに呼ぶ代理です。
`delegate`が、Token Standardのワークフローを使いながら、印を一緒に作ります。
印の作成は、`delegate`が全て決めます。

例えば、アプリの運用のために1つ以上のpartyを使う時に役に立ちます。
この代理を使うと、運用のためのpartyが自分の活動を、アプリの提供者のpartyが表すFeatured Appへ正しく帰属させられます。

signatoryは`provider`で、欄は次の表の2つです。

| 欄 | 型 | 中身 |
|---|---|---|
| `provider` | `Party` | 権利を使うアプリの提供者 |
| `delegate` | `Party` | Token Standardのワークフローとやり取りする`delegate` |

choiceは、次の表の7つです。
`Archive`以外の6つのchoiceは、controllerが`delegate`です。
各choiceは、対象のコントラクトのIDの`cid`と、`proxyArg`を受け取ります。

| choice | controller | `cid`の型 | 返す物 |
|---|---|---|---|
| `DelegateProxy_AllocationFactory_Allocate` | `delegate` | `AllocationFactory` | `ProxyResult AllocationInstructionResult` |
| `DelegateProxy_Allocation_Withdraw` | `delegate` | `Allocation` | `ProxyResult Allocation_WithdrawResult` |
| `DelegateProxy_TransferFactory_Transfer` | `delegate` | `TransferFactory` | `ProxyResult TransferInstructionResult` |
| `DelegateProxy_TransferInstruction_Accept` | `delegate` | `TransferInstruction` | `ProxyResult TransferInstructionResult` |
| `DelegateProxy_TransferInstruction_Reject` | `delegate` | `TransferInstruction` | `ProxyResult TransferInstructionResult` |
| `DelegateProxy_TransferInstruction_Withdraw` | `delegate` | `TransferInstruction` | `ProxyResult TransferInstructionResult` |
| `Archive` | `provider` | なし | `()` |

`ProxyArg`は、代理のchoiceの共通の引数で、次の表の3つの欄を持ちます。
`proxyArg`の型は、`ProxyArg`に呼ぶchoiceの名前を付けた形です。

| 欄 | 型 | 中身 |
|---|---|---|
| `choiceArg` | `arg` | `delegate`が行使するchoiceの引数 |
| `featuredAppRightCid` | `ContractId FeaturedAppRight` | 提供者の`FeaturedAppRight`のコントラクト |
| `beneficiaries` | `[AppRewardBeneficiary]` | 印の受益者 |

`ProxyResult`は、代理のchoiceの共通の結果で、次の表の2つの欄を持ちます。

| 欄 | 型 |
|---|---|
| `markerResult` | `FeaturedAppRight_CreateActivityMarkerResult` |
| `choiceResult` | `r` |

## `WalletUserProxy`は利用者の活動をwalletの提供者へ帰属させる

`WalletUserProxy`は、walletの利用者がToken Standardのワークフローを使う時に、walletのアプリの提供者のために印が作られるよう、Token Standardのchoiceを代わりに呼ぶ代理です。
利用者の活動を、walletのアプリの提供者へ帰属させます。

想定する使い方は、次の2段です。

1. walletのアプリの提供者が、`provider`を自分のpartyにした`WalletUserProxy`のコントラクトを作ります。
2. walletのフロントエンドを、利用者が元のToken Standardのchoiceの代わりに、代理のchoiceを呼ぶように整えます。

重みは、提供者が決められるように、代理のコントラクトに書きます。
choiceに書くと、原理上は、利用者が重みを変えて、意図より高い報酬を自分に与えられてしまいます。
バッチ送金は、`FeaturedAppRight`を持たなくても使えます。

図Aは、この2段と、重みの置き場を追います。
この図では、利用者の呼び出しで印が作られる所と、choiceの結果の返り先は描きません。

```dragon
sequence walletの代理の使い方

box P as 提供者 [note: walletのアプリの提供者, color: rose, icon: user]
box X as 代理 [note: 利用者の活動を提供者へ帰属させる, color: slate, icon: doc]
box U as 利用者 [note: walletの利用者, color: rose, icon: user]

step 代理を作る
  say walletのアプリの提供者が、提供者を自分のpartyにした代理のコントラクトを作ります。
  P -> X: 代理を作る
  source CantonのSplice.Util.FeaturedApp.WalletUserProxy [url: https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-util-featured-app-proxies/splice-util-featuredapp-walletuserproxy]

step 元の代わりに呼ぶ
  say walletのアプリの提供者が、walletのフロントエンドを、利用者が元のToken Standardのchoiceの代わりに、代理のchoiceを呼ぶように整えます。
  U -> X: 代理のchoiceを呼ぶ
  source CantonのSplice.Util.FeaturedApp.WalletUserProxy [url: https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-util-featured-app-proxies/splice-util-featuredapp-walletuserproxy]

step 重みは代理が持つ
  say 重みは代理のコントラクトに書くので、提供者が決められます。choiceに書くと、原理上は、利用者が重みを変えて、意図より高い報酬を自分に与えられてしまいます。
  act X: 重みを持つ
  source CantonのSplice.Util.FeaturedApp.WalletUserProxy [url: https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-util-featured-app-proxies/splice-util-featuredapp-walletuserproxy]
```

signatoryは`provider`で、欄は次の表の5つです。
`Optional`は、値を持つか、値が無い`None`かのどちらかを取る型です。

| 欄 | 型 | 中身 |
|---|---|---|
| `provider` | `Party` | `FeaturedAppRight`を使うアプリの提供者 |
| `providerWeight` | `Decimal` | 提供者の報酬の重み |
| `userWeight` | `Decimal` | 利用者の報酬の重み。利用者に報酬を与えない時は0.0 |
| `extraBeneficiaries` | `[AppRewardBeneficiary]` | 足す受益者 |
| `optAllowList` | `Optional [Party]` | 代理を使えるpartyの許可リスト |

choiceは、次の表の9つです。
`WalletUserProxy_BatchTransfer`と`WalletUserProxy_PublicFetch`と`Archive`を除く6つのchoiceは、controllerが`proxyArg`の欄`user`で、`cid`と`proxyArg`を受け取ります。

| choice | controller | 受け取る欄 | 返す物 |
|---|---|---|---|
| `WalletUserProxy_AllocationFactory_Allocate` | `proxyArg`の`user` | `cid`の型は`AllocationFactory` | `ProxyResult AllocationInstructionResult` |
| `WalletUserProxy_Allocation_Withdraw` | `proxyArg`の`user` | `cid`の型は`Allocation` | `ProxyResult Allocation_WithdrawResult` |
| `WalletUserProxy_TransferFactory_Transfer` | `proxyArg`の`user` | `cid`の型は`TransferFactory` | `ProxyResult TransferInstructionResult` |
| `WalletUserProxy_TransferInstruction_Accept` | `proxyArg`の`user` | `cid`の型は`TransferInstruction` | `ProxyResult TransferInstructionResult` |
| `WalletUserProxy_TransferInstruction_Reject` | `proxyArg`の`user` | `cid`の型は`TransferInstruction` | `ProxyResult TransferInstructionResult` |
| `WalletUserProxy_TransferInstruction_Withdraw` | `proxyArg`の`user` | `cid`の型は`TransferInstruction` | `ProxyResult TransferInstructionResult` |
| `WalletUserProxy_BatchTransfer` | `transferCalls`の最初の呼び出しの送り手 | `transferCalls`と`optFeaturedAppRightCid` | `WalletUserProxy_BatchTransferResult` |
| `WalletUserProxy_PublicFetch` | `actor` | `actor` | `WalletUserProxy` |
| `Archive` | `provider` | なし | `()` |

`ProxyArg`は、代理のchoiceの共通の引数で、次の表の3つの欄を持ちます。
`ProxyResult`は、`DelegateProxy`と同じく、`markerResult`と`choiceResult`の2つの欄を持ちます。

| 欄 | 型 | 中身 |
|---|---|---|
| `user` | `Party` | walletを使ってchoiceを行使する、walletの利用者 |
| `choiceArg` | `arg` | 利用者が行使するchoiceの引数 |
| `featuredAppRightCid` | `ContractId FeaturedAppRight` | 提供者の`FeaturedAppRight`のコントラクト |

## バッチ送金は呼び出しの一覧と保有の受け渡しで動く

`WalletUserProxy_BatchTransfer`は、2つの欄を受け取ります。

| 欄 | 型 | 中身 |
|---|---|---|
| `transferCalls` | `[TransferFactoryCall]` | それぞれの`TransferFactory`で実行する送金 |
| `optFeaturedAppRightCid` | `Optional (ContractId FeaturedAppRight)` | 全ての送金に使う、提供者の`FeaturedAppRight` |

`transferCalls`の各送金は、それぞれの`TransferFactory`で実行されます。
入力の保有は、全ての`InstrumentId`にわたって受け渡されます。
送り手のお釣りは、常に、同じ`InstrumentId`の後の送金の入力に足されます。

呼び出しを全て指定した形で受け取るのは、最大限の柔軟性のためです。
受け手ごとに別の`TransferFactory`を使い、例えば事前承認を実装するトークンの管理者がいるからです。
`optFeaturedAppRightCid`をOptionalにしたのは、`FeaturedAppRight`が無くてもバッチのchoiceを使えるようにするためです。

バッチ送金の型は、次の表の3つです。

| 型 | 欄 | 中身 |
|---|---|---|
| `TransferFactoryCall` | `factoryCid`と`choiceArg` | バッチ送金に使う、Token Standardの`TransferFactory`の呼び出し |
| `WalletUserProxy_BatchTransferResult` | `transferResults` | `[TransferInstructionResult]` |
| `WalletUserProxy_BatchTransferResult` | `senderChangeMap` | `InstrumentHoldingMap` |

`InstrumentHoldingMap`は、`InstrumentId`から、保有の`Holding`のコントラクトのIDのリストへの`Map`です。

## `BatchedMarkersProxy`は印をバッチで作る

`BatchedMarkersProxy`は、`FeaturedAppActivityMarker`の印を、1つのViewを持つトランザクションでバッチで作れるようにする代理で、このほうが処理の効率がよいです。
使うには、まず寿命の長い`BatchedMarkersProxy`のコントラクトを1つ作り、次に`BatchedMarkersProxy_CreateMarkers`で実際の印を作ります。
これが動くのは、全ての受益者と提供者が、そのDARをvettingしている時です。

vettingは、頁「packageをvettingして使う」で見ました。

https://cardene.dev/diagrams/canton-dar-vetting

signatoryは`provider`で、欄は`provider`と`dso`の2つで、型は`Party`です。
choiceは、controllerがどれも`provider`で、次の表の3つです。

| choice | 受け取る欄 | 返す物 |
|---|---|---|
| `BatchedMarkersProxy_CreateMarkers` | `featuredAppRightCid`と、`[RewardBatch]`の`batches` | `BatchedMarkersProxy_CreateMarkersResult` |
| `BatchedMarkersProxy_CreateMarkersV2` | `featuredAppRightCid`と、`[RewardBatchV2]`の`batches` | `BatchedMarkersProxy_CreateMarkersV2Result` |
| `Archive` | なし | `()` |

次の表は、結果と、バッチの型の欄を並べます。

| 型 | 欄 | 欄の型 | 中身 |
|---|---|---|---|
| `BatchedMarkersProxy_CreateMarkersResult` | `results` | `[[FeaturedAppRight_CreateActivityMarkerResult]]` | |
| `BatchedMarkersProxy_CreateMarkersV2Result` | `results` | `[FeaturedAppRight_CreateActivityMarkerResult]` | |
| `RewardBatch` | `beneficiaries` | `[AppRewardBeneficiary]` | |
| `RewardBatch` | `numMarkers` | `Int` | |
| `RewardBatchV2` | `beneficiaries` | `[AppRewardBeneficiary]` | |
| `RewardBatchV2` | `markerWeight` | `Decimal` | 作る印の重みの合計 |

## 3つの代理は使う場面で選ぶ

図Bは、3つの代理を、パッケージのモジュールごとの枝にして追います。
この図では、枝は代理ごとに足し、使う順は示しません。

```dragon
mind 印を作る代理の使い分け

step 3つの代理
  say 印を作る3つの代理を、モジュールごとの枝にして追います。
  idea root as "印を作る代理" [color: slate]
  source CantonのSplice.Util.FeaturedApp.DelegateProxy [url: https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-util-featured-app-proxies/splice-util-featuredapp-delegateproxy]

step 運用のparty
  say 1つ目の枝は、アプリの運用に別のpartyを使う時の代理で、印の作成はdelegateが全て決めます。
  idea c1 as "DelegateProxy" of root [color: blue]
  idea c1a as "運用に別のparty" of c1 [color: blue]
  idea c1b as "印は全てdelegateが決める" of c1 [color: blue]
  idea c1c as "delegateのchoiceは6つ" of c1 [color: blue]
  source CantonのSplice.Util.FeaturedApp.DelegateProxy [url: https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-util-featured-app-proxies/splice-util-featuredapp-delegateproxy]

step walletの利用者
  say 2つ目の枝は、walletの利用者の活動を提供者へ帰属させる代理で、重みは代理のコントラクトに書き、バッチ送金も使えます。
  idea c2 as "WalletUserProxy" of root [color: blue]
  idea c2a as "利用者の活動を帰属" of c2 [color: blue]
  idea c2b as "重みは代理が持つ" of c2 [color: blue]
  idea c2c as "バッチ送金" of c2 [color: blue]
  source CantonのSplice.Util.FeaturedApp.WalletUserProxy [url: https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-util-featured-app-proxies/splice-util-featuredapp-walletuserproxy]

step 印のバッチ
  say 3つ目の枝は、印をバッチで作る代理で、寿命の長い代理を1つ作り、受益者と提供者がDARをvettingしている時に動きます。
  idea c3 as "BatchedMarkersProxy" of root [color: blue]
  idea c3a as "印をバッチで作る" of c3 [color: blue]
  idea c3b as "長く使う代理を1つ" of c3 [color: blue]
  idea c3c as "受益者と提供者のDAR" of c3 [color: blue]
  source CantonのSplice.Util.FeaturedApp.BatchedMarkersProxy [url: https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-util-batched-markers/splice-util-featuredapp-batchedmarkersproxy]
```

## 各モジュールの関数

3つのモジュールの`require`は、求めた条件が真かを確認し、偽なら、要件が満たされなかったというメッセージでトランザクションを中止します。
`DelegateProxy`のモジュールは、`require`のほかに、代理を通したchoiceを実行する共通のコード`exerciseProxyChoice`を持ちます。
`BatchedMarkersProxy`のモジュールの関数は、`require`だけです。

`WalletUserProxy`のモジュールの関数は、次の表の9つです。
`require`は上の通りなので、表には並べません。

| 関数 | 受け取る物 | 返す物 | 働き |
|---|---|---|---|
| `getFirstSender` | `[TransferFactoryCall]` | `Party` | 最初の呼び出しの送金の送り手を決める |
| `runBatch` | `WalletUserProxy`、`WalletUserProxy_BatchTransfer` | `Update WalletUserProxy_BatchTransferResult` | バッチの呼び出しを検証して実行する |
| `executeTransferCalls` | `WalletUserProxy`、`Party`、`Optional (ContractId FeaturedAppRight)`、`[TransferFactoryCall]`、`InstrumentHoldingMap`、`[TransferInstructionResult]` | `Update WalletUserProxy_BatchTransferResult` | バッチの中の個々の送金の呼び出しを、入力の保有を受け渡しながら実行する |
| `exerciseProxyChoice` | `WalletUserProxy`、`ContractId t`、`ProxyArg ch`、`ContractId t -> Update Party` | `Update (ProxyResult r)` | 代理を通したchoiceを実行する共通のコード |
| `validateAppRight` | `WalletUserProxy`、`ContractId FeaturedAppRight` | `Update ()` | |
| `checkAllowList` | `Optional [Party]`、`Party` | `Update ()` | |
| `createAppMarker` | `WalletUserProxy`、`Party`、`ContractId FeaturedAppRight` | `Update FeaturedAppRight_CreateActivityMarkerResult` | |
| `proxyBeneficiaries` | `WalletUserProxy`、`Party` | `[AppRewardBeneficiary]` | 印の受益者の一覧を得る |
| `validProxy` | `WalletUserProxy` | `Bool` | |

## 次に読む頁

次の頁「trafficを買い報酬を得る」は、アプリの開発者がCanton Coinでtrafficを買って使う流れと、Featured Appの印でCanton Coinの報酬を得る流れを追います。

https://cardene.dev/diagrams/canton-app-coin-rewards

## 出典

https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-util-featured-app-proxies

https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-util-featured-app-proxies/splice-util-featuredapp-delegateproxy

https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-util-featured-app-proxies/splice-util-featuredapp-walletuserproxy

https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-util-batched-markers

https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-util-batched-markers/splice-util-featuredapp-batchedmarkersproxy
