Skip to main content

What is a policy update?

Policy updates replace the full policy set for your organization, so pull the current policies and merge any changes before proposing the update. Updates are handled through proposals that admins sign and execute.

1) Set up the client

Create the SDK client used to propose policy updates.
import { DenClient, NetworkId } from "@den/sdk";

const client = new DenClient({
  apiKey: "ck_live_...",
  rpcProviders: {
    1: "https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY",
  },
});

2) Build the updated policy set

Fetch existing policies and append or modify the set.
const currentPolicies = await client.getPolicies();

const policies = [
  ...currentPolicies.map((policy) => ({
    ...policy,
    accountIds: policy.accounts.map((account) => account.id),
  })),
  {
    name: "Small USDC Transfers",
    type: "AUTO_APPROVAL",
    transactionType: "TOKEN_TRANSFER",
    networkId: NetworkId.ETHEREUM,
    accountIds: ["acc_123"],
    tokenTransferCondition: {
      tokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
      tokenDecimals: 6,
      amountThreshold: "1000000000",
      destinationAddresses: [],
    },
  },
];

3) Propose, sign, and execute

Submit the proposal, collect approvals, and execute the update.
const proposal = await client.createPoliciesProposal({ policies });

await client.signPolicyProposal(proposal.id, {
  type: "approve",
  signature: "0x...",
});

await client.executePolicyProposal(proposal.id, {
  type: "approve",
});

Full example

import { DenClient, NetworkId } from "@den/sdk";

// 1) Set up the client.
const client = new DenClient({
  apiKey: "ck_live_...",
  rpcProviders: {
    1: "https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY",
  },
});

// 2) Build the updated policy set.
const currentPolicies = await client.getPolicies();

const policies = [
  ...currentPolicies.map((policy) => ({
    ...policy,
    accountIds: policy.accounts.map((account) => account.id),
  })),
  {
    name: "Small USDC Transfers",
    type: "AUTO_APPROVAL",
    transactionType: "TOKEN_TRANSFER",
    networkId: NetworkId.ETHEREUM,
    accountIds: ["acc_123"],
    tokenTransferCondition: {
      tokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
      tokenDecimals: 6,
      amountThreshold: "1000000000",
      destinationAddresses: [],
    },
  },
];

// 3) Propose, sign, and execute.
const proposal = await client.createPoliciesProposal({ policies });

await client.signPolicyProposal(proposal.id, {
  type: "approve",
  signature: "0x...",
});

await client.executePolicyProposal(proposal.id, {
  type: "approve",
});