import { ProjectivePoint } from "../types.js"; import { ProofOfWithdraw } from "../provers/withdraw.js"; import { CipherBalance } from "../types.js"; import { Call, Contract, num, CairoOption } from "starknet"; import { AEBalance } from "../ae_balance.js"; import { IOperation, OperationType } from "./operation.js"; import { Audit } from "./audit.js"; export interface IWithdrawOperation extends IOperation { type: typeof OperationType.Withdraw; } /** * Represents the calldata of a withdraw operation. * @interface WithdrawOpParams * @property {ProjectivePoint} from - The Tongo account to withdraw from * @property {bigint} amount - The amount of tongo to withdraw * @property {bigint} to - The starknet contract address to send the funds to * @property {AEBalance} hint - AE encryption of the final balance of the account * @property {ProofOfWithdraw} proof - ZK proof for the withdraw operation * @property {CairoOption} auditPart - Optional Audit to declare the balance of the account after the tx * @property {Contract} Tongo - The Tongo instance to interact with */ interface WithdrawOpParams { from: ProjectivePoint; to: bigint; amount: bigint; auxiliarCipher:CipherBalance; hint: AEBalance; proof: ProofOfWithdraw; auditPart: CairoOption; Tongo: Contract; } export class WithdrawOperation implements IWithdrawOperation { type: typeof OperationType.Withdraw = OperationType.Withdraw; from: ProjectivePoint; to: bigint; amount: bigint; hint: AEBalance; auxiliarCipher: CipherBalance; proof: ProofOfWithdraw; auditPart: CairoOption; Tongo: Contract; constructor({ from, to, amount, proof, auditPart, Tongo, hint, auxiliarCipher }: WithdrawOpParams) { this.from = from; this.to = to; this.amount = amount; this.auxiliarCipher = auxiliarCipher; this.hint = hint; this.proof = proof; this.auditPart = auditPart; this.Tongo = Tongo; } toCalldata(): Call { return this.Tongo.populate("withdraw", [ { from: this.from, amount: this.amount, hint: this.hint, to: num.toHex(this.to), auxiliarCipher: this.auxiliarCipher, auditPart: this.auditPart, proof: this.proof, }, ]); } }