前の頁「Canton Coinを送る」では、一括の送金が返すTransferResultの欄summaryを、入力と出力の量と、払った料金の要約として見ました。 この頁では、そのTransferSummaryが持つ欄、料金と時と共に減る量の型と計算の関数、送金が失敗する理由を追います。 そこで、まず要約の欄を表で追い、次に料金の型と関数、最後に失敗の理由を、表と図で追います。

TransferとTransferResultとTransferOutputと、Optionalとvariantは、前の頁で見ました。

どの料金が実際に掛かるかと、mining roundとactivity recordは、頁「Canton Coinの役と料金を知る」で見ました。

その頁は、CIP-0078が送金の料金とロックの料金を除いたと書きます。 この頁の欄と型は資料が載せる型で、除いた後の値は追いません。

CIPは、頁「CIPが承認され効力を持つまで」で見ました。

reward couponは、報酬の引換券です。

送金の要約が記す入力の量

TransferSummaryは、入力と出力の量と、払った料金の要約です。 トランザクションの要約を表示する時に、送金を始めたTransferの指定と合わせて使います。 台帳の外で計算するのが難しい主要な数を、手早く得るためにあります。

入力の量の欄は、次の表の7つです。 それぞれ、送金へ入れたreward couponとAmuletとactivity recordの発行の合計を示します。

欄 型 合計する物
inputAppRewardAmount Decimal app reward couponの発行
inputValidatorRewardAmount Decimal validator reward couponの発行
inputSvRewardAmount Decimal SV reward couponの発行
inputAmuletAmount Decimal Amuletの入力
inputValidatorFaucetAmount Optional Decimal validator faucet couponの発行
inputUnclaimedActivityRecordAmount Optional Decimal unclaimed activity recordの発行
inputDevelopmentFundAmount Optional Decimal development fund couponの発行

inputAmuletAmountは、保有の料金を引く前の、送金へ入れたAmuletの合計です。 inputValidatorFaucetAmountは、CIP-3で足された欄です。

料金と残高の欄

料金と残高の欄は、次の表の6つです。

欄 型 中身
balanceChanges Map Party BalanceChange partyごとの残高の変化
holdingFees Decimal 送り手が入力のAmuletに払った保有の料金
outputFees [Decimal] 出力ごとの料金を、指定した順に並べた一覧
senderChangeFee Decimal 送り手へお釣りを返す料金
senderChangeAmount Decimal 全ての出力と料金を払った後に送り手へ返す最後の量。0なら送り手のAmuletは作られない
amuletPrice Decimal 送金を実行したroundのAmuletの価格

senderChangeFeeは、全ての出力を払った後の残りと、Amuletを1つ作る料金の、小さい方になります。 残りが作る料金より小さい時は、残りの全てがお釣りを返す料金に消えます。 この時は、送り手のAmuletは作られず、senderChangeAmountは0になりますが、送金は成功します。 お釣りを返さない送金では、全ての出力を払った後の残りは必ず0になり、senderChangeFeeも0になります。

入力の合計と残高の変化

TransferInputsSummaryは、次の表の10の欄を持ちます。

欄 型
totalAmuletAmount Decimal
totalAppRewardAmount Decimal
totalValidatorRewardAmount Decimal
totalValidatorFaucetAmount Decimal
totalSvRewardAmount Decimal
totalHoldingFees Decimal
amountArchivedAsOfRoundZero Decimal
changeToHoldingFeesRate Decimal
totalUnclaimedActivityRecordAmount Optional Decimal
totalDevelopmentFundAmount Optional Decimal

totalValidatorFaucetAmountは、台帳に保存されない型の欄なので、Optionalにしません。 inputUnclaimedActivityRecordAmountとinputDevelopmentFundAmountと、この表のtotalUnclaimedActivityRecordAmountとtotalDevelopmentFundAmountは、Optionalにしてあります。 これは、TransferSummaryとTransferInputsSummaryがシリアライズできる型で、欄の追加を、パッケージのアップロードの時に、アップグレードの検査が確かめるためです。

BalanceChangeは、次の表の2つの欄を持ちます。 Additiveのインスタンスを持ち、足し合わせられます。

欄 型 中身
changeToInitialAmountAsOfRoundZero Decimal round 0に正規化した、総残高の変化
changeToHoldingFeesRate Decimal 保有の料金の総額の変化

round 0への正規化では、round 3で作られたAmuletを、初めの量がより多いround 0で作られたAmuletとして扱います。

出力の要約と料金の計算

PreprocessedTransferOutputは、次の表の4つの欄を持ちます。 TransferOutputsSummaryは、その一覧の[PreprocessedTransferOutput]の別名です。

欄 型 中身
owner Party 出力の所有者
outputFee Decimal この出力を作る料金
amount Decimal 料金を引いた後に、出力が持つAmuletの量
lock Optional TimeLock Amuletをロックするか

AmuletRules_ComputeFeesは、与えたcontextに対する、送金の出力の料金を計算するchoiceです。 controllerはsenderで、次の表の4つの欄を受け取ります。 返すAmuletRules_ComputeFeesResultは、[Decimal]の欄feesを持ちます。

欄 型
context TransferContext
sender Party
outputs [TransferOutput]
expectedDso Optional Party

料金と減る量の型

Splice.Feesのモジュールは、いろいろな種類の料金を計算するための関数と型をまとめます。 次の表の5つの型が、料金と時と共に減る量を表します。

型 欄 中身
ExpiringAmount initialAmountはDecimal、createdAtはRound、ratePerRoundはRatePerRound 時と共に減る量
FixedFee feeはDecimal 行う操作に関わらず一定の料金
RatePerDay rateはDecimal 1日あたりの率
RatePerRound rateはDecimal 1roundあたりの率
SteppedRate initialRateはDecimal、stepsはDecimalの組の一覧 区分ごとに線形な関数で決まる率

SteppedRate 0.01 [(100.0, 0.001), (1000.0, 0.0001), (1000000, 0.00001)]は、最初の100に1%、100から1000に0.1%、1000から1000000に0.01%、それより上に0.001%を課します。 FixedFeeとRatePerRoundとSteppedRateは、Patchableのインスタンスを持ち、設定の一部を差分で書き換えられます。

この5つの型を、欄の型に持つ所は、次の表の7つです。

欄を持つ型 欄 型
Amulet amount ExpiringAmount
TransferConfig createFee FixedFee
TransferConfig lockHolderFee FixedFee
TransferConfig holdingFee RatePerRound
TransferConfigV2 holdingFee RatePerRound
ExpiringAmount ratePerRound RatePerRound
TransferConfig transferFee SteppedRate

次の図Aでは、Amuletから、欄の型を順にたどって追います。 この図では、枝は欄の型の入れ子だけを示します。 欄の名前は、上の表で見ます。

AmuletExpiringAmountRatePerRound1122
  1. Amuletが持つ量

    Amuletが持つ量の型は、時と共に減る量の型です。

  2. 時と共に減る量の率

    時と共に減る量の型は、1roundあたりの率の型を持ちます。

次の図Bでは、設定のTransferConfigから、欄の型を順にたどって追います。 この図では、枝は欄の型の入れ子だけを示します。 TransferConfigV2のholdingFeeは、表で見ます。

TransferConfigFixedFeeRatePerRoundSteppedRate112233
  1. 一定の料金

    設定のTransferConfigは、作る料金とロックの料金に、一定の料金の型を持ちます。

  2. 保有の料金の率

    設定のTransferConfigは、保有の料金に、1roundあたりの率の型を持ちます。

  3. 送金の料金の率

    設定のTransferConfigは、送金の料金に、区分ごとの率の型を持ちます。

率と減る量を計算する関数

率と減る量を計算する関数は、次の表の9つです。

関数 受け取る物 返す物 中身
chargeRatePerRound RatePerRound、経過したroundの数のRelRound Decimal 課す額
chargeSteppedRate SteppedRate、Decimal Decimal 課す額。補助のgoChargeSteppedRateが段を順にたどって計算する
chargeRatePerDay RatePerDay、時間の長さのRelTime Decimal 課す額
ratePerRoundToRatePerDay RatePerRound、1roundの長さのRelTime RatePerDay 1roundあたりの率を、1日あたりの率に直した値
scaleRatePerRound Decimal、RatePerRound RatePerRound roundの率を倍した値
scaleFixedFee Decimal、FixedFee FixedFee FixedFeeを倍した値
scaleSteppedRate Decimal、SteppedRate SteppedRate 固定と変動の率を倍した値
expiringAmount RatePerRound、初めの量のDecimal、作ったroundのRound ExpiringAmount ExpiringAmountを作る
getValueAsOfRound0 ExpiringAmount Decimal round 0の時点に換算した値

倍率の関数は、任意の倍率sについて、次の等式が成り立つように率を倍します。 rは率、dtはchargeRatePerRoundが受け取る経過したroundの数、qはchargeSteppedRateが受け取る量です。

s * chargeRatePerRound r dt = chargeRatePerRound (s scaleRatePerRound r) dt

s * chargeSteppedRate r (q/s) = chargeSteppedRate (s scaleSteppedRate r) q

値が正しい形かをBoolで返す関数は、次の表の4つです。

関数 受け取る物
positiveRatePerRound RatePerRound
positiveFixedFee FixedFee
validSteppedRate SteppedRate
validExpiringAmount ExpiringAmount

時間の長さを数に直す関数は、次の表の5つです。

関数 受け取る物 返す物
relTimeToMicros RelTime Decimal
microsPerDay なし Decimal
relTimeToDays RelTime Decimal
daysToRelTime Decimal RelTime
relTimeToSeconds RelTime Decimal

設定と要約を扱う関数

送金の設定と要約を扱う関数は、次の表の6つです。

関数 受け取る物 返す物
transferConfigAmuletFromOpenRound OpenMiningRound TransferConfig Amulet
scaleFees Decimal、TransferConfig USD TransferConfig Amulet
scaleFees2 Decimal、TransferConfigV2 USD TransferConfigV2 Amulet
splitAndBurn Party、Decimal、[TransferInput]、TransferContext、Party、Text TransferResultとMetadataの組
totalBurnFromSummary TransferSummary Decimal
legacyAmuletCreateSummary 2つのParty、ContractId OpenMiningRound、ContractId Amulet AmuletCreateSummary (ContractId Amulet)

transferConfigAmuletFromOpenRoundは、そのroundのTransferConfig Amuletを返します。 scaleFeesは、取る料金が同じ倍率で変わるように、設定を倍率で直します。 scaleFees2は、同じことをTransferConfigV2に行います。 totalBurnFromSummaryは、送金の中でburnした総量を計算します。

送金が失敗する理由

送金の失敗に関わる名前は、InvalidTransferReasonの5つの形と、失敗の状態を返す5つの関数です。 InvalidTransferReasonはvariantで、次の表の5つの形を持ちます。

形 欄
ITR_InsufficientFunds missingAmountはDecimal
ITR_UnknownSynchronizer synchronizerIdはText
ITR_InsufficientTopupAmount requestedTopupAmountとminTopupAmountは、どちらもInt
ITR_Other descriptionはText
ExtInvalidTransferReason dummyUnitFieldは()

ExtInvalidTransferReasonは、前の頁で見た拡張の形です。

失敗の状態のFailureStatusを返す関数は、次の表の5つです。

関数 受け取る物 返す物
mkUnknownSynchronizerFailure Text FailureStatus
mkInsufficientTopupAmountFailure 2つのInt FailureStatus
mkMaximumInputsExceededFailure なし FailureStatus
mkMaximumOutputsExceededFailure なし FailureStatus
mkInsufficientFundsFailure Decimal FailureStatus

関数mkFailureStatusは、TextとFailureCategoryとTextとTextMap Textを受け取り、FailureStatusを返します。 関数spliceErrorIdは、Textを受け取り、Textを返します。 関数checkTransferConstraintsは、TransferとTransferSummaryとTransferConfigV2 unitを受け取り、制約を満たさない時のFailureStatusか、()をEitherで返します。

次の図Cでは、2つの一覧の5つずつの名前を、表の並びで足して追います。 関数の枝の名前は、関数の名前から、先頭のmkと末尾のFailureを除いた形です。 この図では、2つの一覧の対応を線にしません。

送金の失敗無効な理由ITR_InsufficientFundsITR_UnknownSynchronizerITR_InsufficientTopupAmountITR_OtherExtInvalidTransferReason失敗の状態UnknownSynchronizerInsufficientTopupAmountMaximumInputsExceededMaximumOutputsExceededInsufficientFunds112233
  1. 無効な理由の型

    送金の失敗に関わる名前の1つ目は、無効な理由の型です。

  2. 無効な理由の5つの形

    無効な理由の型は、5つの形を持ちます。

  3. 失敗の状態を返す5つの関数

    2つ目は、失敗の状態を返す5つの関数です。
    枝の名前は、関数の名前から先頭のmkと末尾のFailureを除いた形です。

次に読む頁

次の頁「受け手が前もって受け取りを許す」は、受け手がTransferPreapprovalを作り、更新し、取り消して、個々のtransfer offerを承認せずにCanton Coinを受ける流れを追います。

出典