@@ -361,22 +361,14 @@ contract UCS03Zkgm is
361
361
return address (ibcHandler);
362
362
}
363
363
364
- function transferAndCall (
364
+ function internalSendOverChannel (
365
365
uint32 channelId ,
366
366
bytes calldata receiver ,
367
367
address baseToken ,
368
368
uint256 baseAmount ,
369
369
bytes calldata quoteToken ,
370
- uint256 quoteAmount ,
371
- bytes calldata contractAddress ,
372
- bytes calldata contractCalldata ,
373
- uint64 timeoutHeight ,
374
- uint64 timeoutTimestamp ,
375
- bytes32 salt
376
- ) public {
377
- if (baseAmount == 0 ) {
378
- revert ZkgmLib.ErrInvalidAmount ();
379
- }
370
+ uint256 quoteAmount
371
+ ) internal returns (Instruction memory ) {
380
372
uint256 origin = tokenOrigin[baseToken];
381
373
// Verify the unwrap
382
374
(address wrappedToken ,) =
@@ -397,13 +389,14 @@ contract UCS03Zkgm is
397
389
);
398
390
channelBalance[channelId][address (baseToken)] += baseAmount;
399
391
}
392
+
400
393
// TODO: make this non-failable as it's not guaranteed to exist
401
- Instruction[] memory instructions = new Instruction [](2 );
402
394
IERC20Metadata sentTokenMeta = IERC20Metadata (baseToken);
403
395
string memory symbol = sentTokenMeta.symbol ();
404
396
string memory name = sentTokenMeta.name ();
405
397
uint8 decimals = sentTokenMeta.decimals ();
406
- instructions[0 ] = Instruction ({
398
+
399
+ return Instruction ({
407
400
version: ZkgmLib.INSTR_VERSION_1,
408
401
opcode: ZkgmLib.OP_FUNGIBLE_ASSET_ORDER,
409
402
operand: ZkgmLib.encodeFungibleAssetOrder (
@@ -421,6 +414,28 @@ contract UCS03Zkgm is
421
414
})
422
415
)
423
416
});
417
+ }
418
+
419
+ function transferAndCall (
420
+ uint32 channelId ,
421
+ bytes calldata receiver ,
422
+ address baseToken ,
423
+ uint256 baseAmount ,
424
+ bytes calldata quoteToken ,
425
+ uint256 quoteAmount ,
426
+ bytes calldata contractAddress ,
427
+ bytes calldata contractCalldata ,
428
+ uint64 timeoutHeight ,
429
+ uint64 timeoutTimestamp ,
430
+ bytes32 salt
431
+ ) public {
432
+ if (baseAmount == 0 ) {
433
+ revert ZkgmLib.ErrInvalidAmount ();
434
+ }
435
+ Instruction[] memory instructions = new Instruction [](2 );
436
+ instructions[0 ] = internalSendOverChannel (
437
+ channelId, receiver, baseToken, baseAmount, quoteToken, quoteAmount
438
+ );
424
439
instructions[1 ] = Instruction ({
425
440
version: ZkgmLib.INSTR_VERSION_0,
426
441
opcode: ZkgmLib.OP_MULTIPLEX,
@@ -453,39 +468,6 @@ contract UCS03Zkgm is
453
468
);
454
469
}
455
470
456
- function call (
457
- uint32 channelId ,
458
- bytes calldata contractAddress ,
459
- bytes calldata contractCalldata ,
460
- uint64 timeoutHeight ,
461
- uint64 timeoutTimestamp ,
462
- bytes32 salt
463
- ) public {
464
- ibcHandler.sendPacket (
465
- channelId,
466
- timeoutHeight,
467
- timeoutTimestamp,
468
- ZkgmLib.encode (
469
- ZkgmPacket ({
470
- salt: keccak256 (abi.encodePacked (msg .sender , salt)),
471
- path: 0 ,
472
- instruction: Instruction ({
473
- version: ZkgmLib.INSTR_VERSION_0,
474
- opcode: ZkgmLib.OP_MULTIPLEX,
475
- operand: ZkgmLib.encodeMultiplex (
476
- Multiplex ({
477
- sender: abi.encodePacked (msg .sender ),
478
- eureka: true ,
479
- contractAddress: contractAddress,
480
- contractCalldata: contractCalldata
481
- })
482
- )
483
- })
484
- })
485
- )
486
- );
487
- }
488
-
489
471
function transferV2 (
490
472
uint32 channelId ,
491
473
bytes calldata receiver ,
@@ -501,52 +483,11 @@ contract UCS03Zkgm is
501
483
if (baseAmount == 0 ) {
502
484
revert ZkgmLib.ErrInvalidAmount ();
503
485
}
504
- uint256 origin = tokenOrigin[baseToken];
505
- // Verify the unwrap
506
- (address wrappedToken ,) =
507
- internalPredictWrappedTokenMemory (0 , channelId, quoteToken);
508
- // Only allow unwrapping if the quote asset is the unwrapped asset.
509
- if (
510
- ZkgmLib.lastChannelFromPath (origin) == channelId
511
- && abi.encodePacked (baseToken).eq (abi.encodePacked (wrappedToken))
512
- ) {
513
- IZkgmERC20 (baseToken).burn (msg .sender , baseAmount);
514
- } else {
515
- // We reset the origin, the asset will not be unescrowed on the destination
516
- origin = 0 ;
517
- // TODO: extract this as a step before verifying to allow for ERC777
518
- // send hook
519
- SafeERC20.safeTransferFrom (
520
- IERC20 (baseToken), msg .sender , address (this ), baseAmount
521
- );
522
- channelBalance[channelId][address (baseToken)] += baseAmount;
523
- }
524
-
525
- // TODO: make calls to sentTokenMeta non-failable as it's not guaranteed to exist
526
- IERC20Metadata sentTokenMeta = IERC20Metadata (baseToken);
527
- uint256 nbOfInstructions = 1 ;
528
- if (msg .value > 0 ) {
529
- nbOfInstructions = 2 ;
530
- }
531
- Instruction[] memory instructions = new Instruction [](nbOfInstructions);
532
- instructions[0 ] = Instruction ({
533
- version: ZkgmLib.INSTR_VERSION_1,
534
- opcode: ZkgmLib.OP_FUNGIBLE_ASSET_ORDER,
535
- operand: ZkgmLib.encodeFungibleAssetOrder (
536
- FungibleAssetOrder ({
537
- sender: abi.encodePacked (msg .sender ),
538
- receiver: receiver,
539
- baseToken: abi.encodePacked (baseToken),
540
- baseTokenPath: origin,
541
- baseTokenSymbol: sentTokenMeta.symbol (),
542
- baseTokenName: sentTokenMeta.name (),
543
- baseTokenDecimals: sentTokenMeta.decimals (),
544
- baseAmount: baseAmount,
545
- quoteToken: quoteToken,
546
- quoteAmount: quoteAmount
547
- })
548
- )
549
- });
486
+ Instruction[] memory instructions =
487
+ new Instruction [](msg .value > 0 ? 2 : 1 );
488
+ instructions[0 ] = internalSendOverChannel (
489
+ channelId, receiver, baseToken, baseAmount, quoteToken, quoteAmount
490
+ );
550
491
if (msg .value > 0 ) {
551
492
weth.deposit {value: msg .value }();
552
493
address wethBaseToken = address (weth);
@@ -897,15 +838,13 @@ contract UCS03Zkgm is
897
838
return executeFungibleAssetOrder (
898
839
ibcPacket,
899
840
relayer,
900
- relayerMsg,
901
- salt,
902
841
path,
903
- order.sender,
904
842
order.receiver,
905
843
order.baseToken,
906
844
order.baseAmount,
907
845
order.baseTokenSymbol,
908
846
order.baseTokenName,
847
+ 0 ,
909
848
order.baseTokenPath,
910
849
order.quoteToken,
911
850
order.quoteAmount
@@ -916,15 +855,13 @@ contract UCS03Zkgm is
916
855
return executeFungibleAssetOrder (
917
856
ibcPacket,
918
857
relayer,
919
- relayerMsg,
920
- salt,
921
858
path,
922
- order.sender,
923
859
order.receiver,
924
860
order.baseToken,
925
861
order.baseAmount,
926
862
order.baseTokenSymbol,
927
863
order.baseTokenName,
864
+ order.baseTokenDecimals,
928
865
order.baseTokenPath,
929
866
order.quoteToken,
930
867
order.quoteAmount
@@ -1099,15 +1036,13 @@ contract UCS03Zkgm is
1099
1036
function executeFungibleAssetOrder (
1100
1037
IBCPacket calldata ibcPacket ,
1101
1038
address relayer ,
1102
- bytes calldata relayerMsg ,
1103
- bytes32 salt ,
1104
1039
uint256 path ,
1105
- bytes calldata orderSender ,
1106
1040
bytes calldata orderReceiver ,
1107
1041
bytes calldata orderBaseToken ,
1108
1042
uint256 orderBaseAmount ,
1109
1043
string calldata orderBaseTokenSymbol ,
1110
1044
string calldata orderBaseTokenName ,
1045
+ uint8 orderBaseTokenDecimals ,
1111
1046
uint256 orderBaseTokenPath ,
1112
1047
bytes calldata orderQuoteToken ,
1113
1048
uint256 orderQuoteAmount
@@ -1133,6 +1068,7 @@ contract UCS03Zkgm is
1133
1068
abi.encode (
1134
1069
orderBaseTokenName,
1135
1070
orderBaseTokenSymbol,
1071
+ orderBaseTokenDecimals,
1136
1072
address (this )
1137
1073
)
1138
1074
),
@@ -1403,16 +1339,13 @@ contract UCS03Zkgm is
1403
1339
delete inFlightPacket[packetHash];
1404
1340
} else {
1405
1341
ZkgmPacket calldata zkgmPacket = ZkgmLib.decode (ibcPacket.data);
1406
- timeoutInternal (
1407
- ibcPacket, relayer, zkgmPacket.salt, zkgmPacket.instruction
1408
- );
1342
+ timeoutInternal (ibcPacket, relayer, zkgmPacket.instruction);
1409
1343
}
1410
1344
}
1411
1345
1412
1346
function timeoutInternal (
1413
1347
IBCPacket calldata ibcPacket ,
1414
1348
address relayer ,
1415
- bytes32 salt ,
1416
1349
Instruction calldata instruction
1417
1350
) internal {
1418
1351
if (instruction.opcode == ZkgmLib.OP_FUNGIBLE_ASSET_ORDER) {
@@ -1424,8 +1357,6 @@ contract UCS03Zkgm is
1424
1357
ZkgmLib.decodeFungibleAssetOrderV0 (instruction.operand);
1425
1358
timeoutFungibleAssetOrder (
1426
1359
ibcPacket,
1427
- relayer,
1428
- salt,
1429
1360
order.sender,
1430
1361
order.baseToken,
1431
1362
order.baseTokenPath,
@@ -1436,8 +1367,6 @@ contract UCS03Zkgm is
1436
1367
ZkgmLib.decodeFungibleAssetOrder (instruction.operand);
1437
1368
timeoutFungibleAssetOrder (
1438
1369
ibcPacket,
1439
- relayer,
1440
- salt,
1441
1370
order.sender,
1442
1371
order.baseToken,
1443
1372
order.baseTokenPath,
@@ -1449,30 +1378,21 @@ contract UCS03Zkgm is
1449
1378
revert ZkgmLib.ErrUnsupportedVersion ();
1450
1379
}
1451
1380
timeoutBatch (
1452
- ibcPacket,
1453
- relayer,
1454
- salt,
1455
- ZkgmLib.decodeBatch (instruction.operand)
1381
+ ibcPacket, relayer, ZkgmLib.decodeBatch (instruction.operand)
1456
1382
);
1457
1383
} else if (instruction.opcode == ZkgmLib.OP_FORWARD) {
1458
1384
if (instruction.version > ZkgmLib.INSTR_VERSION_0) {
1459
1385
revert ZkgmLib.ErrUnsupportedVersion ();
1460
1386
}
1461
1387
timeoutForward (
1462
- ibcPacket,
1463
- relayer,
1464
- salt,
1465
- ZkgmLib.decodeForward (instruction.operand)
1388
+ ibcPacket, relayer, ZkgmLib.decodeForward (instruction.operand)
1466
1389
);
1467
1390
} else if (instruction.opcode == ZkgmLib.OP_MULTIPLEX) {
1468
1391
if (instruction.version > ZkgmLib.INSTR_VERSION_0) {
1469
1392
revert ZkgmLib.ErrUnsupportedVersion ();
1470
1393
}
1471
1394
timeoutMultiplex (
1472
- ibcPacket,
1473
- relayer,
1474
- salt,
1475
- ZkgmLib.decodeMultiplex (instruction.operand)
1395
+ ibcPacket, relayer, ZkgmLib.decodeMultiplex (instruction.operand)
1476
1396
);
1477
1397
} else {
1478
1398
revert ZkgmLib.ErrUnknownOpcode ();
@@ -1482,15 +1402,14 @@ contract UCS03Zkgm is
1482
1402
function timeoutBatch (
1483
1403
IBCPacket calldata ibcPacket ,
1484
1404
address relayer ,
1485
- bytes32 salt ,
1486
1405
Batch calldata batch
1487
1406
) internal {
1488
1407
uint256 l = batch.instructions.length ;
1489
1408
for (uint256 i = 0 ; i < l; i++ ) {
1490
1409
timeoutInternal (
1491
1410
ibcPacket,
1492
1411
relayer,
1493
- keccak256 (abi.encode (i, salt)),
1412
+ // keccak256(abi.encode(i, salt)),
1494
1413
batch.instructions[i]
1495
1414
);
1496
1415
}
@@ -1499,14 +1418,12 @@ contract UCS03Zkgm is
1499
1418
function timeoutForward (
1500
1419
IBCPacket calldata ibcPacket ,
1501
1420
address relayer ,
1502
- bytes32 salt ,
1503
1421
Forward calldata forward
1504
1422
) internal {}
1505
1423
1506
1424
function timeoutMultiplex (
1507
1425
IBCPacket calldata ibcPacket ,
1508
1426
address relayer ,
1509
- bytes32 salt ,
1510
1427
Multiplex calldata multiplex
1511
1428
) internal {
1512
1429
if (! multiplex.eureka) {
@@ -1527,8 +1444,6 @@ contract UCS03Zkgm is
1527
1444
1528
1445
function timeoutFungibleAssetOrder (
1529
1446
IBCPacket calldata ibcPacket ,
1530
- address relayer ,
1531
- bytes32 salt ,
1532
1447
bytes calldata orderSender ,
1533
1448
bytes calldata orderBaseToken ,
1534
1449
uint256 orderBaseTokenPath ,
0 commit comments