Skip to content

Commit

Permalink
Merge pull request #147 from terra-money/proposal/register-fee-sharing
Browse files Browse the repository at this point in the history
Proposal/register fee sharing
  • Loading branch information
vladjdk authored Nov 16, 2023
2 parents d98fdbc + 641e10f commit a21ebab
Show file tree
Hide file tree
Showing 11 changed files with 681 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apps/enterprise/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@hookform/resolvers": "^2.9.7",
"@sentry/integrations": "^7.52.1",
"@sentry/react": "^7.52.1",
"@terra-money/feather.js": "^1.0.4",
"@terra-money/feather.js": "^1.0.8",
"@terra-money/log-finder-ruleset": "^3.0.2",
"@terra-money/terra-station-mobile": "1.0.8",
"@terra-money/wallet-kit": "1.0.11",
Expand Down
7 changes: 7 additions & 0 deletions apps/enterprise/src/chain/CosmWasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@ export interface WasmMigrateMsg {
}
}

export interface StargateMsg {
stargate: {
type_url: string,
value: string
}
}

export type CosmWasmMsg = BankSendMsg | DelegateMsg | UndelegateMsg | RedelegateMsg | WasmExecuteMsg | WasmInstantiateMsg | WasmMigrateMsg
4 changes: 4 additions & 0 deletions apps/enterprise/src/dao/shared/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const sharedProposalTypes = [
'redelegate',
'council',
'minWeightForRewards',
'registerFeeShare',
] as const;

export const daoProposalsRecord = {
Expand Down Expand Up @@ -68,6 +69,7 @@ export const proposalTitle: Record<ProposalType, string> = {
redelegate: 'Redelegate LUNA',
council: 'Update council',
minWeightForRewards: 'Update minimum weight for rewards',
registerFeeShare: 'Register an address for fee sharing'
};

export const proposalActionTypeName = [
Expand All @@ -82,6 +84,7 @@ export const proposalActionTypeName = [
'members',
'distribute',
'min weight',
'fee share',
'text',
'other',
] as const;
Expand All @@ -100,6 +103,7 @@ export const proposalActionShortName: Record<enterprise.ProposalActionType, Prop
modify_multisig_membership: 'members',
distribute_funds: 'distribute',
update_minimum_weight_for_rewards: 'min weight',
register_fee_share: 'fee share'
};

export const getProposalActionType = (action: enterprise.ProposalAction): enterprise.ProposalActionType => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { Center } from 'lib/ui/Center';
import { Spinner } from 'lib/ui/Spinner';
import { Text } from 'lib/ui/Text';
import { CreateProposalProvider } from './CreateProposalProvider';
import { RegisterFeeShareProposalPage } from './register-fee-share/RegisterFeeShareProposalPage';

type CreateProposalPageParams = {
type: ProposalType;
Expand Down Expand Up @@ -103,6 +104,7 @@ export const CreateProposalPageContent = () => {
undelegate={() => <UndelegateProposalForm />}
redelegate={() => <RedelegateProposalForm />}
minWeightForRewards={() => <MinimumWeightForRewardsProposalPage />}
registerFeeShare={() => <RegisterFeeShareProposalPage />}
/>
</CurrentDaoProvider>
</Container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const proposalDescription: Record<ProposalType, ReactNode> = {
mintNft:
'Mint a new DAO NFT to the specified addresses. This proposal will only work if the minter on the NFT contract is the DAO treasury address.',
minWeightForRewards: 'Update the minimum weight required to receive rewards.',
registerFeeShare: 'Register a contract address that was created by the DAO for fee sharing.'
};

// TODO: turn into a reusable component
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { ProposalForm } from '../shared/ProposalForm';
import * as z from 'zod';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { toRegisterFeeShareMsg } from './helpers/toRegisterFeeShareMsg';
import { VStack } from 'lib/ui/Stack';
import { TextInput } from 'lib/ui/inputs/TextInput';
import { zodAddressValidator } from 'chain/utils/validators';
import { useCurrentDao } from 'dao/components/CurrentDaoProvider';

interface RegisterFeeShareProposalFormSchema {
contractAddress: string;
withdrawerAddress: string;
}

export const RegisterFeeShareProposalForm = () => {
const dao = useCurrentDao();



const formSchema: z.ZodType<RegisterFeeShareProposalFormSchema> = z.object({
contractAddress: zodAddressValidator,
withdrawerAddress: zodAddressValidator
});

const {
formState: { isValid },
getValues,
register,
} = useForm<RegisterFeeShareProposalFormSchema>({
mode: 'all',
resolver: zodResolver(formSchema),
});

return (
<ProposalForm
disabled={!isValid}
getProposalActions={() => {
const { contractAddress, withdrawerAddress } = getValues();
return [
{
execute_msgs: {
action_type: 'register-fee-share',
msgs: [
toRegisterFeeShareMsg({
contractAddress,
deployerAddress: dao.address,
withdrawerAddress,
}),
],
},
},
];
}}
>
<VStack alignItems="start" gap={8}>
<TextInput {...register('contractAddress')} label="Contract address" placeholder="Enter a DAO-owned address" />
<TextInput {...register('withdrawerAddress')} label="Withdrawer address" placeholder="Enter an address to whitelist for fee withdrawal" />
</VStack>
</ProposalForm>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { RegisterFeeShareProposalForm } from './RegisterFeeShareProposalForm';

export const RegisterFeeShareProposalPage = () => {
return (
<RegisterFeeShareProposalForm />
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { StargateMsg } from 'chain/CosmWasm';
import { MsgRegisterFeeShare } from '@terra-money/feather.js';


interface RegisterFeeShareParams {
contractAddress: string
deployerAddress: string,
withdrawerAddress: string;
}

export const toRegisterFeeShareMsg = ({ contractAddress, deployerAddress, withdrawerAddress }: RegisterFeeShareParams) => {

const registerMsg = new MsgRegisterFeeShare(contractAddress, deployerAddress, withdrawerAddress);
const packed = registerMsg.packAny();


const msg: StargateMsg = {
stargate: {
type_url: packed.typeUrl,
value: Buffer.from(packed.value).toString("base64")
}
};

return JSON.stringify(msg);
};
1 change: 1 addition & 0 deletions apps/enterprise/src/pages/proposal/ProposalActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const ProposalActions = () => {
<UpdateMultisigMembersAction />
</CurrentDAOMultisigMembersProvider>
)}
register_fee_share={() => null}
/>
</CurrentProposalActionProvider>
);
Expand Down
3 changes: 2 additions & 1 deletion apps/enterprise/src/types/contracts/enterprise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ export module enterprise {
| 'execute_msgs'
| 'modify_multisig_membership'
| 'distribute_funds'
| 'update_minimum_weight_for_rewards';
| 'update_minimum_weight_for_rewards'
| 'register_fee_share';
export type Binary = string;
export interface CreateProposalMsg {
/**
Expand Down
Loading

0 comments on commit a21ebab

Please sign in to comment.