For user controlled wallet, user can delegate developer to send certain transactions on behalf of them for a limited time by creating delegation policy. This is very useful for automation of certain tasks where user don’t want to be involved when the task needs to be performed.

Prerequisite: Create Wallet
const createPolicyResp = await wk.policies.create({
    network: Network.Base,
    walletAddress: "<walelt address>",
    argumentRules: [
        {
            value: "<USDC_ADDRESS>",
            argument: "to",
            operator: Operator.Eq,
        },
        {
            value: "transfer",
            argument: "decodedInput.function",
            operator: Operator.Eq,
        },
        {
            value: "10000000",
            argument: "decodedInput.value",
            operator: Operator.Lt,
        },
        {
            value: "0x4795cd8f434847eccdf5b62370157a70a7da6a46",
            argument: "decodedInput.to",
            operator: Operator.Eq,
        }
    ],
    expiresAt: new Date("2024-01-23T18:25:43.511Z"),
    developerSecret: "<developer secret>",
    userPin: "<user pin>",
});

if (!createPolicyResp.ok) {
// handle error
}

The above example creates a policy that allows developer to initiate USDC transfer that is less than 10 USDC to the specified address without requiring user to be involved.

Delegation policy is a set of rules that define what transactions can be sent on behalf of the user for a given period. And rules are defined as a list of ArgumentRule objects. The argument field defines which part of the transaction should be checked (e.g. to, value). WalletKit decodes the transaction input data to decodedInput object, to access the decoded input, use decodedInput.<field> (e.g. decodedInput.function, decodedInput.to).