forked from DeFiCh/ain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeature_loan_vault.py
executable file
·1089 lines (908 loc) · 49.2 KB
/
feature_loan_vault.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# Copyright (c) 2014-2019 The Bitcoin Core developers
# Copyright (c) DeFi Blockchain Developers
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
"""Test vault."""
from decimal import Decimal
from test_framework.test_framework import DefiTestFramework
from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, assert_raises_rpc_error
import calendar
import time
class VaultTest (DefiTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.setup_clean_chain = True
self.extra_args = [
['-txnotokens=0', '-amkheight=1', '-bayfrontheight=1', '-bayfrontgardensheight=1', '-eunosheight=1', '-txindex=1', '-fortcanningheight=1', '-fortcanninghillheight=300', '-fortcanningcrunchheight=1700', '-jellyfish_regtest=1', '-simulatemainnet'],
['-txnotokens=0', '-amkheight=1', '-bayfrontheight=1', '-bayfrontgardensheight=1', '-eunosheight=1', '-txindex=1', '-fortcanningheight=1', '-fortcanninghillheight=300', '-fortcanningcrunchheight=1700', '-jellyfish_regtest=1', '-simulatemainnet']
]
self.vaults = []
self.owner_addresses = []
self.oracles = []
def move_to_gw_fork(self):
result = self.nodes[0].listcollateraltokens()
assert_equal(result[0]['token'], 'DFI')
assert_equal(result[0]['factor'], Decimal('1.00000000'))
assert_equal(result[0]['fixedIntervalPriceId'], 'DFI/USD')
assert_equal(result[1]['token'], 'BTC')
assert_equal(result[1]['factor'], Decimal('0.80000000'))
assert_equal(result[1]['fixedIntervalPriceId'], 'BTC/USD')
result = self.nodes[0].listloantokens()
assert_equal(result[0]['token']['6']['symbol'], 'TSLA')
assert_equal(result[0]['token']['6']['isLoanToken'], True)
assert_equal(result[0]['fixedIntervalPriceId'], 'TSLA/USD')
assert_equal(result[0]['interest'], Decimal('2.00000000'))
assert_equal(result[1]['token']['7']['symbol'], 'DUSD')
assert_equal(result[1]['token']['7']['isLoanToken'], True)
assert_equal(result[1]['fixedIntervalPriceId'], 'DUSD/USD')
assert_equal(result[1]['interest'], Decimal('1.00000000'))
# Move to hard fork
self.nodes[0].generate(1701 - self.nodes[0].getblockcount())
result = self.nodes[0].getgov('ATTRIBUTES')['ATTRIBUTES']
assert_equal(result['v0/token/0/fixed_interval_price_id'], 'DFI/USD')
assert_equal(result['v0/token/0/loan_collateral_enabled'], 'true')
assert_equal(result['v0/token/0/loan_collateral_factor'], '1')
assert_equal(result['v0/token/1/fixed_interval_price_id'], 'BTC/USD')
assert_equal(result['v0/token/1/loan_collateral_enabled'], 'true')
assert_equal(result['v0/token/1/loan_collateral_factor'], '0.8')
assert_equal(result['v0/token/6/fixed_interval_price_id'], 'TSLA/USD')
assert_equal(result['v0/token/6/loan_minting_enabled'], 'true')
assert_equal(result['v0/token/6/loan_minting_interest'], '2')
assert_equal(result['v0/token/7/fixed_interval_price_id'], 'DUSD/USD')
assert_equal(result['v0/token/7/loan_minting_enabled'], 'true')
assert_equal(result['v0/token/7/loan_minting_interest'], '1')
result = self.nodes[0].listcollateraltokens()
assert_equal(result[0]['token'], 'DFI')
assert_equal(result[0]['factor'], Decimal('1.00000000'))
assert_equal(result[0]['fixedIntervalPriceId'], 'DFI/USD')
assert_equal(result[1]['token'], 'BTC')
assert_equal(result[1]['factor'], Decimal('0.80000000'))
assert_equal(result[1]['fixedIntervalPriceId'], 'BTC/USD')
result = self.nodes[0].listloantokens()
assert_equal(result[0]['token']['6']['symbol'], 'TSLA')
assert_equal(result[0]['token']['6']['isLoanToken'], True)
assert_equal(result[0]['fixedIntervalPriceId'], 'TSLA/USD')
assert_equal(result[0]['interest'], Decimal('2.00000000'))
assert_equal(result[1]['token']['7']['symbol'], 'DUSD')
assert_equal(result[1]['token']['7']['isLoanToken'], True)
assert_equal(result[1]['fixedIntervalPriceId'], 'DUSD/USD')
assert_equal(result[1]['interest'], Decimal('1.00000000'))
def setup_loanschemes(self):
self.nodes[0].createloanscheme(175, 3, 'LOAN0001')
self.nodes[0].createloanscheme(150, 2.5, 'LOAN000A')
self.nodes[0].createloanscheme(200, 2, 'LOAN0002')
self.nodes[0].createloanscheme(350, 1.5, 'LOAN0003')
self.nodes[0].createloanscheme(550, 1.5, 'LOAN0004')
self.nodes[0].generate(1)
self.nodes[0].setdefaultloanscheme('LOAN0001')
self.nodes[0].generate(1)
def create_vaults(self):
owner_addr_0 = self.nodes[0].getnewaddress('', 'legacy')
self.owner_addresses.append(owner_addr_0)
vault_id_0 = self.nodes[0].createvault(owner_addr_0) # default loan scheme
self.vaults.append(vault_id_0)
owner_addr_1 = self.nodes[0].getnewaddress('', 'legacy')
self.owner_addresses.append(owner_addr_1)
vault_id_1 = self.nodes[0].createvault(owner_addr_1, 'LOAN0001')
self.vaults.append(vault_id_1)
vault_id_2 = self.nodes[0].createvault(owner_addr_1, 'LOAN0003')
self.vaults.append(vault_id_2)
vault_id_3 = self.nodes[0].createvault(owner_addr_1, 'LOAN0003')
self.vaults.append(vault_id_3)
self.nodes[0].generate(1)
def setup_accounts_and_tokens(self):
assert_equal(len(self.nodes[0].listtokens()), 1) # only one token == DFI
self.nodes[0].generate(25)
self.sync_blocks()
self.nodes[1].generate(102)
self.sync_blocks()
self.symbolDFI = "DFI"
self.symbolBTC = "BTC"
self.symbolETH = "ETH"
self.symbolGOOGL = "GOOGL"
self.symbolUSDT = "USDT"
self.symbolAAPL = "AAPL"
self.nodes[1].createtoken({
"symbol": self.symbolBTC,
"name": "BTC token",
"isDAT": True,
"collateralAddress": self.nodes[1].get_genesis_keys().ownerAuthAddress
})
self.nodes[1].generate(1)
self.sync_blocks()
self.nodes[0].createtoken({
"symbol": self.symbolETH,
"name": "Ethereum",
"isDAT": True,
"collateralAddress": self.nodes[0].get_genesis_keys().ownerAuthAddress
})
self.nodes[0].generate(1)
self.nodes[0].createtoken({
"symbol": self.symbolGOOGL,
"name": "Google",
"isDAT": True,
"collateralAddress": self.nodes[0].get_genesis_keys().ownerAuthAddress
})
self.nodes[0].generate(1)
self.nodes[0].createtoken({
"symbol": self.symbolUSDT,
"name": "USDT Stable Coin",
"isDAT": True,
"collateralAddress": self.nodes[0].get_genesis_keys().ownerAuthAddress
})
self.nodes[0].generate(1)
self.nodes[0].createtoken({
"symbol": self.symbolAAPL,
"name": "Apple",
"isDAT": True,
"collateralAddress": self.nodes[0].get_genesis_keys().ownerAuthAddress
})
self.nodes[0].generate(1)
self.sync_blocks()
self.nodes[1].minttokens("10@" + self.symbolBTC)
self.nodes[1].generate(1)
self.sync_blocks()
self.idDFI = list(self.nodes[0].gettoken(self.symbolDFI).keys())[0]
self.idBTC = list(self.nodes[0].gettoken(self.symbolBTC).keys())[0]
self.idETH = list(self.nodes[0].gettoken(self.symbolETH).keys())[0]
self.idGOOGL = list(self.nodes[0].gettoken(self.symbolGOOGL).keys())[0]
self.idUSDT = list(self.nodes[0].gettoken(self.symbolUSDT).keys())[0]
self.idAAPL = list(self.nodes[0].gettoken(self.symbolAAPL).keys())[0]
self.accountDFI = self.nodes[0].get_genesis_keys().ownerAuthAddress
self.accountBTC = self.nodes[1].get_genesis_keys().ownerAuthAddress
self.nodes[0].utxostoaccount({self.accountDFI: "100@" + self.symbolDFI})
self.nodes[0].generate(1)
self.nodes[0].setloantoken({
'symbol': "TSLA",
'name': "Tesla Token",
'fixedIntervalPriceId': "TSLA/USD",
'mintable': True,
'interest': 2})
self.nodes[0].generate(1)
self.nodes[0].setcollateraltoken({
'token': self.idDFI,
'factor': 1,
'fixedIntervalPriceId': "DFI/USD"})
self.nodes[0].setcollateraltoken({
'token': self.idBTC,
'factor': 0.8,
'fixedIntervalPriceId': "BTC/USD"})
self.nodes[0].generate(120)
self.sync_blocks()
self.nodes[0].setloantoken({
'symbol': "DUSD",
'name': "DUSD stable token",
'fixedIntervalPriceId': "DUSD/USD",
'mintable': True,
'interest': 1})
self.nodes[0].generate(120)
def setup_oracles(self):
oracle_address1 = self.nodes[0].getnewaddress("", "legacy")
price_feeds1 = [{"currency": "USD", "token": "DFI"}, {"currency": "USD", "token": "BTC"}, {"currency": "USD", "token": "TSLA"}, {"currency": "USD", "token": "GOOGL"}, {"currency": "USD", "token": "ETH"}]
oracle_id1 = self.nodes[0].appointoracle(oracle_address1, price_feeds1, 10)
self.oracles.append(oracle_id1)
self.nodes[0].generate(1)
oracle1_prices = [{"currency": "USD", "tokenAmount": "1@DFI"}, {"currency": "USD", "tokenAmount": "1@BTC"}, {"currency": "USD", "tokenAmount": "1@TSLA"}]
timestamp = calendar.timegm(time.gmtime())
self.nodes[0].setoracledata(oracle_id1, timestamp, oracle1_prices)
self.nodes[0].generate(116)
def create_poolpairs(self):
poolOwner = self.nodes[0].getnewaddress("", "legacy")
self.nodes[0].createpoolpair({
"tokenA": "DUSD",
"tokenB": self.idDFI,
"commission": Decimal('0.002'),
"status": True,
"ownerAddress": poolOwner,
"pairSymbol": "DUSD-DFI",
}, [])
self.nodes[0].generate(1)
self.nodes[0].minttokens("300@DUSD")
self.nodes[0].generate(1)
self.nodes[0].utxostoaccount({self.accountDFI: "100@" + self.symbolDFI})
self.nodes[0].generate(1)
self.nodes[0].addpoolliquidity({
self.accountDFI: ["300@DUSD", "100@" + self.symbolDFI]
}, self.accountDFI, [])
self.nodes[0].generate(1)
self.nodes[0].createpoolpair({
"tokenA": "DUSD",
"tokenB": "TSLA",
"commission": Decimal('0.002'),
"status": True,
"ownerAddress": poolOwner,
"pairSymbol": "DUSD-TSLA",
}, [])
self.nodes[0].generate(1)
self.nodes[0].minttokens("100@TSLA")
self.nodes[0].generate(1)
self.nodes[0].minttokens("100@DUSD")
self.nodes[0].generate(1)
self.nodes[0].addpoolliquidity({
self.accountDFI: ["100@TSLA", "100@DUSD"]
}, self.accountDFI, [])
self.nodes[0].generate(1)
def setup(self):
self.nodes[0].generate(120)
self.setup_loanschemes()
self.create_vaults()
self.setup_oracles()
self.setup_accounts_and_tokens()
self.create_poolpairs()
def createvault_with_invalid_parameters(self):
try:
self.nodes[0].createvault('ffffffffff')
except JSONRPCException as e:
errorString = e.error['message']
assert('recipient script (ffffffffff) does not solvable/non-standard' in errorString)
# Create vault with invalid loanschemeid and default owner address
owner = self.nodes[0].getnewaddress('', 'legacy')
try:
self.nodes[0].createvault(owner, 'FAKELOAN')
except JSONRPCException as e:
errorString = e.error['message']
assert('Cannot find existing loan scheme with id FAKELOAN' in errorString)
def listvaults_and_filtering(self):
# check listvaults
list_vault = self.nodes[0].listvaults()
assert_equal(len(list_vault), 4)
# Filetering
# by owner_address
list_vault = self.nodes[0].listvaults({ "ownerAddress": self.owner_addresses[1] })
assert_equal(len(list_vault), 3)
for vault in list_vault:
assert_equal(vault["ownerAddress"], self.owner_addresses[1])
# by loanSchemeId
list_vault = self.nodes[0].listvaults({ "loanSchemeId": "LOAN0003" })
assert_equal(len(list_vault), 2)
for vault in list_vault:
assert_equal(vault["loanSchemeId"], "LOAN0003")
# Pagination
# limit
list_vault = self.nodes[0].listvaults({}, {"limit": 1})
assert_equal(len(list_vault), 1)
# including_include_start
list_vault_include_start = self.nodes[0].listvaults({}, {"limit": 1, "including_start": False})
assert_equal(len(list_vault_include_start), 1)
assert(list_vault[0]['vaultId'] != list_vault_include_start[0]['vaultId'])
startId = list_vault[0]['vaultId']
# start
list_vault_start = self.nodes[0].listvaults({}, {"start": startId})
assert_equal(len(list_vault_start), 3)
# start & include_start
list_vault_start = self.nodes[0].listvaults({}, {"start": startId, "including_start": True})
assert_equal(len(list_vault_start), 4)
def test_feeburn(self):
assert_equal(self.nodes[0].getburninfo()['feeburn'], Decimal('7'))
def getvault_wrong_vault_address(self):
try:
self.nodes[0].getvault('5474b2e9bfa96446e5ef3c9594634e1aa22d3a0722cb79084d61253acbdf87bf')
except JSONRPCException as e:
errorString = e.error['message']
assert('Vault <5474b2e9bfa96446e5ef3c9594634e1aa22d3a0722cb79084d61253acbdf87bf> not found' in errorString)
def test_getvault(self):
vault = self.nodes[0].getvault(self.vaults[0])
assert_equal(vault["loanSchemeId"], 'LOAN0001')
assert_equal(vault["ownerAddress"], self.owner_addresses[0])
assert_equal(vault["state"], "active")
assert_equal(vault["collateralAmounts"], [])
assert_equal(vault["loanAmounts"], [])
assert_equal(vault["collateralValue"], Decimal(0))
assert_equal(vault["loanValue"], Decimal(0))
assert_equal(vault["informativeRatio"], Decimal('-1.00000000'))
def updatevault_with_invalid_parameters(self):
try:
params = {}
self.nodes[0].updatevault(self.vaults[0], params)
except JSONRPCException as e:
errorString = e.error['message']
assert("At least ownerAddress OR loanSchemeId must be set" in errorString)
# bad loan scheme id
try:
params = {'loanSchemeId': 'FAKELOAN'}
self.nodes[0].updatevault(self.vaults[0], params)
except JSONRPCException as e:
errorString = e.error['message']
assert("Cannot find existing loan scheme with id FAKELOAN" in errorString)
# bad owner address
try:
params = {'ownerAddress': 'ffffffffff'}
self.nodes[0].updatevault(self.vaults[0], params)
except JSONRPCException as e:
errorString = e.error['message']
assert("Error: Invalid owner address" in errorString)
def actions_on_vault_with_scheme_to_be_destroyed(self):
# Create or update vault with loan scheme planned to be destroyed
destruction_height = self.nodes[0].getblockcount() + 3
self.nodes[0].destroyloanscheme('LOAN0002', destruction_height)
self.nodes[0].generate(1)
# create
assert_raises_rpc_error(-32600, 'Cannot set LOAN0002 as loan scheme, set to be destroyed on block 626', self.nodes[0].createvault, self.owner_addresses[0], 'LOAN0002')
# update
assert_raises_rpc_error(-32600, 'Cannot set LOAN0002 as loan scheme, set to be destroyed on block 626', self.nodes[0].updatevault, self.vaults[1], {'loanSchemeId':'LOAN0002'})
def update_vault_scheme(self):
new_address = self.nodes[0].getnewaddress('', 'legacy')
params = {'loanSchemeId': 'LOAN0001', 'ownerAddress': new_address}
self.nodes[0].updatevault(self.vaults[1], params)
self.nodes[0].generate(1)
vault = self.nodes[0].getvault(self.vaults[1])
assert_equal(vault['ownerAddress'], new_address)
assert_equal(vault['loanSchemeId'], 'LOAN0001')
# update global list after update
self.owner_addresses[1] = new_address
def automatic_update_after_loanscheme_delete(self):
# update with non-default loan scheme and delete loan to check automatic update
params = {'loanSchemeId': 'LOAN0003'}
self.nodes[0].updatevault(self.vaults[1], params)
self.nodes[0].generate(1)
vault = self.nodes[0].getvault(self.vaults[1])
assert_equal(vault['loanSchemeId'], 'LOAN0003')
self.nodes[0].destroyloanscheme('LOAN0003')
self.nodes[0].generate(1)
vault = self.nodes[0].getvault(self.vaults[1])
assert_equal(vault['loanSchemeId'], 'LOAN0001')
def automatic_update_after_loanscheme_delete_with_delay(self):
# back to non-default loan scheme and delete scheme with delay
params = {'loanSchemeId': 'LOAN0004'}
self.nodes[0].updatevault(self.vaults[1], params)
self.nodes[0].generate(1)
vault = self.nodes[0].getvault(self.vaults[1])
assert_equal(vault['loanSchemeId'], 'LOAN0004')
destruction_height = self.nodes[0].getblockcount() + 2
self.nodes[0].destroyloanscheme('LOAN0004', destruction_height)
self.nodes[0].generate(1)
vault = self.nodes[0].getvault(self.vaults[1])
assert_equal(vault['loanSchemeId'], 'LOAN0004')
# now LOAN0002 is deleted in next block
self.nodes[0].generate(1)
vault = self.nodes[0].getvault(self.vaults[1])
assert_equal(vault['loanSchemeId'], 'LOAN0001')
def deposittovault_with_invalid_params(self):
# Insufficient funds
try:
self.nodes[0].deposittovault(self.vaults[0], self.accountDFI, '101@DFI')
except JSONRPCException as e:
errorString = e.error['message']
assert("Insufficient funds" in errorString)
# Check from auth
try:
self.nodes[0].deposittovault(self.vaults[0], self.accountBTC, '1@DFI')
except JSONRPCException as e:
errorString = e.error['message']
assert("Incorrect authorization for {}".format(self.accountBTC) in errorString)
# Check negative amount
try:
self.nodes[0].deposittovault(self.vaults[0], self.accountDFI, '-1@DFI')
except JSONRPCException as e:
errorString = e.error['message']
assert("Amount out of range" in errorString)
# Check too small amount
try:
self.nodes[0].deposittovault(self.vaults[0], self.accountDFI, '0.000000001@DFI')
except JSONRPCException as e:
errorString = e.error['message']
assert("Invalid amount" in errorString)
def test_deposittovault(self):
# Check deposit 1 satoshi
self.nodes[0].deposittovault(self.vaults[0], self.accountDFI, '0.00000001@DFI')
self.nodes[0].generate(1)
self.nodes[0].withdrawfromvault(self.vaults[0], self.accountDFI, "0.00000001@DFI")
self.nodes[0].generate(1)
self.nodes[1].deposittovault(self.vaults[0], self.accountBTC, '0.7@BTC')
self.nodes[1].generate(1)
self.sync_blocks()
vault = self.nodes[1].getvault(self.vaults[0])
assert_equal(vault['collateralAmounts'], ['0.70000000@BTC'])
acBTC = self.nodes[1].getaccount(self.accountBTC)
assert_equal(acBTC, ['9.30000000@BTC'])
def takeloan_breaking_50pctDFI_rule(self):
try:
self.nodes[0].takeloan({
'vaultId': self.vaults[0],
'amounts': "0.1@TSLA"})
except JSONRPCException as e:
error_str = e.error['message']
assert("At least 50% of the minimum required collateral must be in DFI when taking a loan" in error_str)
def takeloan_with_50pctDFI(self):
self.nodes[0].deposittovault(self.vaults[0], self.accountDFI, '0.7@DFI')
self.nodes[0].generate(1)
self.sync_blocks()
vault = self.nodes[1].getvault(self.vaults[0])
assert_equal(vault['collateralAmounts'], ['0.70000000@DFI', '0.70000000@BTC'])
acDFI = self.nodes[0].getaccount(self.accountDFI)
assert_equal(acDFI, ['99.30000000@DFI', '173.20507075@DUSD-DFI', '99.99999000@DUSD-TSLA'])
self.nodes[0].deposittovault(self.vaults[0], self.accountDFI, '0.3@DFI')
self.nodes[0].generate(1)
self.sync_blocks()
self.nodes[1].deposittovault(self.vaults[0], self.accountBTC, '0.3@BTC')
self.nodes[1].generate(1)
self.sync_blocks()
vault = self.nodes[1].getvault(self.vaults[0])
assert_equal(vault['collateralAmounts'],['1.00000000@DFI', '1.00000000@BTC'])
acBTC = self.nodes[1].getaccount(self.accountBTC)
assert_equal(acBTC, ['9.00000000@BTC'])
acDFI = self.nodes[0].getaccount(self.accountDFI)
assert_equal(acDFI, ['99.00000000@DFI', '173.20507075@DUSD-DFI', '99.99999000@DUSD-TSLA'])
oracle1_prices = [{"currency": "USD", "tokenAmount": "1@DFI"}, {"currency": "USD", "tokenAmount": "1@TSLA"}, {"currency": "USD", "tokenAmount": "1@BTC"}]
timestamp = calendar.timegm(time.gmtime())
self.nodes[0].setoracledata(self.oracles[0], timestamp, oracle1_prices)
self.nodes[0].generate(1)
self.sync_blocks()
self.nodes[0].takeloan({
'vaultId': self.vaults[0],
'amounts': "0.5@TSLA"})
self.nodes[0].generate(1)
self.sync_blocks()
interest = self.nodes[0].getinterest('LOAN0001')[0]
assert_equal(interest['interestPerBlock'], Decimal('3E-8'))
vault = self.nodes[0].getvault(self.vaults[0])
assert_equal(vault['loanAmounts'], ['0.50000003@TSLA'])
assert_equal(vault['collateralValue'], Decimal('1.80000000'))
assert_equal(vault['loanValue'],Decimal('0.50000003'))
assert_equal(vault['interestValue'],Decimal('0.00000003'))
assert_equal(vault['interestAmounts'],['0.00000003@TSLA'])
def withdraw_breaking_50pctDFI_rule(self):
try:
self.nodes[0].withdrawfromvault(self.vaults[0], self.accountDFI, "0.8@DFI")
except JSONRPCException as e:
error_str = e.error['message']
assert("At least 50% of the minimum required collateral must be in DFI" in error_str)
def move_interest_from_old_scheme(self):
params = {'loanSchemeId':'LOAN000A'}
self.nodes[0].updatevault(self.vaults[0], params)
self.nodes[0].generate(1)
self.sync_blocks()
# interest is moved out from old scheme
interest = self.nodes[0].getinterest('LOAN0001')
assert_equal(len(interest), 0)
def vault_enter_liquidation_updating_oracle(self):
oracle_prices = [{"currency": "USD", "tokenAmount": "4@TSLA"}]
timestamp = calendar.timegm(time.gmtime())
self.nodes[0].setoracledata(self.oracles[0], timestamp, oracle_prices)
self.nodes[0].generate(240)
self.sync_blocks()
vault = self.nodes[0].getvault(self.vaults[0])
assert_equal(vault['state'], "inLiquidation")
assert_equal(vault['liquidationHeight'], 1560)
assert_equal(vault['liquidationPenalty'], Decimal('5.00000000'))
assert_equal(vault['batchCount'], 1)
assert_raises_rpc_error(-26, 'Vault is under liquidation', self.nodes[0].closevault, self.vaults[0], self.owner_addresses[0])
def listvaults_state_filtering(self):
# check listvaults
list_vault = self.nodes[0].listvaults()
assert_equal(len(list_vault), 4)
list_vault = self.nodes[0].listvaults({"state": "active"})
assert_equal(len(list_vault), 3)
list_vault = self.nodes[0].listvaults({"state": "inLiquidation"})
assert_equal(len(list_vault), 1)
def updatevault_to_scheme_with_lower_collateralization_ratio(self):
self.nodes[0].deposittovault(self.vaults[1], self.accountDFI, '2.5@DFI')
self.nodes[0].generate(1)
self.sync_blocks()
vault = self.nodes[0].getvault(self.vaults[1])
assert_equal(vault['collateralAmounts'], ['2.50000000@DFI'])
assert_equal(self.nodes[0].getaccount(self.owner_addresses[1]), [])
self.nodes[0].takeloan({
'vaultId': self.vaults[1],
'amounts': "0.355@TSLA"})
self.nodes[0].generate(1)
vault = self.nodes[0].getvault(self.vaults[1])
self.nodes[0].createloanscheme(200, 2.5, 'LOAN0005')
self.nodes[0].generate(1)
vault = self.nodes[0].getvault(self.vaults[1])
params = {'loanSchemeId': 'LOAN0005'}
try:
self.nodes[0].updatevault(self.vaults[1], params)
except JSONRPCException as e:
errorString = e.error['message']
assert("Vault does not have enough collateralization ratio defined by loan scheme - 176 < 200" in errorString)
self.nodes[0].generate(1)
def closevault_with_active_loans(self):
try:
self.nodes[0].closevault(self.vaults[1], self.owner_addresses[1])
except JSONRPCException as e:
error_str = e.error['message']
assert("Vault <"+self.vaults[1]+"> has loans" in error_str)
self.nodes[0].generate(1)
def test_closevault(self):
list_vault = self.nodes[1].listvaults()
assert_equal(len(list_vault), 4)
self.nodes[0].closevault(self.vaults[3], self.owner_addresses[1])
self.nodes[0].generate(1)
list_vault = self.nodes[1].listvaults()
assert_equal(len(list_vault), 3)
try:
self.nodes[1].getvault(self.vaults[3])
except JSONRPCException as e:
error_str = e.error['message']
assert("Vault <"+self.vaults[3]+"> not found" in error_str)
def estimatevault_with_invalid_params(self):
# Invalid loan token
try:
self.nodes[0].estimatevault('3.00000000@DFI', '3.00000000@TSLAA')
except JSONRPCException as e:
error_str = e.error['message']
assert("Invalid Defi token: TSLAA" in error_str)
# Invalid collateral token
try:
self.nodes[0].estimatevault('3.00000000@DFII', '3.00000000@TSLA')
except JSONRPCException as e:
error_str = e.error['message']
assert("Invalid Defi token: DFII" in error_str)
# Token not set as a collateral
try:
self.nodes[0].estimatevault('3.00000000@TSLA', '3.00000000@TSLA')
except JSONRPCException as e:
error_str = e.error['message']
assert("Token with id (6) is not a valid collateral!" in error_str)
# Token not set as loan token
try:
self.nodes[0].estimatevault('3.00000000@DFI', '3.00000000@DFI')
except JSONRPCException as e:
error_str = e.error['message']
assert("Token with id (0) is not a loan token!" in error_str)
def test_estimatevault(self):
vault = self.nodes[0].getvault(self.vaults[1])
estimatevault = self.nodes[0].estimatevault(vault["collateralAmounts"], vault["loanAmounts"])
assert_equal(estimatevault["collateralValue"], vault["collateralValue"])
assert_equal(estimatevault["loanValue"], vault["loanValue"])
assert_equal(estimatevault["informativeRatio"], vault["informativeRatio"])
assert_equal(estimatevault["collateralRatio"], vault["collateralRatio"])
def test_50pctDFI_fresh_vault_takeloan_withdraw(self):
# Reset price
oracle_prices = [{"currency": "USD", "tokenAmount": "1@DFI"}, {"currency": "USD", "tokenAmount": "1@TSLA"}, {"currency": "USD", "tokenAmount": "1@BTC"}]
timestamp = calendar.timegm(time.gmtime())
self.nodes[0].setoracledata(self.oracles[0], timestamp, oracle_prices)
self.nodes[0].generate(240)
# Deposit collaterals. 50% of BTC
address = self.nodes[0].getnewaddress()
self.nodes[0].generate(1)
self.sync_blocks()
self.owner_addresses.append(address)
self.nodes[1].sendtokenstoaddress({}, { address: '1.50@BTC'})
self.nodes[1].generate(1)
self.sync_blocks()
vault_id = self.nodes[0].createvault(address, 'LOAN000A')
self.vaults.append(vault_id)
self.nodes[0].generate(1)
self.sync_blocks()
self.nodes[0].deposittovault(vault_id, address, '1.25@BTC') # 1.25@BTC as collateral factor 0.8
self.nodes[0].deposittovault(vault_id, self.accountDFI, '1@DFI')
self.nodes[0].generate(1)
self.sync_blocks()
self.nodes[0].takeloan({
'vaultId': vault_id,
'amounts': "1@TSLA"
})
self.nodes[0].generate(1)
self.nodes[0].deposittovault(vault_id, address, '0.2@BTC')
self.nodes[0].generate(1)
# Should be able to withdraw extra BTC
account = self.nodes[0].getaccount(address)
assert_equal(account, ['0.05000000@BTC', '1.00000000@TSLA'])
# try withdraw negative amount
try:
self.nodes[0].withdrawfromvault(vault_id, address, "-0.00000001@BTC")
except JSONRPCException as e:
error_str = e.error['message']
assert("Amount out of range" in error_str)
# try withdraw too small amount
try:
self.nodes[0].withdrawfromvault(vault_id, address, "0.000000001@BTC")
except JSONRPCException as e:
error_str = e.error['message']
assert("Invalid amount" in error_str)
# try withdraw 1 satoshi
self.nodes[0].withdrawfromvault(vault_id, address, "0.00000001@BTC")
self.nodes[0].withdrawfromvault(vault_id, address, "0.09999999@BTC")
self.nodes[0].generate(1)
account = self.nodes[0].getaccount(address)
assert_equal(account, ['0.15000000@BTC', '1.00000000@TSLA'])
def test_50pctDFI_rule_after_BTC_price_increase(self):
# BTC triplicates in price
oracle_prices = [{"currency": "USD", "tokenAmount": "1@DFI"}, {"currency": "USD", "tokenAmount": "1@TSLA"}, {"currency": "USD", "tokenAmount": "3@BTC"}]
timestamp = calendar.timegm(time.gmtime())
self.nodes[0].setoracledata(self.oracles[0], timestamp, oracle_prices)
self.nodes[0].generate(240)
# Should be able to withdraw part of BTC after BTC appreciation in price
self.nodes[0].withdrawfromvault(self.vaults[4], self.owner_addresses[2], "0.5@BTC")
self.nodes[0].generate(1)
# Should not be able to withdraw if DFI lower than 50% of collateralized loan value
try:
self.nodes[0].withdrawfromvault(self.vaults[4], self.accountDFI, "0.25@DFI")
except JSONRPCException as e:
errorString = e.error['message']
assert("At least 50% of the minimum required collateral must be in DFI" in errorString)
# Should be able to take 0.10@TSLA and respect 50% DFI ratio
self.nodes[0].takeloan({
'vaultId': self.vaults[4],
'amounts': "0.10@TSLA"
})
self.nodes[0].generate(1)
def overflowed_collateral_value(self):
address = self.owner_addresses[2]
vault_id = self.nodes[0].createvault(address, 'LOAN000A')
self.nodes[0].generate(1)
self.nodes[0].utxostoaccount({self.accountDFI: "100000000@" + self.symbolDFI})
self.nodes[0].generate(1)
self.nodes[0].deposittovault(vault_id, self.accountDFI, "100000000@" + self.symbolDFI)
self.nodes[0].generate(1)
self.nodes[0].takeloan({
'vaultId': vault_id,
'amounts': "0.5@TSLA"
})
self.nodes[0].generate(1)
oracle1_prices = [{"currency": "USD", "tokenAmount": "9999999999@DFI"}, {"currency": "USD", "tokenAmount": "1@TSLA"}, {"currency": "USD", "tokenAmount": "1@BTC"}, {"currency": "USD", "tokenAmount": "1@ETH"}, {"currency": "USD", "tokenAmount": "2@GOOGL"}]
timestamp = calendar.timegm(time.gmtime())
self.nodes[0].setoracledata(self.oracles[0], timestamp, oracle1_prices)
self.nodes[0].generate(240)
vault = self.nodes[0].getvault(vault_id)
assert_equal(vault['collateralValue'], 0) # collateral value overflowed
# Actions on vault should be blocked
assert_raises_rpc_error(-32600, 'Value/price too high', self.nodes[0].takeloan, {'vaultId': vault_id,'amounts': "0.5@TSLA"})
assert_raises_rpc_error(-32600, 'Value/price too high', self.nodes[0].deposittovault, vault_id, self.accountDFI, "1@" + self.symbolDFI)
assert_raises_rpc_error(-32600, 'Value/price too high', self.nodes[0].withdrawfromvault, vault_id, address, "1@DFI")
# Should be able to close vault
self.nodes[0].paybackloan({'vaultId': vault_id, 'from': address, 'amounts': ["1@TSLA"]})
self.nodes[0].generate(1)
self.nodes[0].closevault(vault_id, address)
self.nodes[0].generate(1)
def close_vault_check_burninfo_and_owner_close_fee_payback(self):
self.sync_blocks()
# Save burninfo and balances before create vault
balance1Before = self.nodes[1].getbalance()
burninfoBefore = self.nodes[1].getburninfo()
# Create vault
owner1 = self.nodes[1].getnewaddress()
vaultId = self.nodes[1].createvault(owner1)
self.nodes[1].generate(1)
# Save burninfo and balances after create vault
burninfoAfterCreate = self.nodes[1].getburninfo()
balance1AfterCreate = self.nodes[1].getbalance()
# Close vault
self.nodes[1].closevault(vaultId, owner1)
self.nodes[1].generate(1)
# Save burninfo and balances after close vault
account1AfterClose = self.nodes[1].getaccount(owner1)[0]
burninfoAfterClose = self.nodes[1].getburninfo()
# checks
assert_equal(balance1Before-balance1AfterCreate, Decimal('1.00004640')) # ~1 UTXO charged on createvault
assert_equal(burninfoBefore['feeburn']-burninfoAfterCreate['feeburn'], Decimal('-0.50000000')) # 0.5 DFI burned on createvault
assert_equal(account1AfterClose, '0.50000000@DFI') # 0.5 DFI returned to owner
assert_equal(burninfoAfterClose['feeburn'], burninfoAfterCreate['feeburn']) # No more DFI is burned on close vault
def close_vault_after_update_owner_check_close_fee_payback(self):
self.sync_blocks()
owner1 = self.nodes[1].getnewaddress()
owner2 = self.nodes[0].getnewaddress()
# Save burninfo and balances before create vault
balance1Before = self.nodes[1].getbalance()
# Create vault
vaultId = self.nodes[1].createvault(owner1)
self.nodes[1].generate(1)
# Save burninfo and balances after create vault
balance1AfterCreate = self.nodes[1].getbalance()
# Update vault to owner2
self.nodes[1].updatevault(vaultId, {"ownerAddress": owner2})
self.nodes[1].generate(1)
self.sync_blocks()
vault = self.nodes[0].getvault(vaultId)
assert_equal(owner2, vault['ownerAddress'])
# Close vault without auth
try:
self.nodes[1].closevault(vaultId, owner1)
except JSONRPCException as e:
errorString = e.error['message']
assert('Incorrect authorization for' in errorString)
self.nodes[0].closevault(vaultId, owner1)
self.nodes[0].generate(1)
self.sync_blocks()
# Save burninfo and balances after close vault
account1AfterClose = self.nodes[1].getaccount(owner1)
account2AfterClose = self.nodes[1].getaccount(owner2)
# checks
assert_equal(balance1Before-balance1AfterCreate, Decimal('1.00003540')) # ~1 UTXO charged on createvault
assert_equal(account1AfterClose, ['0.50000000@DFI']) # 0.5 DFI returned to owner1
assert_equal([], account2AfterClose) # close vault called with owner1
def loan_and_collateral_token_to_govvar(self):
# Move to hard fork
self.move_to_gw_fork()
# Invalidate fork block
self.nodes[0].invalidateblock(self.nodes[0].getblockhash(self.nodes[0].getblockcount()))
assert_equal(len(self.nodes[0].getgov('ATTRIBUTES')['ATTRIBUTES']), 0)
# Move to hard fork again
self.move_to_gw_fork()
# Test setting collateral token partially
self.nodes[0].setgov({"ATTRIBUTES":{f'v0/token/{self.idETH}/fixed_interval_price_id':'ETH/USD', f'v0/token/{self.idETH}/loan_collateral_enabled':'true'}})
self.nodes[0].generate(1)
# Should not show up as collateral token
assert_equal(len(self.nodes[0].listcollateraltokens()), 2)
# Revert
self.nodes[0].invalidateblock(self.nodes[0].getblockhash(self.nodes[0].getblockcount()))
self.nodes[0].clearmempool()
# Test setting collateral token partially
self.nodes[0].setgov({"ATTRIBUTES":{f'v0/token/{self.idETH}/fixed_interval_price_id':'ETH/USD', f'v0/token/{self.idETH}/loan_collateral_factor':'0.5'}})
self.nodes[0].generate(1)
# Should not show up as collateral token
assert_equal(len(self.nodes[0].listcollateraltokens()), 2)
# Revert
self.nodes[0].invalidateblock(self.nodes[0].getblockhash(self.nodes[0].getblockcount()))
self.nodes[0].clearmempool()
# Set collateral token
self.nodes[0].setgov({"ATTRIBUTES":{f'v0/token/{self.idETH}/fixed_interval_price_id':'ETH/USD', f'v0/token/{self.idETH}/loan_collateral_enabled':'true', f'v0/token/{self.idETH}/loan_collateral_factor':'0.5'}})
self.nodes[0].generate(1)
# Test setting it again, should not be a problem.
self.nodes[0].setgov({"ATTRIBUTES":{f'v0/token/{self.idETH}/fixed_interval_price_id':'ETH/USD', f'v0/token/{self.idETH}/loan_collateral_enabled':'true', f'v0/token/{self.idETH}/loan_collateral_factor':'0.5'}})
self.nodes[0].generate(1)
# Should now show up as collateral token
result = self.nodes[0].listcollateraltokens()
assert_equal(len(result), 3)
assert_equal(result[2]['token'], 'ETH')
assert_equal(result[2]['factor'], Decimal('0.50000000'))
assert_equal(result[2]['fixedIntervalPriceId'], 'ETH/USD')
# Should not show up as loan token yet
assert_equal(self.nodes[0].gettoken(self.idGOOGL)[self.idGOOGL]['isLoanToken'], False)
# Test setting loan token partially.
self.nodes[0].setgov({"ATTRIBUTES":{f'v0/token/{self.idGOOGL}/fixed_interval_price_id':'GOOGL/USD', f'v0/token/{self.idGOOGL}/loan_minting_enabled':'true'}})
self.nodes[0].generate(1)
# Should not show up as loan token
assert_equal(self.nodes[0].gettoken(self.idGOOGL)[self.idGOOGL]['isLoanToken'], False)
assert_equal(len(self.nodes[0].listloantokens()), 2)
# Revert
self.nodes[0].invalidateblock(self.nodes[0].getblockhash(self.nodes[0].getblockcount()))
self.nodes[0].clearmempool()
# Test setting loan token partially.
self.nodes[0].setgov({"ATTRIBUTES":{f'v0/token/{self.idGOOGL}/fixed_interval_price_id':'GOOGL/USD', f'v0/token/{self.idGOOGL}/loan_minting_interest':'1'}})
self.nodes[0].generate(1)
# Should not show up as loan token
assert_equal(self.nodes[0].gettoken(self.idGOOGL)[self.idGOOGL]['isLoanToken'], False)
assert_equal(len(self.nodes[0].listloantokens()), 2)
# Revert
self.nodes[0].invalidateblock(self.nodes[0].getblockhash(self.nodes[0].getblockcount()))
self.nodes[0].clearmempool()
# Set loan token
self.nodes[0].setgov({"ATTRIBUTES":{f'v0/token/{self.idGOOGL}/fixed_interval_price_id':'GOOGL/USD', f'v0/token/{self.idGOOGL}/loan_minting_enabled':'true', f'v0/token/{self.idGOOGL}/loan_minting_interest':'1'}})
self.nodes[0].generate(1)
# Test setting it again, should not be a problem.
self.nodes[0].setgov({"ATTRIBUTES":{f'v0/token/{self.idGOOGL}/fixed_interval_price_id':'GOOGL/USD', f'v0/token/{self.idGOOGL}/loan_minting_enabled':'true', f'v0/token/{self.idGOOGL}/loan_minting_interest':'1'}})
self.nodes[0].generate(1)
# Should now show up as loan token
assert_equal(self.nodes[0].gettoken(self.idGOOGL)[self.idGOOGL]['isLoanToken'], True)
result = self.nodes[0].listloantokens()
assert_equal(len(result), 3)
assert_equal(result[0]['token'][str(self.idGOOGL)]['symbol'], 'GOOGL')
assert_equal(result[0]['token'][str(self.idGOOGL)]['isLoanToken'], True)
assert_equal(result[0]['fixedIntervalPriceId'], 'GOOGL/USD')
assert_equal(result[0]['interest'], Decimal('1.00000000'))
# Set oracle price
oracle_prices = [{"currency": "USD", "tokenAmount": "1@DFI"}, {"currency": "USD", "tokenAmount": "1@TSLA"}, {"currency": "USD", "tokenAmount": "0.5@BTC"}, {"currency": "USD", "tokenAmount": "1@ETH"}, {"currency": "USD", "tokenAmount": "2@GOOGL"}]
timestamp = calendar.timegm(time.gmtime())
self.nodes[0].setoracledata(self.oracles[0], timestamp, oracle_prices)
self.nodes[0].generate(240)
# Create new vault
ownerAddress3 = self.nodes[0].getnewaddress("", "legacy")
vaultId6 = self.nodes[0].createvault(ownerAddress3)
self.nodes[0].generate(1)
# Fund with DFI
self.nodes[0].deposittovault(vaultId6, self.accountDFI, '5@DFI')
self.nodes[0].generate(1)
# Fund with ETH
self.nodes[0].minttokens("10@" + self.symbolETH)
self.nodes[0].generate(1)
self.nodes[0].deposittovault(vaultId6, self.nodes[0].get_genesis_keys().ownerAuthAddress, '5@ETH')
self.nodes[0].generate(1)
# Try and deposit more GOOGL to vault
self.nodes[0].minttokens("1@" + self.symbolGOOGL)
self.nodes[0].generate(1)
assert_raises_rpc_error(-32600, f'Collateral token with id ({self.idGOOGL}) does not exist!', self.nodes[0].deposittovault, vaultId6, self.nodes[0].get_genesis_keys().ownerAuthAddress, '1@GOOGL')
# Try and take collateral token as loan
assert_raises_rpc_error(-32600, f'Loan token with id ({self.idETH}) does not exist!', self.nodes[0].takeloan, {'vaultId': vaultId6, 'amounts': "1@ETH"})
# Take loan
self.nodes[0].takeloan({'vaultId': vaultId6, 'amounts': "1@GOOGL"})
self.nodes[0].generate(1)
# Check collateral ratio
assert_equal(self.nodes[0].getvault(vaultId6)['collateralRatio'], 375)
# Change collateral ratio
self.nodes[0].setgov({"ATTRIBUTES":{f'v0/token/{self.idETH}/loan_collateral_factor':'1'}})
self.nodes[0].generate(2)
# Check new ratio
assert_equal(self.nodes[0].getvault(vaultId6)['collateralRatio'], 500)
assert_equal(self.nodes[0].getgov('ATTRIBUTES')['ATTRIBUTES'][f'v0/token/{self.idETH}/loan_collateral_factor'], '1')
# Change collateral currency pair
self.nodes[0].setgov({"ATTRIBUTES":{f'v0/token/{self.idETH}/fixed_interval_price_id':'BTC/USD'}})
self.nodes[0].generate(1)
# Check new ratio and currency pair
assert_equal(self.nodes[0].getvault(vaultId6)['collateralRatio'], 375)
assert_equal(self.nodes[0].getgov('ATTRIBUTES')['ATTRIBUTES'][f'v0/token/{self.idETH}/fixed_interval_price_id'], 'BTC/USD')
# Disable collateral token
self.nodes[0].setgov({"ATTRIBUTES":{f'v0/token/{self.idETH}/loan_collateral_enabled':'false'}})
self.nodes[0].generate(1)
# Check ETH collateral token disabled
assert_equal(self.nodes[0].getgov('ATTRIBUTES')['ATTRIBUTES'][f'v0/token/{self.idETH}/loan_collateral_enabled'], 'false')
# Try and deposit disabled collateral to vault
assert_raises_rpc_error(-32600, f'Collateral token ({self.idETH}) is disabled', self.nodes[0].deposittovault, vaultId6, self.nodes[0].get_genesis_keys().ownerAuthAddress, '1@ETH')
# Reduce interest to zero
self.nodes[0].setgov({"ATTRIBUTES":{f'v0/token/{self.idGOOGL}/loan_minting_interest':'0'}})
self.nodes[0].generate(1)
# Take new loan with zero interest on the loan token
self.nodes[0].takeloan({'vaultId': vaultId6, 'amounts': "1@GOOGL"})
self.nodes[0].generate(1)
# Check interest is now zero