@renegade-fi/core
Version:
VanillaJS library for Renegade
37 lines • 1.89 kB
JavaScript
import invariant from "tiny-invariant";
import { toHex } from "viem";
import { DEPOSIT_BALANCE_ROUTE } from "../constants.js";
import { stringifyForWasm } from "../utils/bigJSON.js";
import { postRelayerWithAuth } from "../utils/http.js";
import { getBackOfQueueWallet } from "./getBackOfQueueWallet.js";
import { getWalletId } from "./getWalletId.js";
export async function deposit(config, parameters) {
const { amount, fromAddr, mint, newPublicKey, permit, permitDeadline, permitNonce } = parameters;
const { getBaseUrl, utils, renegadeKeyType } = config;
const logger = config.getLogger("core:actions:deposit");
const walletId = getWalletId(config);
const wallet = await getBackOfQueueWallet(config);
const seed = renegadeKeyType === "internal" ? config.state.seed : undefined;
const signMessage = renegadeKeyType === "external" ? config.signMessage : undefined;
if (renegadeKeyType === "external") {
invariant(signMessage !== undefined, "Sign message function is required for external key type");
}
if (renegadeKeyType === "internal") {
invariant(seed !== undefined, "Seed is required for internal key type");
}
const body = await utils.deposit(
// TODO: Change Rust to accept Option<String>
seed, stringifyForWasm(wallet), fromAddr, mint, toHex(amount), toHex(permitNonce), toHex(permitDeadline), permit, newPublicKey, signMessage);
try {
const res = await postRelayerWithAuth(config, getBaseUrl(DEPOSIT_BALANCE_ROUTE(walletId)), body);
logger.debug(`task update-wallet(${res.task_id})`, { walletId, taskId: res.task_id });
return { taskId: res.task_id };
}
catch (error) {
logger.error(`Deposit failed: ${error instanceof Error ? error.message : String(error)}`, {
walletId,
});
throw error;
}
}
//# sourceMappingURL=deposit.js.map