import { Policy } from "./policy.types"; function dew_vault_policies( derivation_path: string, vault_account_id: string ): Policy[] { // Array of ids and descriptions const policyDefinitions = [ { id: "dew_vault_update_share_prices", description: "Updates share prices in the Dew vault", }, { id: "dew_vault_update_config", description: "Updates configuration parameters in the Dew vault", }, { id: "dew_vault_confirm_pending_redeems", description: "Confirms pending redemption requests in the Dew vault", }, { id: "dew_vault_process_pending_deposits", description: "Processes pending deposit requests in the Dew vault", }, { id: "dew_vault_asset_transfer", description: "Transfers assets from the Dew vault", }, { id: "dew_vault_update_metadata", description: "Updates metadata information for the Dew vault", }, { id: "dew_vault_add_to_whitelist", description: "Adds an account to the whitelist in the Dew vault", }, { id: "dew_vault_remove_from_whitelist", description: "Removes an account from the whitelist in the Dew vault", }, { id: "dew_vault_add_to_blacklist", description: "Adds an account to the blacklist in the Dew vault", }, { id: "dew_vault_remove_from_blacklist", description: "Removes an account from the blacklist in the Dew vault", }, { id: "dew_vault_emergency_pause", description: "Pauses the Dew vault in case of emergency", }, { id: "dew_vault_emergency_unpause", description: "Unpauses the Dew vault after an emergency pause", }, { id: "dew_vault_reject_pending_deposits", description: "Rejects pending deposit requests in the Dew vault", }, { id: "dew_vault_reject_pending_redeems", description: "Rejects pending redemption requests in the Dew vault", }, { id: "dew_vault_force_reset_flow_cap", description: "Forcefully resets the flow cap in the Dew vault", }, { id: "dew_vault_set_asset_fees", description: "Sets asset fees for the Dew vault", }, { id: "dew_vault_set_protocol_fee_cuts", description: "Sets protocol fee cuts for the Dew vault", }, { id: "dew_vault_set_fee_recipient", description: "Sets the fee recipient address for the Dew vault", }, { id: "dew_vault_claim_fees", description: "Claims accumulated fees from the Dew vault", }, { id: "dew_vault_claim_protocol_fees", description: "Claims accumulated protocol fees from the Dew vault", }, { id: "dew_vault_unpause_accountant", description: "Unpauses the accountant role in the Dew vault", }, { id: "dew_vault_crystallize_performance_fee", description: "Crystallizes performance fees in the Dew vault", }, { id: "dew_vault_start_vault", description: "Starts the Dew vault operations", }, { id: "dew_vault_transfer_ownership", description: "Transfers ownership of the Dew vault to a new account", }, ]; // Loop through the array to build Policy[] return policyDefinitions.map((policyDef) => ({ id: policyDef.id, description: policyDef.description, required_role: "Owner", required_vote_count: 1, policy_type: "ChainSigTransaction" as const, policy_details: { ChainSigTransaction: { derivation_path, chain_environment: "NearWasm", restrictions: [ { schema: `and( $.contract_id.equal("${vault_account_id}"), $.function_name.equal("${policyDef.id}"), )`, interface: "", }, ], }, }, activation_time: "0", proposal_expiry_time_nanosec: "86400000000000", required_pending_actions: [], })); } // increases available balance function strategist_transfer( derivation_path: string, vault_account_id: string, token_account_id: string ): Policy { return { id: "dew_vault_strategist_transfer", description: "Processes pending redeem requests", required_role: "Owner", required_vote_count: 1, policy_type: "ChainSigTransaction" as const, policy_details: { ChainSigTransaction: { derivation_path, chain_environment: "NearWasm", restrictions: [ { schema: `and( $.contract_id.equal("${token_account_id}"), $.function_name.equal("ft_transfer_call"), $.args.receiver_id.equal("${vault_account_id}"), $.args.msg.json().is_strategist_transfer.equal(true) )`, interface: "", }, ], }, }, activation_time: "0", proposal_expiry_time_nanosec: "86400000000000", required_pending_actions: [], }; } function process_redeems( derivation_path: string, vault_account_id: string, token_account_id: string ): Policy { return { id: "dew_vault_strategist_transfer", description: "Processes pending redeem requests", required_role: "Owner", required_vote_count: 1, policy_type: "ChainSigTransaction" as const, policy_details: { ChainSigTransaction: { derivation_path, chain_environment: "NearWasm", restrictions: [ { schema: `and( $.contract_id.equal("${token_account_id}"), $.function_name.equal("ft_transfer_call"), $.args.receiver_id.equal("${vault_account_id}"), $.args.msg.json().process_redeems.length().gte(1) )`, interface: "", }, ], }, }, activation_time: "0", proposal_expiry_time_nanosec: "86400000000000", required_pending_actions: [], }; } function main() { const derivation_path = "default123"; const vault_account_id = "vault.example.near"; const token_account_id = "token.example.near"; const policies = dew_vault_policies(derivation_path, vault_account_id); const extra_policy_1 = strategist_transfer(derivation_path, vault_account_id, token_account_id); const extra_policy_2 = process_redeems(derivation_path, vault_account_id, token_account_id); policies.push(extra_policy_1, extra_policy_2); console.log(JSON.stringify(policies, null, 2)); } main();