Skip to main content

vault.depositYield(DepositYield)

Deposit yield into a vault’s reward distributor. This approves the ERC20 amount and then deposits it.

DepositYield Type Parameters

ParameterTypeRequiredDescription
depositorSignerSignerRequiredSigner that deposits yield. Must be connected to a provider.
vaultstringRequiredVault address.
erc20stringRequiredERC20 token address used to deposit yield.
decimalsnumberRequiredERC20 token decimals.
humanReadableAmountstringRequiredAmount to deposit in human-readable units (e.g., "1").

Returns

FieldTypeDescription
statusdepositedStatus of the operation.
vaultstringVault address.
rewardDistributorstringReward distributor contract address.
depositorstringAddress that submitted the transaction.
token{ address: string; decimals: number }ERC20 token details.
amount{ human: string; units: bigint }Amount details.
approval{ status: 'approved'; spender: string; allowanceBefore: bigint; allowanceAfter: bigint }Approval details for the reward distributor.
receiptTransactionReceiptTransaction receipt for the deposit call.

Usage

TypeScript

import 'dotenv/config';
import { RWA, Chain, type SDKInit } from "@peaq-network/rwa";
import { JsonRpcProvider, Wallet } from "ethers";

async function main() {
  // 0. Create RWA instance and get provider
  const provider = new JsonRpcProvider(process.env.HTTPS_BASE_URL);
  const init: SDKInit = { chainId: Chain.AGUNG, provider: provider };
  const rwa_sdk = new RWA(init);

  // 1. Depositor signer
  const alice = new Wallet(process.env.ALICE_PRIVATE_KEY!, provider);

  // 2. Deposit yield
  const result = await rwa_sdk.vault.depositYield({
    depositorSigner: alice,
    vault: "0x907229D0A25A5Bb16F0ff3D890f38Eb4Ad52Ea1a",
    erc20: rwa_sdk.getAddresses().erc20.peaq,
    decimals: 18,
    humanReadableAmount: "1"
  });
  console.log("Result", result);
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

JavaScript

import 'dotenv/config';
import { RWA, Chain } from "@peaq-network/rwa";
import { JsonRpcProvider, Wallet } from "ethers";

async function main() {
  // 0. Create RWA instance and get provider
  const provider = new JsonRpcProvider(process.env.HTTPS_BASE_URL);
  const rwa_sdk = new RWA({ chainId: Chain.AGUNG, provider });

  // 1. Depositor signer
  const alice = new Wallet(process.env.ALICE_PRIVATE_KEY, provider);

  // 2. Deposit yield
  const result = await rwa_sdk.vault.depositYield({
    depositorSigner: alice,
    vault: "0x907229D0A25A5Bb16F0ff3D890f38Eb4Ad52Ea1a",
    erc20: rwa_sdk.getAddresses().erc20.peaq,
    decimals: 18,
    humanReadableAmount: "1"
  });
  console.log("Result", result);
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

Example outputs

Result {
  status: 'deposited',
  vault: '0x907229D0A25A5Bb16F0ff3D890f38Eb4Ad52Ea1a',
  rewardDistributor: '0x...',
  depositor: '0x16cd4D21537eD8F33bE08271A9FA6DCC426709b2',
  token: { address: '0x...', decimals: 18 },
  amount: { human: '1', units: 1000000000000000000n },
  approval: {
    status: 'approved',
    spender: '0x...',
    allowanceBefore: 0n,
    allowanceAfter: 1000000000000000000n
  },
  receipt: ContractTransactionReceipt {
    ...
  }
}