5
5
AlgorandClient ,
6
6
AssetOptInParams ,
7
7
AssetTransferParams ,
8
- OnCompleteCallParameters ,
9
8
SigningAccount ,
10
9
)
11
10
from algokit_utils .config import config
12
11
13
12
from smart_contracts import constants as sc_cst
14
13
from smart_contracts .artifacts .perpetual_bond .perpetual_bond_client import (
14
+ AssetCreateArgs ,
15
15
AssetMetadata ,
16
16
PerpetualBondClient ,
17
+ PerpetualBondFactory , AssignRoleArgs , AssetConfigArgs , OpenAccountArgs , CommonAppCallParams ,
18
+ SetSecondaryTimeEventsArgs , PrimaryDistributionArgs , PayCouponArgs , SetAssetSuspensionArgs , SetDefaultStatusArgs
17
19
)
18
20
from tests import utils
19
21
from tests .conftest import (
@@ -85,38 +87,28 @@ def perpetual_bond_cfg(
85
87
86
88
87
89
@pytest .fixture (scope = "function" )
88
- def perpetual_bond_client_void (
89
- algorand : AlgorandClient , arranger : SigningAccount
90
+ def perpetual_bond_client_empty (
91
+ algorand : AlgorandClient ,
92
+ arranger : SigningAccount ,
93
+ asset_metadata : AssetMetadata ,
90
94
) -> PerpetualBondClient :
91
95
config .configure (
92
96
debug = False ,
97
+ populate_app_call_resources = True ,
93
98
# trace_all=True,
94
99
)
95
100
96
- client = PerpetualBondClient (
97
- algorand .client .algod ,
98
- creator = arranger .address ,
99
- signer = arranger .signer ,
100
- indexer_client = algorand .client .indexer ,
101
+ factory = algorand .client .get_typed_app_factory (
102
+ PerpetualBondFactory , default_sender = arranger .address , default_signer = arranger .signer
101
103
)
102
- return client
103
-
104
-
105
- @pytest .fixture (scope = "function" )
106
- def perpetual_bond_client_empty (
107
- algorand : AlgorandClient ,
108
- arranger : SigningAccount ,
109
- asset_metadata : AssetMetadata ,
110
- perpetual_bond_client_void : PerpetualBondClient ,
111
- ) -> PerpetualBondClient :
112
- perpetual_bond_client_void .create_asset_create (
113
- arranger = arranger .address , metadata = asset_metadata
104
+ client , _ = factory .send .create .asset_create (
105
+ AssetCreateArgs (arranger = arranger .address , metadata = asset_metadata )
114
106
)
115
107
algorand .account .ensure_funded_from_environment (
116
- account_to_fund = perpetual_bond_client_void .app_address ,
108
+ account_to_fund = client .app_address ,
117
109
min_spending_balance = INITIAL_ALGO_FUNDS ,
118
110
)
119
- return perpetual_bond_client_void
111
+ return client
120
112
121
113
122
114
@pytest .fixture (scope = "function" )
@@ -133,13 +125,12 @@ def account_manager(
133
125
min_spending_balance = INITIAL_ALGO_FUNDS ,
134
126
)
135
127
role_config = utils .set_role_config ()
136
- perpetual_bond_client_empty .assign_role (
137
- role_address = account .address ,
138
- role = account .role_id (),
139
- config = role_config ,
140
- transaction_parameters = OnCompleteCallParameters (
141
- boxes = [(perpetual_bond_client_empty .app_id , account .box_id )]
142
- ),
128
+ perpetual_bond_client_empty .send .assign_role (
129
+ AssignRoleArgs (
130
+ role_address = account .address ,
131
+ role = account .role_id (),
132
+ config = role_config ,
133
+ )
143
134
)
144
135
return account
145
136
@@ -158,13 +149,12 @@ def trustee(
158
149
min_spending_balance = INITIAL_ALGO_FUNDS ,
159
150
)
160
151
role_config = utils .set_role_config ()
161
- perpetual_bond_client_empty .assign_role (
162
- role_address = account .address ,
163
- role = account .role_id (),
164
- config = role_config ,
165
- transaction_parameters = OnCompleteCallParameters (
166
- boxes = [(perpetual_bond_client_empty .app_id , account .box_id )]
167
- ),
152
+ perpetual_bond_client_empty .send .assign_role (
153
+ AssignRoleArgs (
154
+ role_address = account .address ,
155
+ role = account .role_id (),
156
+ config = role_config ,
157
+ )
168
158
)
169
159
return account
170
160
@@ -183,13 +173,12 @@ def authority(
183
173
min_spending_balance = INITIAL_ALGO_FUNDS ,
184
174
)
185
175
role_config = utils .set_role_config ()
186
- perpetual_bond_client_empty .assign_role (
187
- role_address = account .address ,
188
- role = account .role_id (),
189
- config = role_config ,
190
- transaction_parameters = OnCompleteCallParameters (
191
- boxes = [(perpetual_bond_client_empty .app_id , account .box_id )]
192
- ),
176
+ perpetual_bond_client_empty .send .assign_role (
177
+ AssignRoleArgs (
178
+ role_address = account .address ,
179
+ role = account .role_id (),
180
+ config = role_config ,
181
+ )
193
182
)
194
183
return account
195
184
@@ -208,13 +197,12 @@ def interest_oracle(
208
197
min_spending_balance = INITIAL_ALGO_FUNDS ,
209
198
)
210
199
role_config = utils .set_role_config ()
211
- perpetual_bond_client_empty .assign_role (
212
- role_address = account .address ,
213
- role = account .role_id (),
214
- config = role_config ,
215
- transaction_parameters = OnCompleteCallParameters (
216
- boxes = [(perpetual_bond_client_empty .app_id , account .box_id )]
217
- ),
200
+ perpetual_bond_client_empty .send .assign_role (
201
+ AssignRoleArgs (
202
+ role_address = account .address ,
203
+ role = account .role_id (),
204
+ config = role_config ,
205
+ )
218
206
)
219
207
return account
220
208
@@ -226,16 +214,8 @@ def perpetual_bond_client_active(
226
214
perpetual_bond_cfg : utils .DAsaConfig ,
227
215
perpetual_bond_client_empty : PerpetualBondClient ,
228
216
) -> PerpetualBondClient :
229
- perpetual_bond_client_empty .asset_config (
230
- ** perpetual_bond_cfg .dictify (),
231
- transaction_parameters = OnCompleteCallParameters (
232
- foreign_assets = [perpetual_bond_cfg .denomination_asset_id ],
233
- boxes = [
234
- (perpetual_bond_client_empty .app_id , sc_cst .BOX_ID_COUPON_RATES ),
235
- (perpetual_bond_client_empty .app_id , sc_cst .BOX_ID_TIME_EVENTS ),
236
- (perpetual_bond_client_empty .app_id , sc_cst .BOX_ID_TIME_PERIODS ),
237
- ],
238
- ),
217
+ perpetual_bond_client_empty .send .asset_config (
218
+ AssetConfigArgs (** perpetual_bond_cfg .dictify ())
239
219
)
240
220
241
221
algorand .send .asset_transfer (
@@ -263,17 +243,16 @@ def primary_dealer(
263
243
account_to_fund = account .address ,
264
244
min_spending_balance = INITIAL_ALGO_FUNDS ,
265
245
)
266
- state = perpetual_bond_client_active .get_global_state ()
246
+ state = perpetual_bond_client_active .state . global_state
267
247
role_config = utils .set_role_config (
268
248
state .primary_distribution_opening_date , state .primary_distribution_closure_date
269
249
)
270
- perpetual_bond_client_active .assign_role (
271
- role_address = account .address ,
272
- role = account .role_id (),
273
- config = role_config ,
274
- transaction_parameters = OnCompleteCallParameters (
275
- boxes = [(perpetual_bond_client_active .app_id , account .box_id )]
276
- ),
250
+ perpetual_bond_client_active .send .assign_role (
251
+ AssignRoleArgs (
252
+ role_address = account .address ,
253
+ role = account .role_id (),
254
+ config = role_config ,
255
+ )
277
256
)
278
257
return account
279
258
@@ -301,19 +280,12 @@ def _factory(perpetual_bond_client: PerpetualBondClient) -> utils.DAsaAccount:
301
280
)
302
281
)
303
282
304
- perpetual_bond_client .open_account (
305
- holding_address = account .address ,
306
- payment_address = account .address ,
307
- transaction_parameters = OnCompleteCallParameters (
308
- signer = account_manager .signer ,
309
- boxes = [
310
- (perpetual_bond_client .app_id , account_manager .box_id ),
311
- (
312
- perpetual_bond_client .app_id ,
313
- utils .DAsaAccount .box_id_from_address (account .address ),
314
- ),
315
- ],
283
+ perpetual_bond_client .send .open_account (
284
+ OpenAccountArgs (
285
+ holding_address = account .address ,
286
+ payment_address = account .address ,
316
287
),
288
+ params = CommonAppCallParams (sender = account_manager .address )
317
289
)
318
290
return utils .DAsaAccount (
319
291
d_asa_client = perpetual_bond_client ,
@@ -328,9 +300,9 @@ def _factory(perpetual_bond_client: PerpetualBondClient) -> utils.DAsaAccount:
328
300
def perpetual_bond_client_primary (
329
301
perpetual_bond_client_active : PerpetualBondClient ,
330
302
) -> PerpetualBondClient :
331
- state = perpetual_bond_client_active .get_global_state ()
332
- perpetual_bond_client_active .set_secondary_time_events (
333
- secondary_market_time_events = [state .issuance_date ],
303
+ state = perpetual_bond_client_active .state . global_state
304
+ perpetual_bond_client_active .send . set_secondary_time_events (
305
+ SetSecondaryTimeEventsArgs ( secondary_market_time_events = [state .issuance_date ]) ,
334
306
)
335
307
utils .time_warp (state .primary_distribution_opening_date )
336
308
return perpetual_bond_client_active
@@ -344,16 +316,12 @@ def account_with_units_factory(
344
316
) -> Callable [..., utils .DAsaAccount ]:
345
317
def _factory (* , units : int = INITIAL_D_ASA_UNITS ) -> utils .DAsaAccount :
346
318
account = account_factory (perpetual_bond_client_primary )
347
- perpetual_bond_client_primary .primary_distribution (
348
- holding_address = account .holding_address ,
349
- units = units ,
350
- transaction_parameters = OnCompleteCallParameters (
351
- signer = primary_dealer .signer ,
352
- boxes = [
353
- (perpetual_bond_client_primary .app_id , primary_dealer .box_id ),
354
- (perpetual_bond_client_primary .app_id , account .box_id ),
355
- ],
319
+ perpetual_bond_client_primary .send .primary_distribution (
320
+ PrimaryDistributionArgs (
321
+ holding_address = account .holding_address ,
322
+ units = units ,
356
323
),
324
+ params = CommonAppCallParams (sender = primary_dealer .address )
357
325
)
358
326
return account
359
327
@@ -379,7 +347,7 @@ def account_with_coupons_factory(
379
347
account_with_units_factory : Callable [..., utils .DAsaAccount ],
380
348
perpetual_bond_client_primary : PerpetualBondClient ,
381
349
) -> Callable [..., utils .DAsaAccount ]:
382
- state = perpetual_bond_client_primary .get_global_state ()
350
+ state = perpetual_bond_client_primary .state . global_state
383
351
384
352
def _factory (
385
353
* , units : int = INITIAL_D_ASA_UNITS , coupons : int = DUE_COUPONS
@@ -388,14 +356,11 @@ def _factory(
388
356
issuance_date = state .issuance_date
389
357
utils .time_warp (issuance_date + COUPON_PERIOD * coupons )
390
358
for _ in range (1 , coupons + 1 ):
391
- perpetual_bond_client_primary .pay_coupon (
392
- holding_address = account .holding_address ,
393
- payment_info = b"" ,
394
- transaction_parameters = OnCompleteCallParameters (
395
- foreign_assets = [state .denomination_asset_id ],
396
- accounts = [account .payment_address ],
397
- boxes = [(perpetual_bond_client_primary .app_id , account .box_id )],
398
- ),
359
+ perpetual_bond_client_primary .send .pay_coupon (
360
+ PayCouponArgs (
361
+ holding_address = account .holding_address ,
362
+ payment_info = b"" ,
363
+ )
399
364
)
400
365
return account
401
366
@@ -406,7 +371,7 @@ def _factory(
406
371
def perpetual_bond_client_ongoing (
407
372
perpetual_bond_client_primary : PerpetualBondClient ,
408
373
) -> PerpetualBondClient :
409
- state = perpetual_bond_client_primary .get_global_state ()
374
+ state = perpetual_bond_client_primary .state . global_state
410
375
utils .time_warp (state .issuance_date )
411
376
return perpetual_bond_client_primary
412
377
@@ -416,12 +381,8 @@ def perpetual_bond_client_suspended(
416
381
authority : utils .DAsaAuthority ,
417
382
perpetual_bond_client_ongoing : PerpetualBondClient ,
418
383
) -> PerpetualBondClient :
419
- perpetual_bond_client_ongoing .set_asset_suspension (
420
- suspended = True ,
421
- transaction_parameters = OnCompleteCallParameters (
422
- signer = authority .signer ,
423
- boxes = [(perpetual_bond_client_ongoing .app_id , authority .box_id )],
424
- ),
384
+ perpetual_bond_client_ongoing .send .set_asset_suspension (
385
+ SetAssetSuspensionArgs (suspended = True )
425
386
)
426
387
return perpetual_bond_client_ongoing
427
388
@@ -430,11 +391,7 @@ def perpetual_bond_client_suspended(
430
391
def perpetual_bond_client_defaulted (
431
392
trustee : utils .DAsaTrustee , perpetual_bond_client_ongoing : PerpetualBondClient
432
393
) -> PerpetualBondClient :
433
- perpetual_bond_client_ongoing .set_default_status (
434
- defaulted = True ,
435
- transaction_parameters = OnCompleteCallParameters (
436
- signer = trustee .signer ,
437
- boxes = [(perpetual_bond_client_ongoing .app_id , trustee .box_id )],
438
- ),
394
+ perpetual_bond_client_ongoing .send .set_default_status (
395
+ SetDefaultStatusArgs (defaulted = True )
439
396
)
440
397
return perpetual_bond_client_ongoing
0 commit comments