tres-asc845-swap-reprice-skill

작성자: anthropic

ASC 845(비화폐성 거래)에 따라 스왑 거래 레그의 가격을 재조정하여 청산 계정이 순액 기준 0이 되도록 합니다. 사용자가 다음을 원할 때마다 이 스킬을 사용하세요:…

npx skills add https://github.com/anthropics/claude-plugins-community --skill tres-asc845-swap-reprice-skill

ASC 845 Swap Repricing Skill

Purpose

Implements equal-value exchange under ASC 845 (Nonmonetary Transactions) for swap transactions in TRES Finance. In a simultaneous swap, the fair value of the asset surrendered (outflow) is the best evidence of the fair value of the asset received (inflow). This skill reprices inflow legs to match outflow legs so that clearing accounts net to zero.

When to Use

  • A swaps/trade clearing account has a non-zero residual after month-end
  • User wants to apply ASC 845 to a population of swap transactions
  • User says "setBatchUseCounterpartyFiatValue" or similar

MCP Server

All GraphQL calls use the user-tres-finance MCP server (execute tool).

Variable keys and nested input fields MUST use camelCase (e.g. timestamp_Gte, not timestamp_gte).

Prerequisites

  • TRES Finance MCP connection (user-tres-finance)
  • The user must specify:
    1. Target ERP account — the clearing account to zero out (e.g. "Swaps Clearing Account", NS #818)
    2. Transaction scope — either a date range (timestamp_Gte / timestamp_Lte) or specific tx hashes
    3. Confirmation — user must approve before mutations are executed

Workflow

Step 1: Gather Parameters

Ask the user for:

  • Target ERP account name or ID (the clearing account)
  • Date range OR list of transaction hashes
  • Activity tags (optional) — filter to only transactions with specific classification activities (e.g. "STAKING LOCKUP", "SWAP"). None, one, or many may be selected. If omitted, all activities are included. Use tx_Classification_Activity_In on the TRES query.
  • Currency (default: USD)
  • Whether to run in dry-run (preview only) or execute mode

Step 2: Query Subtransactions

Use the TRES subTransaction query to fetch all subtransactions in scope. Include these fields:

{
  id
  amount
  balanceFactor
  timestamp
  fiatValue
  isManualFiatValue
  belongsTo { id name }
  asset { assetClass { symbol } }
  tx { id identifier classification { activity } }
  flowRule {
    ruleName
    integrationAccount { name value }
  }
}

If activity tags were specified, pass them as tx_Classification_Activity_In: ["STAKING LOCKUP", "SWAP"] on the query. Note: transactions with classification: null will be excluded when this filter is used, so only apply it when the user explicitly requests it.

Paginate in batches of 50 (to avoid timeouts). Save the combined results to a JSON file for the orchestrator script.

Step 3: Run the Orchestrator Script

From the skill scripts/ directory, run orchestrate_reprice.py (handles MCP response shapes, account filter, preview, and mutation JSON):

cd "${CLAUDE_PLUGIN_ROOT}/skills/tres-asc845-swap-reprice-skill/scripts" && \
python3 orchestrate_reprice.py \
  --input /path/to/swap_reprice_input.json \
  --account-name "Swaps Clearing Account" \
  --output /path/to/reprice_plan.json \
  --mutations-output /path/to/reprice_mutations.json

Use --account-value instead of --account-name when filtering by ERP account number. Pass --activity-tags SWAP "STAKING LOCKUP" when the user requested activity filters.

The script prints a preview to stdout and writes:

  • reprice_plan.json — full plan with per-transaction adjustments
  • reprice_mutations.json — ready-to-execute setManualFiatValue variables

For lower-level repricing only (no orchestration), use reprice_swaps.py directly — see scripts/reprice_swaps.py for flags.

Step 4: Repricing Logic (ASC 845)

The orchestrator implements the logic below. Read scripts/reprice_swaps.py for the canonical implementation.

The core principle: calculate the difference between total outflow fiat and total inflow fiat, then distribute that difference across inflows in proportion to their token amounts. This preserves the original pricing as a base and makes the minimum adjustment needed.

For each parent transaction:

Case 1: One outflow, one inflow

inflow.newFiatValue = outflow.fiatValue

Case 2: One outflow, many inflows

difference = outflow.fiatValue - sum(inflow.fiatValue for each inflow)
totalInflowTokens = sum(inflow.amount for each inflow)
for each inflow:
    tokenProportion = inflow.amount / totalInflowTokens
    inflow.newFiatValue = inflow.fiatValue + (difference * tokenProportion)

Case 3: Many outflows, one inflow

inflow.newFiatValue = sum(outflow.fiatValue for each outflow)

Case 4: Many outflows, many inflows

totalOutflowFiat = sum(outflow.fiatValue for each outflow)
totalInflowFiat = sum(inflow.fiatValue for each inflow)
difference = totalOutflowFiat - totalInflowFiat
totalInflowTokens = sum(inflow.amount for each inflow)
for each inflow:
    tokenProportion = inflow.amount / totalInflowTokens
    inflow.newFiatValue = inflow.fiatValue + (difference * tokenProportion)

Worked example (Case 2):

Before:  Outflow = 100 tokens @ $100 | Inflows = 25 tokens @ $25, 25 @ $25, 35 @ $35 (total $85)
         Difference = $100 - $85 = $15 | Total inflow tokens = 85

After:   Inflow 1: $25 + ($15 × 25/85) = $25 + $4.41 = $29.41
         Inflow 2: $25 + ($15 × 25/85) = $25 + $4.41 = $29.41
         Inflow 3: $35 + ($15 × 35/85) = $35 + $6.18 = $41.18
         Total inflows after = $100.00 ✓  (clearing account nets to zero)

Edge cases:

  • If totalInflowTokens == 0, distribute the difference equally across inflows
  • If a subtransaction already has isManualFiatValue == true, flag it for user review (it was already manually repriced)
  • Skip transactions with only outflows or only inflows (not a complete swap)
  • Last inflow in the group receives the remainder to absorb rounding (ensures exact match)

Step 5: Preview the Reprice Plan

Present the orchestrator stdout summary and/or the plan JSON to the user:

TX Identifier | Outflow Total | Inflow Before | Inflow After | Adjustment
------------- | ------------- | ------------- | ------------ | ----------
0xabc...      | $1,234.56     | $1,230.00     | $1,234.56    | +$4.56
0xdef...      | $5,678.90     | $5,670.00     | $5,678.90    | +$8.90

Also show aggregate stats:

  • Total transactions affected
  • Total outflow fiat
  • Total inflow fiat (before)
  • Total inflow fiat (after)
  • Net clearing account residual (before → after, should go to $0)
  • Count of already-manually-priced subtxs being overwritten

Step 6: Execute (with user confirmation)

Never run mutations without explicit user confirmation.

Only after the user confirms, execute setManualFiatValue for each inflow subtransaction (use variables from reprice_mutations.json):

mutation SetManualFiatValue($id: ID!, $newFiatValue: String!, $currency: String) {
  setManualFiatValue(id: $id, newFiatValue: $newFiatValue, currency: $currency) {
    subTransaction {
      id
      fiatValue
      isManualFiatValue
    }
  }
}

Execute one at a time (not batch) to handle locked-period errors gracefully. If setBatchManualFiatValue is preferred for speed, group inflows by asset where a uniform per-unit price applies.

Important: setManualFiatValue takes newFiatValue as a string. setBatchManualFiatValue takes ids (list) and newUnitValue (Float) and computes newUnitValue * amount — only use this if all subtxs in the batch should have the same unit price.

Step 7: Verify

Re-query the subtransactions and re-aggregate to confirm the clearing account now nets to zero.

Error Handling

  • Locked period: If a subtransaction is in a locked period, warn the user. They must unlock via deleteLockedPeriod, apply changes, then re-lock via createLockedPeriod.
  • Missing fiat values: If outflow fiatValue is null, skip the transaction and flag it.
  • Zero-value legs: If outflow total is $0, skip (nothing to propagate).
  • Already manual: Flag but still overwrite — only after the user confirmed the batch.

Script Reference

ScriptRole
scripts/orchestrate_reprice.pyPrimary entry — parse MCP JSON, filter, preview, write plan + mutations
scripts/reprice_swaps.pyCore ASC 845 repricing engine (imported by orchestrator; usable standalone)

anthropic의 다른 스킬

analyzing-financial-statements
anthropic
이 스킬은 재무제표 데이터로부터 투자 분석을 위한 주요 재무 비율과 지표를 계산합니다.
applying-brand-guidelines
anthropic
이 스킬은 생성된 모든 문서에 일관된 기업 브랜딩과 스타일(색상, 글꼴, 레이아웃, 메시징 포함)을 적용합니다.
creating-financial-models
anthropic
이 스킬은 DCF 분석, 민감도 테스트, 몬테카를로 시뮬레이션, 시나리오 플래닝을 포함한 고급 재무 모델링 제품군을 투자…에 제공합니다.
board-minutes
anthropic
이사회 또는 위원회 회의록을 사내 형식으로 작성합니다. 캘린더에서 예정된 이사회 및 위원회 회의를 자동으로 감지하고, 안건을 요청한 후…
crm-cleanup
anthropic
HubSpot에서 오래된 거래, 중복 연락처, 누락된 필드를 스캔한 후 소유자가 승인한 항목을 수정합니다. 선택적 범위 인수를 받아 거래, 연락처 등을 지정할 수 있습니다.
redshift-api
anthropic
Amazon Redshift에 대해 SQL 실행 — 명령문 제출, 상태 폴링, 결과 페이지 탐색, 데이터베이스/스키마/테이블 탐색. 사용자가 원할 때마다 이 기능을 사용하세요…
ticket-deflector
anthropic
고객이 전달한 이메일이나 티켓을 읽고, PayPal에서 주문/환불 상태를 가져오며, HubSpot에서 계정 내역을 조회한 후, 소유자의 어조에 맞춰 답변을 작성합니다.
reg-feed-watcher
anthropic
규제 피드를 지금 확인하고, 마지막 확인 이후 새로 추가된 내용을 사용자의 중요도 기준에 따라 필터링하여 보고합니다. 사용자가 "피드 확인해 줘"라고 말할 때 사용하세요.