@@ -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);
@@ -1398,9 +1339,7 @@ contract UCS03Zkgm is
1398
1339
delete inFlightPacket[packetHash];
1399
1340
} else {
1400
1341
ZkgmPacket calldata zkgmPacket = ZkgmLib.decode (ibcPacket.data);
1401
- timeoutInternal (
1402
- ibcPacket, relayer, zkgmPacket.instruction
1403
- );
1342
+ timeoutInternal (ibcPacket, relayer, zkgmPacket.instruction);
1404
1343
}
1405
1344
}
1406
1345
@@ -1439,27 +1378,21 @@ contract UCS03Zkgm is
1439
1378
revert ZkgmLib.ErrUnsupportedVersion ();
1440
1379
}
1441
1380
timeoutBatch (
1442
- ibcPacket,
1443
- relayer,
1444
- ZkgmLib.decodeBatch (instruction.operand)
1381
+ ibcPacket, relayer, ZkgmLib.decodeBatch (instruction.operand)
1445
1382
);
1446
1383
} else if (instruction.opcode == ZkgmLib.OP_FORWARD) {
1447
1384
if (instruction.version > ZkgmLib.INSTR_VERSION_0) {
1448
1385
revert ZkgmLib.ErrUnsupportedVersion ();
1449
1386
}
1450
1387
timeoutForward (
1451
- ibcPacket,
1452
- relayer,
1453
- ZkgmLib.decodeForward (instruction.operand)
1388
+ ibcPacket, relayer, ZkgmLib.decodeForward (instruction.operand)
1454
1389
);
1455
1390
} else if (instruction.opcode == ZkgmLib.OP_MULTIPLEX) {
1456
1391
if (instruction.version > ZkgmLib.INSTR_VERSION_0) {
1457
1392
revert ZkgmLib.ErrUnsupportedVersion ();
1458
1393
}
1459
1394
timeoutMultiplex (
1460
- ibcPacket,
1461
- relayer,
1462
- ZkgmLib.decodeMultiplex (instruction.operand)
1395
+ ibcPacket, relayer, ZkgmLib.decodeMultiplex (instruction.operand)
1463
1396
);
1464
1397
} else {
1465
1398
revert ZkgmLib.ErrUnknownOpcode ();
0 commit comments