@@ -953,3 +953,125 @@ describe("BoostCore", () => {
953953 expect ( feesInfo . asset . toLowerCase ( ) ) . toBe ( erc20 . assertValidAddress ( ) ) ;
954954 } ) ;
955955} ) ;
956+
957+ describe ( "Top-Up Incentives" , ( ) => {
958+ let incentive : ReturnType < typeof fixtures . core . ERC20Incentive > ;
959+ let boostId : bigint ;
960+
961+ beforeAll ( async ( ) => {
962+ const { core } = fixtures ;
963+ const { budget, erc20 } = budgets ;
964+
965+ incentive = core . ERC20Incentive ( {
966+ asset : erc20 . assertValidAddress ( ) ,
967+ strategy : StrategyType . POOL ,
968+ reward : parseEther ( "1" ) ,
969+ limit : 5n ,
970+ manager : budget . assertValidAddress ( ) ,
971+ } ) ;
972+ await erc20 . mint ( defaultOptions . account . address , parseEther ( "110" ) ) ;
973+ await erc20 . approve ( budget . assertValidAddress ( ) , parseEther ( "110" ) ) ;
974+ await budget . allocate ( {
975+ amount : parseEther ( "110" ) ,
976+ asset : erc20 . assertValidAddress ( ) ,
977+ target : defaultOptions . account . address ,
978+ } ) ;
979+
980+
981+ const createdBoost = await core . createBoost ( {
982+ protocolFee : 0n ,
983+ maxParticipants : 5n ,
984+ budget,
985+ action : core . EventAction (
986+ makeMockEventActionPayload (
987+ core . assertValidAddress ( ) ,
988+ erc20 . assertValidAddress ( ) ,
989+ ) ,
990+ ) ,
991+ validator : core . SignerValidator ( {
992+ signers : [ defaultOptions . account . address ] ,
993+ validatorCaller : defaultOptions . account . address ,
994+ } ) ,
995+ allowList : core . SimpleAllowList ( {
996+ owner : defaultOptions . account . address ,
997+ allowed : [ defaultOptions . account . address ] ,
998+ } ) ,
999+ incentives : [ incentive ] ,
1000+ } ) ;
1001+ boostId = createdBoost . id ;
1002+ } ) ;
1003+
1004+ test ( "can top up from a budget (pre-fee)" , async ( ) => {
1005+ const { core } = fixtures ;
1006+ const { budget, erc20 } = budgets ;
1007+
1008+ console . log ( "budget" , budget . assertValidAddress ( ) ) ;
1009+
1010+ const netTopup = parseEther ( "5" ) ;
1011+
1012+ await core . topupIncentiveFromBudgetPreFee ( boostId , 0n , netTopup , budget . assertValidAddress ( ) ) ;
1013+ console . log ( "topup done" ) ;
1014+
1015+ expect ( await incentive . limit ( ) ) . toBe ( 5n + 5n ) ; // original limit 5 + topup 5
1016+ } ) ;
1017+
1018+ test ( "can top up from a budget (post-fee)" , async ( ) => {
1019+ const { core } = fixtures ;
1020+ const { budget } = budgets ;
1021+
1022+ const total = parseEther ( "5.5" ) ;
1023+ await core . topupIncentiveFromBudgetPostFee ( boostId , 0n , total , budget . assertValidAddress ( ) ) ;
1024+
1025+ expect ( await incentive . limit ( ) ) . toBe ( 10n + 5n ) ;
1026+ } ) ;
1027+
1028+ test ( "pre-fee and post-fee top-ups lead to the same net top-up" , async ( ) => {
1029+ const { core } = fixtures ;
1030+ const { budget } = budgets ;
1031+
1032+ const net = parseEther ( "2" ) ;
1033+ const netPlusFee = parseEther ( "2.2" ) ;
1034+
1035+ await core . topupIncentiveFromBudgetPreFee ( boostId , 0n , net , budget . assertValidAddress ( ) ) ;
1036+
1037+ await core . topupIncentiveFromBudgetPostFee ( boostId , 0n , netPlusFee , budget . assertValidAddress ( ) ) ;
1038+
1039+ expect ( await incentive . limit ( ) ) . toBe ( 15n + 4n ) ;
1040+ } ) ;
1041+
1042+ test ( "can top up from sender (pre-fee)" , async ( ) => {
1043+ const { core } = fixtures ;
1044+ const { erc20 } = budgets ;
1045+
1046+ const netTopup = parseEther ( "10" ) ;
1047+ const netPlusFee = parseEther ( "11" ) ;
1048+ await erc20 . mint ( defaultOptions . account . address , netPlusFee ) ;
1049+ await erc20 . approve ( core . assertValidAddress ( ) , netPlusFee ) ;
1050+
1051+ await core . topupIncentiveFromSenderPreFee ( boostId , 0n , netTopup ) ;
1052+
1053+ expect ( await incentive . limit ( ) ) . toBe ( 19n + 10n ) ;
1054+ } ) ;
1055+
1056+ test ( "can top up from sender (post-fee)" , async ( ) => {
1057+ const { core } = fixtures ;
1058+ const { erc20 } = budgets ;
1059+
1060+ const totalWithFee = parseEther ( "5.5" ) ;
1061+ await erc20 . mint ( defaultOptions . account . address , totalWithFee ) ;
1062+ await erc20 . approve ( core . assertValidAddress ( ) , totalWithFee ) ;
1063+
1064+ await core . topupIncentiveFromSenderPostFee ( boostId , 0n , totalWithFee ) ;
1065+
1066+ expect ( await incentive . limit ( ) ) . toBe ( 29n + 5n ) ;
1067+ } ) ;
1068+
1069+ test ( "throws if net top-up is zero" , async ( ) => {
1070+ const { core } = fixtures ;
1071+ const { budget } = budgets ;
1072+
1073+ await expect ( async ( ) => {
1074+ await core . topupIncentiveFromBudgetPreFee ( boostId , 0n , 0n , budget . assertValidAddress ( ) ) ;
1075+ } ) . rejects . toThrowError ( ) ;
1076+ } ) ;
1077+ } ) ;
0 commit comments