@@ -24,9 +24,9 @@ const {
24
24
} = require ( '../..' ) ;
25
25
26
26
contract ( 'Synthetix' , async accounts => {
27
- const [ sAUD , sEUR ] = [ 'sAUD' , 'sEUR' ] . map ( toBytes32 ) ;
27
+ const [ sAUD , sEUR , sUSD , sETH ] = [ 'sAUD' , 'sEUR' , 'sUSD' , 'sETH '] . map ( toBytes32 ) ;
28
28
29
- const [ , owner , account1 , account2 ] = accounts ;
29
+ const [ , owner , account1 , account2 , account3 ] = accounts ;
30
30
31
31
let synthetix ,
32
32
exchangeRates ,
@@ -36,7 +36,9 @@ contract('Synthetix', async accounts => {
36
36
rewardEscrowV2 ,
37
37
oracle ,
38
38
addressResolver ,
39
- systemStatus ;
39
+ systemStatus ,
40
+ sUSDContract ,
41
+ sETHContract ;
40
42
41
43
before ( async ( ) => {
42
44
( {
@@ -48,6 +50,8 @@ contract('Synthetix', async accounts => {
48
50
RewardEscrow : rewardEscrow ,
49
51
RewardEscrowV2 : rewardEscrowV2 ,
50
52
SupplySchedule : supplySchedule ,
53
+ SynthsUSD : sUSDContract ,
54
+ SynthsETH : sETHContract ,
51
55
} = await setupAllContracts ( {
52
56
accounts,
53
57
synths : [ 'sUSD' , 'sETH' , 'sEUR' , 'sAUD' ] ,
@@ -105,6 +109,7 @@ contract('Synthetix', async accounts => {
105
109
beforeEach ( async ( ) => {
106
110
smockExchanger = await smockit ( artifacts . require ( 'Exchanger' ) . abi ) ;
107
111
smockExchanger . smocked . exchangeWithVirtual . will . return . with ( ( ) => [ '1' , account1 ] ) ;
112
+ smockExchanger . smocked . exchangeWithTracking . will . return . with ( ( ) => [ '1' ] ) ;
108
113
await addressResolver . importAddresses (
109
114
[ 'Exchanger' ] . map ( toBytes32 ) ,
110
115
[ smockExchanger . address ] ,
@@ -130,6 +135,24 @@ contract('Synthetix', async accounts => {
130
135
assert . equal ( smockExchanger . smocked . exchangeWithVirtual . calls [ 0 ] [ 4 ] , msgSender ) ;
131
136
assert . equal ( smockExchanger . smocked . exchangeWithVirtual . calls [ 0 ] [ 5 ] , trackingCode ) ;
132
137
} ) ;
138
+
139
+ it ( 'exchangeWithTrackingForInitiator is called with the right arguments ' , async ( ) => {
140
+ await synthetix . exchangeWithTrackingForInitiator (
141
+ currencyKey1 ,
142
+ amount1 ,
143
+ currencyKey2 ,
144
+ account2 ,
145
+ trackingCode ,
146
+ { from : account3 }
147
+ ) ;
148
+ assert . equal ( smockExchanger . smocked . exchangeWithTracking . calls [ 0 ] [ 0 ] , account3 ) ;
149
+ assert . equal ( smockExchanger . smocked . exchangeWithTracking . calls [ 0 ] [ 1 ] , currencyKey1 ) ;
150
+ assert . equal ( smockExchanger . smocked . exchangeWithTracking . calls [ 0 ] [ 2 ] . toString ( ) , amount1 ) ;
151
+ assert . equal ( smockExchanger . smocked . exchangeWithTracking . calls [ 0 ] [ 3 ] , currencyKey2 ) ;
152
+ assert . equal ( smockExchanger . smocked . exchangeWithTracking . calls [ 0 ] [ 4 ] , account3 ) ; // destination address (tx.origin)
153
+ assert . equal ( smockExchanger . smocked . exchangeWithTracking . calls [ 0 ] [ 5 ] , account2 ) ;
154
+ assert . equal ( smockExchanger . smocked . exchangeWithTracking . calls [ 0 ] [ 6 ] , trackingCode ) ;
155
+ } ) ;
133
156
} ) ;
134
157
135
158
describe ( 'mint() - inflationary supply minting' , async ( ) => {
@@ -390,4 +413,58 @@ contract('Synthetix', async accounts => {
390
413
assert . bnEqual ( await synthetix . balanceOf ( rewardEscrow . address ) , 0 ) ;
391
414
} ) ;
392
415
} ) ;
416
+
417
+ describe ( 'Using a contract to invoke exchangeWithTrackingForInitiator' , ( ) => {
418
+ describe ( 'when a third party contract is setup to exchange synths' , ( ) => {
419
+ let contractExample ;
420
+ let amountOfsUSD ;
421
+ beforeEach ( async ( ) => {
422
+ amountOfsUSD = toUnit ( '100' ) ;
423
+
424
+ const MockThirdPartyExchangeContract = artifacts . require ( 'MockThirdPartyExchangeContract' ) ;
425
+
426
+ // create a contract
427
+ contractExample = await MockThirdPartyExchangeContract . new ( addressResolver . address ) ;
428
+
429
+ // ensure rates are set
430
+ await updateRatesWithDefaults ( { exchangeRates, oracle, debtCache } ) ;
431
+
432
+ // issue sUSD from the owner
433
+ await synthetix . issueSynths ( amountOfsUSD , { from : owner } ) ;
434
+
435
+ // transfer the sUSD to the contract
436
+ await sUSDContract . transfer ( contractExample . address , toUnit ( '100' ) , { from : owner } ) ;
437
+ } ) ;
438
+
439
+ describe ( 'when Barrie invokes the exchange function on the contract' , ( ) => {
440
+ let txn ;
441
+ beforeEach ( async ( ) => {
442
+ // Barrie has no sETH to start
443
+ assert . equal ( await sETHContract . balanceOf ( account3 ) , '0' ) ;
444
+
445
+ txn = await contractExample . exchange ( sUSD , amountOfsUSD , sETH , { from : account3 } ) ;
446
+ } ) ;
447
+ it ( 'then Barrie has the synths in her account' , async ( ) => {
448
+ assert . bnGt ( await sETHContract . balanceOf ( account3 ) , toUnit ( '0.01' ) ) ;
449
+ } ) ;
450
+ it ( 'and the contract has none' , async ( ) => {
451
+ assert . equal ( await sETHContract . balanceOf ( contractExample . address ) , '0' ) ;
452
+ } ) ;
453
+ it ( 'and the event emitted indicates that Barrie was the destinationAddress' , async ( ) => {
454
+ const logs = artifacts . require ( 'Synthetix' ) . decodeLogs ( txn . receipt . rawLogs ) ;
455
+ assert . eventEqual (
456
+ logs . find ( log => log . event === 'SynthExchange' ) ,
457
+ 'SynthExchange' ,
458
+ {
459
+ account : contractExample . address ,
460
+ fromCurrencyKey : sUSD ,
461
+ fromAmount : amountOfsUSD ,
462
+ toCurrencyKey : sETH ,
463
+ toAddress : account3 ,
464
+ }
465
+ ) ;
466
+ } ) ;
467
+ } ) ;
468
+ } ) ;
469
+ } ) ;
393
470
} ) ;
0 commit comments