Skip to content

Commit 71a59fd

Browse files
committed
feat: add createEvmScript for new-vote
1 parent 973f4a2 commit 71a59fd

File tree

4 files changed

+100
-2
lines changed

4 files changed

+100
-2
lines changed

src/constants/dao/actions.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import {IDict} from "../../interfaces";
2+
import gaugeControllerABI from "../abis/gaugecontroller.json" assert { type: 'json' };
3+
import votingEscrowABI from '../abis/votingescrow.json' assert { type: 'json' };
4+
5+
export const DaoAbiDictionaries: Record<string, IDict<any>> = {
6+
//pools
7+
pools: {
8+
'commit_new_fee': 1,
9+
'ramp_A': 1,
10+
'commit_transfer_ownership': 1,
11+
'withdraw_admin_fees': 1,
12+
'unkill_me': 1,
13+
'apply_transfer_ownership': 1,
14+
'revert_transfer_ownership': 1,
15+
'apply_new_fee': 1,
16+
'stop_ramp_A': 1,
17+
'revert_new_parameters': 1,
18+
},
19+
gauges: {
20+
'commit_transfer_ownership': gaugeControllerABI,
21+
'add_type': gaugeControllerABI,
22+
'add_gauge': gaugeControllerABI,
23+
'change_type_weight': gaugeControllerABI,
24+
'change_gauge_weight': gaugeControllerABI,
25+
'apply_transfer_ownership': gaugeControllerABI,
26+
},
27+
member: {
28+
'mint': 1,
29+
'burn': 1,
30+
},
31+
escrow: {
32+
'commit_transfer_ownership': votingEscrowABI,
33+
'commit_smart_wallet_checker': votingEscrowABI,
34+
'apply_transfer_ownership': votingEscrowABI,
35+
'apply_smart_wallet_checker': votingEscrowABI,
36+
},
37+
poolProxy: {
38+
'commit_set_admins': 1,
39+
'set_burner': 1,
40+
'apply_set_admins': 1,
41+
},
42+
registry: {
43+
'add_pool': 1,
44+
'add_pool_without_underlying': 1,
45+
'remove_pool': 1,
46+
'set_returns_none': 1,
47+
'set_gas_estimate_contract': 1,
48+
'set_calculator': 1,
49+
'set_burner': 1,
50+
'apply_set_admins': 1,
51+
'commit_transfer_ownership': 1,
52+
'apply_transfer_ownership': 1,
53+
'revert_transfer_ownership': 1,
54+
'claim_token_balance': 1,
55+
'claim_eth_balance': 1,
56+
},
57+
vesting: {
58+
'fund_individual': 1,
59+
'toggle_disable': 1,
60+
'disable_can_disable': 1,
61+
},
62+
}

src/dao.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
IDaoProposalListItem,
1717
IDaoProposalUserListItem,
1818
IDaoProposal,
19-
IDict,
19+
IDict, IDaoAction,
2020
} from './interfaces';
2121
import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" assert { type: 'json' };
2222

@@ -382,3 +382,31 @@ export const voteForProposalEstimateGas = async (type: "PARAMETER" | "OWNERSHIP"
382382
export const voteForProposal = async (type: "PARAMETER" | "OWNERSHIP", id: number, support: boolean): Promise<string> => {
383383
return await _voteForProposal(type, id, support, false) as string;
384384
}
385+
386+
export const createEvmScript = async (address: string, abi: any, action: IDaoAction) => {
387+
const agent = new Contract(address, abi, curve.signer || curve.provider)
388+
console.log('1')
389+
const zeroPad = (num: string, places: number) =>
390+
String(num).padStart(places, "0");
391+
392+
let evm_script = "0x00000001"
393+
394+
const contract = new Contract(action.address, action.abi, curve.signer || curve.provider);
395+
console.log('2')
396+
const call_data = contract.interface.encodeFunctionData(action.method, [...action.args])
397+
console.log(call_data)
398+
console.log('3')
399+
const agent_calldata = agent.interface
400+
.encodeFunctionData("execute", [action.address, 0, call_data])
401+
.substring(2);
402+
403+
console.log('4')
404+
405+
const length = zeroPad((Math.floor(agent_calldata.length) / 2).toString(16), 8);
406+
407+
console.log('5')
408+
409+
evm_script = `${evm_script}${address.substring(2)}${length}${agent_calldata}`;
410+
411+
return evm_script
412+
}

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ import {
124124
getProposal,
125125
userProposalVotes,
126126
voteForProposalEstimateGas,
127-
voteForProposal,
127+
voteForProposal, createEvmScript,
128128
} from "./dao.js";
129129

130130
async function init (
@@ -356,6 +356,7 @@ const curve = {
356356
userProposalVotes,
357357
// Transaction methods
358358
voteForProposal,
359+
createEvmScript,
359360

360361
estimateGas: {
361362
// --- CRV lock ---

src/interfaces.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,11 @@ export interface IDaoProposal extends IDaoProposalListItem{
250250
creatorVotingPower: number,
251251
script: string,
252252
votes: IDaoProposalVote[],
253+
}
254+
255+
export interface IDaoAction {
256+
address: string,
257+
abi: any,
258+
method: string,
259+
args: any[],
253260
}

0 commit comments

Comments
 (0)