96 lines
3.2 KiB
Solidity
96 lines
3.2 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity ^0.8.20;
|
|
|
|
import "../interfaces/IAdapter.sol";
|
|
|
|
/**
|
|
* @title Iso20022PayAdapter
|
|
* @notice Adapter for ISO-20022 payment instructions (off-chain bridge)
|
|
*/
|
|
contract Iso20022PayAdapter is IAdapter {
|
|
string public constant override name = "ISO-20022 Pay";
|
|
|
|
// Event emitted when payment instruction is ready
|
|
event PaymentInstruction(bytes32 indexed planId, bytes32 messageHash, string isoMessage);
|
|
|
|
function executeStep(bytes calldata data) external override returns (bool success, bytes memory returnData) {
|
|
// Decode payment parameters
|
|
// (bytes32 planId, string beneficiaryIBAN, uint256 amount, string currency)
|
|
(bytes32 planId, string memory beneficiaryIBAN, uint256 amount, string memory currency) =
|
|
abi.decode(data, (bytes32, string, uint256, string));
|
|
|
|
// Generate ISO-20022 message (off-chain)
|
|
bytes32 messageHash = keccak256(abi.encode(planId, beneficiaryIBAN, amount, currency));
|
|
string memory isoMessage = _generateIsoMessage(planId, beneficiaryIBAN, amount, currency);
|
|
|
|
emit PaymentInstruction(planId, messageHash, isoMessage);
|
|
|
|
// In production, this would trigger off-chain ISO message generation
|
|
// The actual payment happens off-chain via banking rails
|
|
|
|
success = true;
|
|
returnData = abi.encode(messageHash);
|
|
}
|
|
|
|
function prepareStep(bytes calldata data) external override returns (bool prepared) {
|
|
// Check if payment can be prepared (compliance check, etc.)
|
|
return true;
|
|
}
|
|
|
|
function adapterType() external pure override returns (uint8) {
|
|
return 1; // FIAT_DTL
|
|
}
|
|
|
|
function _generateIsoMessage(
|
|
bytes32 planId,
|
|
string memory beneficiaryIBAN,
|
|
uint256 amount,
|
|
string memory currency
|
|
) internal pure returns (string memory) {
|
|
// Simplified ISO message generation
|
|
// In production, use proper XML builder
|
|
return string(abi.encodePacked(
|
|
"ISO-20022 Message for Plan: ",
|
|
_bytes32ToString(planId),
|
|
", Amount: ",
|
|
_uint256ToString(amount),
|
|
" ",
|
|
currency,
|
|
", IBAN: ",
|
|
beneficiaryIBAN
|
|
));
|
|
}
|
|
|
|
function _bytes32ToString(bytes32 value) internal pure returns (string memory) {
|
|
bytes memory buffer = new bytes(64);
|
|
for (uint256 i = 0; i < 32; i++) {
|
|
buffer[i * 2] = _toHexChar(uint8(value[i]) >> 4);
|
|
buffer[i * 2 + 1] = _toHexChar(uint8(value[i]) & 0x0f);
|
|
}
|
|
return string(buffer);
|
|
}
|
|
|
|
function _uint256ToString(uint256 value) internal pure returns (string memory) {
|
|
if (value == 0) return "0";
|
|
uint256 temp = value;
|
|
uint256 digits;
|
|
while (temp != 0) {
|
|
digits++;
|
|
temp /= 10;
|
|
}
|
|
bytes memory buffer = new bytes(digits);
|
|
while (value != 0) {
|
|
digits--;
|
|
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
|
|
value /= 10;
|
|
}
|
|
return string(buffer);
|
|
}
|
|
|
|
function _toHexChar(uint8 value) internal pure returns (bytes1) {
|
|
if (value < 10) return bytes1(value + 48);
|
|
else return bytes1(value + 87);
|
|
}
|
|
}
|
|
|