IPrivacy.deposit
deposit(
PrivacyDepositRequest calldata request
) external payable returns (bool success) 네이티브 OKRW를 프라이버시 풀에 예치합니다. msg.value(aokrw 단위)를 프라이버시 프리컴파일의 고정 에스크로에 잠그고, 새 노트를 머클 트리에 커밋합니다. 예치 금액은 EVM의 msg.value로 전달합니다. 요청 struct에는 더 이상 amount 필드가 존재하지 않습니다. 성공 시 PrivacyDeposit 이벤트를 발행하며, 이벤트에 기록되는 amount는 msg.value를 런타임 네이티브 denom 기준의 Cosmos 코인 문자열로 표기한 값입니다.
파라미터
| 이름 | 타입 | 필수 | 설명 |
|---|---|---|---|
request | PrivacyDepositRequest | ✓ | 예치 페이로드입니다. struct는 { bytes noteCommitment; bytes encryptedNote; bytes proof; }이며, 금액은 struct에 포함되지 않습니다. noteCommitment는 새 노트의 MiMC 커밋먼트이고, encryptedNote는 수신자에게 암호화된 노트 페이로드이며, proof는 커밋먼트를 msg.value에 결속하는 예치 ZK 증명입니다. |
반환값
타입:
bool 성공 시 true를 반환합니다. 실패 경로는 일반 문자열 사유로 revert됩니다. 이 프리컴파일은 타입 지정 커스텀 오류를 선언하지 않습니다.
에러
| 코드 | 이름 | 설명 |
|---|---|---|
privacy deposit value is required | privacy deposit value is required | msg.value가 전달되지 않았을 때 일반 문자열로 revert됩니다. deposit은 payable이며 aokrw 단위의 양의 값이 필요합니다. |
privacy deposit actor must be the non-zero operator | privacy deposit actor must be the non-zero operator | 실질 발신자가 0 주소이거나 operator와 일치하지 않을 때 일반 문자열로 revert됩니다. 이 두 값을 분리하던 depositWithAuthorization 경로는 이제 제공되지 않으므로 직접 호출만 지원됩니다. |
privacy precompile only supports native denom | privacy precompile only supports native denom "%s", got "%s" | 체인 파라미터에서 조회한 런타임 네이티브 denom이 프리컴파일에 설정된 값과 다를 때 일반 문자열로 revert됩니다. |
invalid fixed privacy deposit funder | invalid fixed privacy deposit funder | 고정 에스크로 주소(프라이버시 프리컴파일 자신)에 대한 내부 정합성 검사가 실패했을 때 일반 문자열로 revert됩니다. 정상 사용에서는 발생하지 않습니다. |
예제
프라이버시 풀에 1,000만 OKRW 예치 (viem)
import { createWalletClient, http, parseEther } from "viem";
import { privateKeyToAccount } from "viem/accounts";
const PRIVACY = "0x100000000000000000000000000000000000000b" as const;
const privacyAbi = [{
type: "function",
name: "deposit",
stateMutability: "payable",
inputs: [{
name: "request",
type: "tuple",
components: [
{ name: "noteCommitment", type: "bytes" },
{ name: "encryptedNote", type: "bytes" },
{ name: "proof", type: "bytes" },
],
}],
outputs: [{ type: "bool" }],
}] as const;
const wallet = createWalletClient({
account: privateKeyToAccount(process.env.DEPOSITOR_KEY as `0x${string}`),
transport: http("https://rpc-testnet.maroo.io"),
});
// Client-side prover produces these three fields bound to the deposit amount.
const { noteCommitment, encryptedNote, proof } = await buildDepositWitness({
amountAokrw: parseEther("10000000"), // 10,000,000 OKRW in aokrw
});
await wallet.writeContract({
address: PRIVACY,
abi: privacyAbi,
functionName: "deposit",
args: [{ noteCommitment, encryptedNote, proof }],
value: parseEther("10000000"), // native OKRW flows via msg.value now
}); payable 이전 ABI에서의 마이그레이션
기존 통합에서 request 안에 amount를 Cosmos 코인 문자열("10000000000000000000000000aokrw")로 인코딩하던 방식은 더 이상 유효하지 않습니다. 대신 msg.value로 값을 전달합니다. 프리컴파일이 런타임 네이티브 denom을 기준으로 트랜잭션 value에서 예치 금액을 도출합니다.
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.22;
import "@maroo-chain/contracts/precompiles/privacy/IPrivacy.sol";
contract PrivacyDepositor {
IPrivacy constant PRIVACY = IPrivacy(0x100000000000000000000000000000000000000b);
/// @notice The request struct no longer carries `amount`. The deposit
/// amount is the native value forwarded as msg.value (aokrw).
function shield(
bytes calldata noteCommitment,
bytes calldata encryptedNote,
bytes calldata proof
) external payable {
require(msg.value > 0, "deposit value required");
PrivacyDepositRequest memory req = PrivacyDepositRequest({
noteCommitment: noteCommitment,
encryptedNote: encryptedNote,
proof: proof
});
bool ok = PRIVACY.deposit{value: msg.value}(req);
require(ok, "privacy deposit failed");
}
}