Skip to content

Commit 4c2f5b9

Browse files
committed
DevelopmentFundCoupon minting in MintingDelegation
Squashed commits from PR reviewed in #3598 Signed-off-by: Divam <dfordivam@gmail.com>
1 parent d428dda commit 4c2f5b9

File tree

5 files changed

+71
-9
lines changed

5 files changed

+71
-9
lines changed

apps/app/src/test/scala/org/lfdecentralizedtrust/splice/integration/tests/WalletMintingDelegationTimeBasedIntegrationTest.scala

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package org.lfdecentralizedtrust.splice.integration.tests
66
import org.lfdecentralizedtrust.splice.codegen.java.splice.amulet.{
77
Amulet,
88
AppRewardCoupon,
9+
DevelopmentFundCoupon,
910
UnclaimedActivityRecord,
1011
ValidatorRewardCoupon,
1112
ValidatorRight,
@@ -438,6 +439,7 @@ class WalletMintingDelegationTimeBasedIntegrationTest
438439
val appRewardAmount = BigDecimal(100.0)
439440
val unclaimedActivityAmount = BigDecimal(200.0)
440441
val validatorRewardAmount = BigDecimal(500.0)
442+
val developmentFundAmount = BigDecimal(300.0)
441443

442444
// For ValidatorRewardCoupon, we need ValidatorRight for beneficiary
443445
aliceValidatorBackend.participantClientWithAdminToken.ledger_api_extensions.commands
@@ -523,6 +525,22 @@ class WalletMintingDelegationTimeBasedIntegrationTest
523525
issuingRound.round,
524526
).create,
525527
)
528+
529+
// Create DevelopmentFundCoupon
530+
sv1Backend.participantClientWithAdminToken.ledger_api_extensions.commands
531+
.submitWithResult(
532+
userId = sv1Backend.config.ledgerApiUser,
533+
actAs = Seq(dsoParty),
534+
readAs = Seq.empty,
535+
update = new DevelopmentFundCoupon(
536+
dsoParty.toProtoPrimitive,
537+
beneficiaryParty.party.toProtoPrimitive,
538+
dsoParty.toProtoPrimitive, // fundManager = dso
539+
developmentFundAmount.bigDecimal,
540+
env.environment.clock.now.plus(Duration.ofDays(1)).toInstant,
541+
"test development fund coupon",
542+
).create,
543+
)
526544
}
527545

528546
// Advance time to collect all rewards
@@ -544,6 +562,9 @@ class WalletMintingDelegationTimeBasedIntegrationTest
544562
externalPartyWallet.store
545563
.listSortedLivenessActivityRecords(issuingRoundsMap)
546564
.futureValue shouldBe empty
565+
externalPartyWallet.store
566+
.listDevelopmentFundCoupons()
567+
.futureValue shouldBe empty
547568
}
548569
}
549570
}
@@ -558,7 +579,8 @@ class WalletMintingDelegationTimeBasedIntegrationTest
558579
issuingRound.optIssuancePerValidatorFaucetCoupon.orElse(java.math.BigDecimal.ZERO)
559580
)) +
560581
(validatorRewardAmount * BigDecimal(issuingRound.issuancePerValidatorRewardCoupon)) +
561-
unclaimedActivityAmount
582+
unclaimedActivityAmount +
583+
developmentFundAmount
562584

563585
actualIncrease shouldBe expectedTotalReward
564586

apps/wallet/src/main/scala/org/lfdecentralizedtrust/splice/wallet/automation/MintingDelegationCollectRewardsTrigger.scala

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import org.lfdecentralizedtrust.splice.codegen.java.splice.amuletrules.{
1212
import org.lfdecentralizedtrust.splice.codegen.java.splice.amuletrules.transferinput.{
1313
InputAmulet,
1414
InputAppRewardCoupon,
15+
InputDevelopmentFundCoupon,
1516
InputUnclaimedActivityRecord,
1617
InputValidatorLivenessActivityRecord,
1718
InputValidatorRewardCoupon,
1819
}
1920
import org.lfdecentralizedtrust.splice.codegen.java.splice.amulet.{
2021
AppRewardCoupon,
2122
Amulet,
23+
DevelopmentFundCoupon,
2224
UnclaimedActivityRecord,
2325
ValidatorRewardCoupon,
2426
ValidatorRight,
@@ -155,7 +157,8 @@ class MintingDelegationCollectRewardsTrigger(
155157
val hasRewardsToCollect = couponsData.livenessActivityRecords.nonEmpty ||
156158
validatorRewardCouponsToCollect.nonEmpty ||
157159
couponsData.appRewardCoupons.nonEmpty ||
158-
couponsData.unclaimedActivityRecords.nonEmpty
160+
couponsData.unclaimedActivityRecords.nonEmpty ||
161+
couponsData.developmentFundCoupons.nonEmpty
159162
// Merge amulets only if we're above 2x the merge limit to reduce potential waste of traffic
160163
val shouldMergeAmulets = amulets.size >= 2 * mergeLimit
161164

@@ -205,6 +208,7 @@ class MintingDelegationCollectRewardsTrigger(
205208
s"${filteredCouponsData.validatorRewardCoupons.size} validator reward coupons, " +
206209
s"${filteredCouponsData.appRewardCoupons.size} app reward coupons, " +
207210
s"${filteredCouponsData.unclaimedActivityRecords.size} unclaimed activity records, " +
211+
s"${filteredCouponsData.developmentFundCoupons.size} development fund coupons, " +
208212
s"and merged ${amuletsToMerge.size} amulets for delegation ${delegation.contractId}"
209213
)
210214
true
@@ -255,8 +259,10 @@ class MintingDelegationCollectRewardsTrigger(
255259
UnclaimedActivityRecord.ContractId,
256260
UnclaimedActivityRecord,
257261
]],
258-
// Handle DevelopmentFundCoupon once it lands on main branch
259-
// Issue: https://github.com/hyperledger-labs/splice/issues/3554
262+
developmentFundCoupons: Seq[Contract[
263+
DevelopmentFundCoupon.ContractId,
264+
DevelopmentFundCoupon,
265+
]],
260266
)
261267

262268
private def fetchCouponsData(
@@ -274,11 +280,13 @@ class MintingDelegationCollectRewardsTrigger(
274280
)
275281
appRewardCouponsWithQuantity <- store.listSortedAppRewards(issuingRoundsMap)
276282
unclaimedActivityRecords <- store.listUnclaimedActivityRecords()
283+
developmentFundCoupons <- store.listDevelopmentFundCoupons()
277284
} yield CouponsData(
278285
livenessActivityRecordsWithQuantity.map(_._1),
279286
validatorRewardCoupons,
280287
appRewardCouponsWithQuantity.map(_._1),
281288
unclaimedActivityRecords,
289+
developmentFundCoupons,
282290
)
283291
}
284292

@@ -308,12 +316,17 @@ class MintingDelegationCollectRewardsTrigger(
308316
new InputUnclaimedActivityRecord(record.contractId): TransferInput
309317
}
310318

319+
val developmentFundCouponInputs: Seq[TransferInput] =
320+
couponsData.developmentFundCoupons.map { coupon =>
321+
new InputDevelopmentFundCoupon(coupon.contractId): TransferInput
322+
}
323+
311324
val amuletInputs: Seq[TransferInput] = amuletsToMerge.map { amulet =>
312325
new InputAmulet(amulet.contractId): TransferInput
313326
}
314327

315328
val allInputs = livenessInputs ++ validatorCouponInputs ++ appCouponInputs ++
316-
unclaimedActivityRecordInputs ++ amuletInputs
329+
unclaimedActivityRecordInputs ++ developmentFundCouponInputs ++ amuletInputs
317330
allInputs.take(maxNumInputs)
318331
}
319332

apps/wallet/src/main/scala/org/lfdecentralizedtrust/splice/wallet/store/ExternalPartyWalletStore.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package org.lfdecentralizedtrust.splice.wallet.store
66
import org.lfdecentralizedtrust.splice.codegen.java.splice.amulet.{
77
Amulet,
88
AppRewardCoupon,
9+
DevelopmentFundCoupon,
910
LockedAmulet,
1011
UnclaimedActivityRecord,
1112
ValidatorRewardCoupon,
@@ -92,6 +93,18 @@ trait ExternalPartyWalletStore extends TransferInputStore with NamedLogging {
9293
.listContracts(UnclaimedActivityRecord.COMPANION, limit)
9394
.map(_.map(_.contract))
9495

96+
def listDevelopmentFundCoupons(
97+
limit: Limit = Limit.DefaultLimit
98+
)(implicit tc: TraceContext): Future[Seq[
99+
Contract[
100+
DevelopmentFundCoupon.ContractId,
101+
DevelopmentFundCoupon,
102+
]
103+
]] =
104+
multiDomainAcsStore
105+
.listContracts(DevelopmentFundCoupon.COMPANION, limit)
106+
.map(_.map(_.contract))
107+
95108
def lookupValidatorRight()(implicit
96109
tc: TraceContext
97110
): Future[Option[Contract[ValidatorRight.ContractId, ValidatorRight]]] =
@@ -193,6 +206,10 @@ object ExternalPartyWalletStore {
193206
co.payload.dso == dso &&
194207
co.payload.beneficiary == externalParty
195208
}(ExternalPartyWalletAcsStoreRowData(_)),
209+
mkFilter(DevelopmentFundCoupon.COMPANION) { co =>
210+
co.payload.dso == dso &&
211+
co.payload.beneficiary == externalParty
212+
}(ExternalPartyWalletAcsStoreRowData(_)),
196213
// ValidatorRight is needed for collecting ValidatorRewardCoupons which
197214
// may have been issued to the external party for traffic purchases, via
198215
// MintingDelegation. The external party is both the user AND the

daml/dars.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ splice-wallet-payments 0.1.6 6124379528eeb6fa17ecdab15577c29abb33d0c0d34dc5f2680
124124
splice-wallet-payments 0.1.7 4e3e0d9cdadf80f4bf8f3cd3660d5287c084c9a29f23c901aabce597d72fd467
125125
splice-wallet-payments 0.1.8 e48ea337ee3335c8bb3206a2501ce947ac1a7bdb1825cee8f28bad64f5a7bc4b
126126
splice-wallet-payments 0.1.9 7f4e081ad96f2ccded0c053b0cf5ddddae1139dfc3bb89cefcf77ea70f2cecb7
127-
splice-wallet-test 0.1.19 b77428ab7dcff349857721f418fd1b25d85325ba0d0f75482af57773db7fcdae
127+
splice-wallet-test 0.1.19 6184b47ef584d5dd4b36a4ea97fa71e09af0c51e4569db5cd66c636e568b6f81
128128
splitwell 0.1.0 075c76de553ab88383a7c69de134afa82aacfdf8ea8fcfe8852c4b199c3b2669
129129
splitwell 0.1.1 ccb1a0215053062202052e1a052f9214da3fdae5253a6d43e2e155ff4f57fe75
130130
splitwell 0.1.10 d42676a366f7ca7a2409974dd3054aa4d83ab29baa3b2086ad021407b0a1a295
@@ -142,4 +142,4 @@ splitwell 0.1.6 872da0dd7986fd768930f85d6a7310a94a0ef924e7fbb7bb7a4e149f2b5feb74
142142
splitwell 0.1.7 841d1c9c86b5c8f3a39059459ecd8febedf7703e18f117300bb0ebf4423db096
143143
splitwell 0.1.8 63b8153a08ceb4bf40d807acc5712372c3eac548c266be4d5e92470b4f655515
144144
splitwell 0.1.9 b6267905698d2798b9ef171e27d49fb88e052ec0ec0e0675a3a1b275c7d037d4
145-
splitwell-test 0.1.19 4e4909acaa20009d7485d51bb8c385c5c2fb8ca441365e58ff90c9e544ee5e8f
145+
splitwell-test 0.1.19 c6ec7ab2af6ff076b37ba6e5be2d6b615acf7d289d3c00ddd87ff7da349c7192

daml/splice-wallet-test/daml/Splice/Scripts/Wallet/TestMintingDelegation.daml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ testMintingDelegation = do
7474
reason = ""
7575
expiresAt = now `addRelTime` days 60
7676

77+
let developmentFundCouponAmount = 50.0
78+
developmentFundCouponCid <- submit app.dso $ createCmd DevelopmentFundCoupon with
79+
dso = app.dso
80+
beneficiary = beneficiary
81+
fundManager = app.dso
82+
amount = developmentFundCouponAmount
83+
expiresAt = now `addRelTime` days 60
84+
reason = "Test development fund coupon"
85+
7786
-- Wait for rounds to advance so coupons can be minted
7887
runNextIssuance app
7988
runNextIssuance app
@@ -96,7 +105,8 @@ testMintingDelegation = do
96105
InputValidatorLivenessActivityRecord livenessActivityRecordCid,
97106
InputAppRewardCoupon appRewardCouponCid,
98107
InputValidatorRewardCoupon validatorRewardCouponCid,
99-
InputUnclaimedActivityRecord unclaimedActivityRecordCid
108+
InputUnclaimedActivityRecord unclaimedActivityRecordCid,
109+
InputDevelopmentFundCoupon developmentFundCouponCid
100110
]
101111
context = PaymentTransferContext with
102112
context
@@ -111,7 +121,7 @@ testMintingDelegation = do
111121
let expectedValidatorFaucetAmount = getIssuingMiningRoundIssuancePerValidatorFaucetCoupon issuingRound
112122
let expectedAppReward = appRewardCouponAmount * issuingRound.issuancePerUnfeaturedAppRewardCoupon
113123
let expectedValidatorReward = validatorRewardCouponAmount * issuingRound.issuancePerValidatorRewardCoupon
114-
let expectedTotal = expectedValidatorFaucetAmount + expectedAppReward + expectedValidatorReward + unclaimedRewardCouponAmount
124+
let expectedTotal = expectedValidatorFaucetAmount + expectedAppReward + expectedValidatorReward + unclaimedRewardCouponAmount + developmentFundCouponAmount
115125

116126
require ("Combined reward should match expected " <> show expectedTotal <> ", got: " <> show reward)
117127
(reward >= expectedTotal - 1.0 && reward <= expectedTotal + 1.0)

0 commit comments

Comments
 (0)