diff --git a/src/constants/dao/actions.ts b/src/constants/dao/actions.ts new file mode 100644 index 00000000..a623a51b --- /dev/null +++ b/src/constants/dao/actions.ts @@ -0,0 +1,62 @@ +import {IDict} from "../../interfaces"; +import gaugeControllerABI from "../abis/gaugecontroller.json" assert { type: 'json' }; +import votingEscrowABI from '../abis/votingescrow.json' assert { type: 'json' }; + +export const DaoAbiDictionaries: Record> = { + //pools + pools: { + 'commit_new_fee': 1, + 'ramp_A': 1, + 'commit_transfer_ownership': 1, + 'withdraw_admin_fees': 1, + 'unkill_me': 1, + 'apply_transfer_ownership': 1, + 'revert_transfer_ownership': 1, + 'apply_new_fee': 1, + 'stop_ramp_A': 1, + 'revert_new_parameters': 1, + }, + gauges: { + 'commit_transfer_ownership': gaugeControllerABI, + 'add_type': gaugeControllerABI, + 'add_gauge': gaugeControllerABI, + 'change_type_weight': gaugeControllerABI, + 'change_gauge_weight': gaugeControllerABI, + 'apply_transfer_ownership': gaugeControllerABI, + }, + member: { + 'mint': 1, + 'burn': 1, + }, + escrow: { + 'commit_transfer_ownership': votingEscrowABI, + 'commit_smart_wallet_checker': votingEscrowABI, + 'apply_transfer_ownership': votingEscrowABI, + 'apply_smart_wallet_checker': votingEscrowABI, + }, + poolProxy: { + 'commit_set_admins': 1, + 'set_burner': 1, + 'apply_set_admins': 1, + }, + registry: { + 'add_pool': 1, + 'add_pool_without_underlying': 1, + 'remove_pool': 1, + 'set_returns_none': 1, + 'set_gas_estimate_contract': 1, + 'set_calculator': 1, + 'set_burner': 1, + 'apply_set_admins': 1, + 'commit_transfer_ownership': 1, + 'apply_transfer_ownership': 1, + 'revert_transfer_ownership': 1, + 'claim_token_balance': 1, + 'claim_eth_balance': 1, + }, + vesting: { + 'fund_individual': 1, + 'toggle_disable': 1, + 'disable_can_disable': 1, + }, +} \ No newline at end of file diff --git a/src/dao.ts b/src/dao.ts index 68dbbcf6..7efda10f 100644 --- a/src/dao.ts +++ b/src/dao.ts @@ -16,7 +16,7 @@ import { IDaoProposalListItem, IDaoProposalUserListItem, IDaoProposal, - IDict, + IDict, IDaoAction, } from './interfaces'; import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" assert { type: 'json' }; @@ -382,3 +382,31 @@ export const voteForProposalEstimateGas = async (type: "PARAMETER" | "OWNERSHIP" export const voteForProposal = async (type: "PARAMETER" | "OWNERSHIP", id: number, support: boolean): Promise => { return await _voteForProposal(type, id, support, false) as string; } + +export const createEvmScript = async (address: string, abi: any, action: IDaoAction) => { + const agent = new Contract(address, abi, curve.signer || curve.provider) + console.log('1') + const zeroPad = (num: string, places: number) => + String(num).padStart(places, "0"); + + let evm_script = "0x00000001" + + const contract = new Contract(action.address, action.abi, curve.signer || curve.provider); + console.log('2') + const call_data = contract.interface.encodeFunctionData(action.method, [...action.args]) + console.log(call_data) + console.log('3') + const agent_calldata = agent.interface + .encodeFunctionData("execute", [action.address, 0, call_data]) + .substring(2); + + console.log('4') + + const length = zeroPad((Math.floor(agent_calldata.length) / 2).toString(16), 8); + + console.log('5') + + evm_script = `${evm_script}${address.substring(2)}${length}${agent_calldata}`; + + return evm_script +} diff --git a/src/index.ts b/src/index.ts index 5b3023cd..6a7aca09 100644 --- a/src/index.ts +++ b/src/index.ts @@ -124,7 +124,7 @@ import { getProposal, userProposalVotes, voteForProposalEstimateGas, - voteForProposal, + voteForProposal, createEvmScript, } from "./dao.js"; async function init ( @@ -356,6 +356,7 @@ const curve = { userProposalVotes, // Transaction methods voteForProposal, + createEvmScript, estimateGas: { // --- CRV lock --- diff --git a/src/interfaces.ts b/src/interfaces.ts index b9aadf70..a662f7aa 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -250,4 +250,11 @@ export interface IDaoProposal extends IDaoProposalListItem{ creatorVotingPower: number, script: string, votes: IDaoProposalVote[], +} + +export interface IDaoAction { + address: string, + abi: any, + method: string, + args: any[], } \ No newline at end of file