Skip to content

Commit

Permalink
feat: add createEvmScript for new-vote
Browse files Browse the repository at this point in the history
  • Loading branch information
fedorovdg committed Jan 4, 2024
1 parent 973f4a2 commit 71a59fd
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 2 deletions.
62 changes: 62 additions & 0 deletions src/constants/dao/actions.ts
Original file line number Diff line number Diff line change
@@ -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<string, IDict<any>> = {
//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,
},
}
30 changes: 29 additions & 1 deletion src/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' };

Expand Down Expand Up @@ -382,3 +382,31 @@ export const voteForProposalEstimateGas = async (type: "PARAMETER" | "OWNERSHIP"
export const voteForProposal = async (type: "PARAMETER" | "OWNERSHIP", id: number, support: boolean): Promise<string> => {
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
}
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ import {
getProposal,
userProposalVotes,
voteForProposalEstimateGas,
voteForProposal,
voteForProposal, createEvmScript,
} from "./dao.js";

async function init (
Expand Down Expand Up @@ -356,6 +356,7 @@ const curve = {
userProposalVotes,
// Transaction methods
voteForProposal,
createEvmScript,

estimateGas: {
// --- CRV lock ---
Expand Down
7 changes: 7 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
}

0 comments on commit 71a59fd

Please sign in to comment.