@@ -3,7 +3,10 @@ import { Contract } from "ethers";
33import { _getAllGauges , _getDaoProposalList , _getDaoProposal } from './external-api.js' ;
44import {
55 _getAddress ,
6- DIGas , ensureAllowance , ensureAllowanceEstimateGas , hasAllowance ,
6+ DIGas ,
7+ ensureAllowance ,
8+ ensureAllowanceEstimateGas ,
9+ hasAllowance ,
710 mulBy1_3 ,
811 parseUnits ,
912 smartNumber ,
@@ -17,8 +20,14 @@ import {
1720 IDaoProposalUserListItem ,
1821 IDaoProposal ,
1922 IDict ,
23+ IDaoAction ,
24+ TDaoActionType ,
25+ TDaoAvailableMethodsOfPool ,
2026} from './interfaces' ;
2127import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" assert { type : 'json' } ;
28+ import { poolActions } from "./constants/dao/actions" ;
29+ import gaugeControllerABI from "./constants/abis/gaugecontroller.json" ;
30+ import axios from "axios" ;
2231
2332
2433// ----------------- Refactored boosting stuff -----------------
@@ -382,3 +391,75 @@ export const voteForProposalEstimateGas = async (type: "PARAMETER" | "OWNERSHIP"
382391export const voteForProposal = async ( type : "PARAMETER" | "OWNERSHIP" , id : number , support : boolean ) : Promise < string > => {
383392 return await _voteForProposal ( type , id , support , false ) as string ;
384393}
394+
395+ export const getAvailableMethodsOfPool = ( address : string ) :TDaoAvailableMethodsOfPool => {
396+ const result : TDaoAvailableMethodsOfPool = { } ;
397+ poolActions . forEach ( ( item ) => {
398+ if ( curve . contracts [ address ] . contract . interface . fragments . find ( ( method : any ) => method . name === item ) ) {
399+ result [ item ] = true ;
400+ } else {
401+ result [ item ] = false ;
402+ }
403+ } )
404+
405+ return result ;
406+ }
407+
408+ export const createActionForVote = ( actionType : TDaoActionType , address : string , method : string , args : any [ ] ) : IDaoAction => {
409+ if ( actionType === 'pools' ) {
410+ if ( ! getAvailableMethodsOfPool ( address ) [ method ] ) {
411+ throw Error ( `Method ${ { method} } is not available for this pool` ) ;
412+ } else {
413+ return {
414+ address,
415+ contract : curve . contracts [ address ] . contract ,
416+ method,
417+ args,
418+ }
419+ }
420+ }
421+ if ( actionType === 'gauges' ) {
422+ return {
423+ address,
424+ contract : new Contract ( address , gaugeControllerABI , curve . signer || curve . provider ) ,
425+ method,
426+ args,
427+ }
428+ }
429+
430+ throw Error ( 'Unavailable pool type' )
431+ }
432+
433+ export const createEvmScript = async ( address : string , abi : any , action : IDaoAction ) => {
434+ const agent = new Contract ( address , abi , curve . signer || curve . provider )
435+ const zeroPad = ( num : string , places : number ) =>
436+ String ( num ) . padStart ( places , "0" ) ;
437+
438+ let evm_script = "0x00000001"
439+
440+ const contract = action . contract ;
441+ const call_data = contract . interface . encodeFunctionData ( action . method , [ ...action . args ] )
442+
443+ const agent_calldata = agent . interface
444+ . encodeFunctionData ( "execute" , [ action . address , 0 , call_data ] )
445+ . substring ( 2 ) ;
446+
447+ const length = zeroPad ( ( Math . floor ( agent_calldata . length ) / 2 ) . toString ( 16 ) , 8 ) ;
448+
449+ evm_script = `${ evm_script } ${ address . substring ( 2 ) } ${ length } ${ agent_calldata } ` ;
450+
451+ return evm_script
452+ }
453+
454+ export const createVoteDescription = async ( description : string ) => {
455+ const vote_description = description . replace ( / ( \r \n | \n | \r ) / gm, "" ) ;
456+ const vote_data = {
457+ text : vote_description ,
458+ } ;
459+
460+ const data = new FormData ( ) ;
461+ data . append ( "file" , JSON . stringify ( vote_data ) ) ;
462+ const url = `https://ipfs.infura.io:5001/api/v0/add` ;
463+ const response = await axios . post ( url , data ) ;
464+ return response . data . Hash ;
465+ }
0 commit comments