Skip to content

added update spending limit functionality - #4

Merged
alikhabazian merged 2 commits into
mainfrom
update-spending-limit
Oct 12, 2023
Merged

added update spending limit functionality#4
alikhabazian merged 2 commits into
mainfrom
update-spending-limit

Conversation

@mehrdadmms

@mehrdadmms mehrdadmms commented Oct 12, 2023

Copy link
Copy Markdown
Member

Description

Added update spending limit functionality and gave the permission to DAO.
Closes #2

How to test

Use the code below or go to Aragon page and create a proposal using smart contract composer.

import { ethers } from "ethers";
import { DaoAction } from "@aragon/sdk-client-common";
import { hexToBytes } from "./../src/lib/helpers";
import { AllowedNetwork } from "./../src/lib/constants";
import { tokenVotingClient } from "./../src/lib/sdk";
import { VoteValues } from "@aragon/sdk-client";

const NETWORK: AllowedNetwork = "goerli";
const DAO_ADDRESS_OR_ENS = "bananadao.dao.eth";
const votingClient = tokenVotingClient(NETWORK);

const pluginAddress = "0xb08d369f81b64182c37dc0bffeb532c62c26fb49"; // Replace with your contract address
const VOTING_APP_ADDRESS = "0x09a48e084f0f664be10656caae0eb2ed26309f85";

const contractABI = [{"inputs":[{"internalType":"address","name":"dao","type":"address"},{"internalType":"address","name":"where","type":"address"},{"internalType":"address","name":"who","type":"address"},{"internalType":"bytes32","name":"permissionId","type":"bytes32"}],"name":"DaoUnauthorized","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"inputs":[],"name":"UPDATE_SPENDING_LIMIT_PERMISSION_ID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dao","outputs":[{"internalType":"contract IDAO","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct IDAO.Action[]","name":"_actions","type":"tuple[]"}],"name":"execute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"hatId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hatsProtocolInstance","outputs":[{"internalType":"contract IHats","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IDAO","name":"_dao","type":"address"},{"internalType":"uint256","name":"_hatId","type":"uint256"},{"internalType":"uint256","name":"_spendingLimitETH","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pluginType","outputs":[{"internalType":"enum IPlugin.PluginType","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"spendingLimitETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_spendingLimitETH","type":"uint256"}],"name":"updateSpendingLimit","outputs":[],"stateMutability":"nonpayable","type":"function"}]

const iface = new ethers.utils.Interface(contractABI);

const hexData = iface.encodeFunctionData("updateSpendingLimit", [BigInt(200000)]);


// Example: Send a transaction to modify contract state
async function modifyState() {
  const daoAction: DaoAction = {
    to: pluginAddress, // Replace with an actual Ethereum address
    value: BigInt(0), // Replace with an actual value (in Wei)
    data: hexToBytes(hexData), // Replace with actual Uint8Array data
  };
  const metadataUri: string = await votingClient.methods.pinMetadata({
    title: "update spending limit",
    summary: "This is a test proposal",
    description: "This is the description of a long test proposal",
    resources: [
      {
        url: "https://thforumurl.com",
        name: "Forum",
      },
    ],
    media: {
      header: "https://fileserver.com/header.png",
      logo: "https://fileserver.com/logo.png",
    },
  });

  const steps = votingClient.methods.createProposal({
    metadataUri,
    pluginAddress: VOTING_APP_ADDRESS,
    actions: [daoAction],
    creatorVote: VoteValues.YES, // creator votes yes
    executeOnPass: true, // execute on pass
    startDate: new Date(0), // Start immediately
    endDate: new Date(0), // uses minimum voting duration
  });

  // 3e. ***Iterate through the steps***
  for await (const step of steps) {
    try {
      console.log(step);
    } catch (err) {
      console.error(err);
    }
    console.log("🎉🎉🎉🎉🎉🎉🎉🎉🎉");
  }
}
modifyState().then();

@alikhabazian
alikhabazian merged commit 0ed9475 into main Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update spending limit after installation

2 participants