Skip to content

Commit

Permalink
Merge pull request #200 from neutron-org/feat/tokenfactory-update
Browse files Browse the repository at this point in the history
Update our tokenfactory to the latest version NTRN-93
  • Loading branch information
pr0n00gler authored Sep 20, 2023
2 parents 5ab2c66 + b81080d commit 7e6d67d
Show file tree
Hide file tree
Showing 11 changed files with 59,778 additions and 47,284 deletions.
79,429 changes: 43,977 additions & 35,452 deletions src/generated/proto.cjs

Large diffs are not rendered by default.

27,315 changes: 15,499 additions & 11,816 deletions src/generated/proto.d.ts

Large diffs are not rendered by default.

25 changes: 22 additions & 3 deletions src/helpers/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
PinnedCodesResponse,
IcaHostParamsResponse,
GlobalfeeParamsResponse,
InterchaintxsParamsResponse,
} from './types';
import { DEBUG_SUBMIT_TX, getContractBinary } from './env';
const adminmodule = AdminProto.adminmodule.adminmodule;
Expand Down Expand Up @@ -75,7 +76,6 @@ cosmosclient.codec.register(
'/cosmos.params.v1beta1.ParameterChangeProposal',
cosmosclient.proto.cosmos.params.v1beta1.ParameterChangeProposal,
);

cosmosclient.codec.register(
'/neutron.interchainqueries.MsgRemoveInterchainQueryRequest',
neutron.interchainqueries.MsgRemoveInterchainQueryRequest,
Expand Down Expand Up @@ -104,6 +104,10 @@ cosmosclient.codec.register(
'/pob.builder.v1.MsgAuctionBid',
pob.builder.v1.MsgAuctionBid,
);
cosmosclient.codec.register(
'/neutron.interchaintxs.v1.MsgUpdateParams',
neutron.interchaintxs.v1.MsgUpdateParams,
);

export class CosmosWrapper {
readonly sdk: cosmosclient.CosmosSDK;
Expand Down Expand Up @@ -396,6 +400,21 @@ export class CosmosWrapper {
}
}

async queryMaxTxsAllowed(): Promise<string> {
try {
const req = await axios.get<InterchaintxsParamsResponse>(
`${this.sdk.url}/neutron/interchaintxs/params`,
{},
);
return req.data.params.msg_submit_tx_max_messages;
} catch (e) {
if (e.response?.data?.message !== undefined) {
throw new Error(e.response?.data?.message);
}
throw e;
}
}

async queryGlobalfeeParams(): Promise<GlobalfeeParamsResponse> {
const req = await axios.get(
`${this.sdk.url}/gaia/globalfee/v1beta1/params`,
Expand Down Expand Up @@ -676,8 +695,8 @@ export class WalletWrapper {
}
| string,
fee = {
gas_limit: Long.fromString('200000'),
amount: [{ denom: this.chain.denom, amount: '1000' }],
gas_limit: Long.fromString('300000'),
amount: [{ denom: this.chain.denom, amount: '1500' }],
},
sequence: number = this.wallet.account.sequence,
mode: cosmosclient.rest.tx.BroadcastTxMode = cosmosclient.rest.tx
Expand Down
22 changes: 22 additions & 0 deletions src/helpers/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
SendProposalInfo,
unpinCodesProposal,
updateAdminProposal,
updateInterchaintxsParamsProposal,
upgradeProposal,
} from './proposal';
import { ibc } from '../generated/ibc/proto';
Expand Down Expand Up @@ -1208,6 +1209,27 @@ export class DaoMember {
);
}

/**
* submitUpdateParamsInterchaintxsProposal creates proposal which changes params of interchaintxs module.
*/

async submitUpdateParamsInterchaintxsProposal(
title: string,
description: string,
msgSubmitTxMaxMessages: number,
amount: string,
): Promise<number> {
const message = updateInterchaintxsParamsProposal({
msg_submit_tx_max_messages: msgSubmitTxMaxMessages,
});
return await this.submitSingleChoiceProposal(
title,
description,
[message],
amount,
);
}

/**
* submitClientUpdateProposal creates proposal which updates client.
*/
Expand Down
23 changes: 23 additions & 0 deletions src/helpers/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export type PinCodesInfo = {
codes_ids: number[];
};

export type UpdateParamsInterchaintxsInfo = {
msg_submit_tx_max_messages: number;
};
export type UpdateAdmin = {
sender: string;
contract: string;
Expand Down Expand Up @@ -192,6 +195,26 @@ export const unpinCodesProposal = (info: PinCodesInfo): any => ({
},
});

export const updateInterchaintxsParamsProposal = (
info: UpdateParamsInterchaintxsInfo,
): any => ({
custom: {
submit_admin_proposal: {
admin_proposal: {
proposal_execute_message: {
message: JSON.stringify({
'@type': '/neutron.interchaintxs.v1.MsgUpdateParams',
authority: ADMIN_MODULE_ADDRESS,
params: {
msg_submit_tx_max_messages: info.msg_submit_tx_max_messages,
},
}),
},
},
},
},
});

export const updateAdminProposal = (info: UpdateAdmin): any => ({
custom: {
submit_admin_proposal: {
Expand Down
38 changes: 33 additions & 5 deletions src/helpers/tokenfactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ cosmosclient.codec.register(
'/osmosis.tokenfactory.v1beta1.MsgChangeAdmin',
osmosis.tokenfactory.v1beta1.MsgChangeAdmin,
);
cosmosclient.codec.register(
'/osmosis.tokenfactory.v1beta1.MsgSetBeforeSendHook',
osmosis.tokenfactory.v1beta1.MsgSetBeforeSendHook,
);

export const msgMintDenom = async (
cmNeutron: WalletWrapper,
Expand Down Expand Up @@ -55,8 +59,8 @@ export const msgCreateDenom = async (
});
const res = await cmNeutron.execTx(
{
gas_limit: Long.fromString('200000'),
amount: [{ denom: cmNeutron.chain.denom, amount: '1000' }],
gas_limit: Long.fromString('2000000'),
amount: [{ denom: cmNeutron.chain.denom, amount: '5000' }],
},
[msgCreateDenom],
10,
Expand All @@ -77,11 +81,12 @@ export const msgBurn = async (
denom: denom,
amount: amountToBurn,
},
burnFromAddress: creator,
});
const res = await cmNeutron.execTx(
{
gas_limit: Long.fromString('200000'),
amount: [{ denom: cmNeutron.chain.denom, amount: '1000' }],
amount: [{ denom: cmNeutron.chain.denom, amount: '5000' }],
},
[msgBurn],
10,
Expand All @@ -100,16 +105,39 @@ export const msgChangeAdmin = async (
const msgChangeAdmin = new osmosis.tokenfactory.v1beta1.MsgChangeAdmin({
sender: creator,
denom,
newAdmin,
new_admin: newAdmin,
});
const res = await cmNeutron.execTx(
{
gas_limit: Long.fromString('200000'),
amount: [{ denom: cmNeutron.chain.denom, amount: '1000' }],
amount: [{ denom: cmNeutron.chain.denom, amount: '5000' }],
},
[msgChangeAdmin],
10,
);

return res.tx_response!;
};

export const msgSetBeforeSendHook = async (
cmNeutron: WalletWrapper,
creator: string,
denom: string,
contractAddr: string,
): Promise<BroadcastTx200ResponseTxResponse> => {
const msgMint = new osmosis.tokenfactory.v1beta1.MsgSetBeforeSendHook({
sender: creator,
denom,
contract_addr: contractAddr,
});
const res = await cmNeutron.execTx(
{
gas_limit: Long.fromString('200000'),
amount: [{ denom: cmNeutron.chain.denom, amount: '1000' }],
},
[msgMint],
10,
);

return res.tx_response!;
};
7 changes: 7 additions & 0 deletions src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export const NeutronContract = {
VESTING_INVESTORS: 'vesting_investors.wasm',
INVESTORS_VESTING_VAULT: 'investors_vesting_vault.wasm',
TOKENFACTORY: 'tokenfactory.wasm',
BEFORE_SEND_HOOK_TEST: 'before_send_hook_test.wasm',
};

export type MultiChoiceOption = {
Expand Down Expand Up @@ -265,6 +266,12 @@ export type IcaHostParamsResponse = {
};
};

export type InterchaintxsParamsResponse = {
params: {
msg_submit_tx_max_messages: string;
};
};

export type GlobalfeeParamsResponse = {
minimum_gas_prices: cosmos.base.v1beta1.ICoin[];
bypass_min_fee_msg_types: string[];
Expand Down
34 changes: 34 additions & 0 deletions src/testcases/parallel/governance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,15 @@ describe('Neutron / Governance', () => {
);
});

test('create proposal #20, will pass', async () => {
await daoMember1.submitUpdateParamsInterchaintxsProposal(
'Proposal #20',
'Update interchaintxs params',
11,
'1000',
);
});

test('create multi-choice proposal #2, will be rejected', async () => {
await daoMember1.submitMultiChoiceParameterChangeProposal(
[
Expand Down Expand Up @@ -1035,6 +1044,31 @@ describe('Neutron / Governance', () => {
});
});

describe('vote for proposal #20 with unbonded funds(no, yes, yes)', () => {
const proposalId = 20;
test('vote NO from wallet 1', async () => {
await daoMember1.voteNo(proposalId);
});
test('vote YES from wallet 2', async () => {
await daoMember2.voteYes(proposalId);
});
test('vote YES from wallet 3', async () => {
await daoMember3.voteYes(proposalId);
});
});

describe('try to execute proposal #20', () => {
const proposalId = 20;
test('check if proposal is passed', async () => {
await dao.checkPassedProposal(proposalId);
});
test('execute passed proposal', async () => {
await daoMember1.executeProposalWithAttempts(proposalId);
const paramAfter = await neutronChain.queryMaxTxsAllowed();
expect(paramAfter).toEqual('11');
});
});

describe('check that only admin can create valid proposals', () => {
test('submit admin proposal from non-admin addr, should fail', async () => {
const res = await daoMember1.user.msgSendDirectProposal(
Expand Down
3 changes: 1 addition & 2 deletions src/testcases/parallel/stargate_queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ describe('Neutron / Simple', () => {

test('tokenfactory params should work', async () => {
const res = JSON.parse(await querySmart({ tokenfactory_params: {} }));
expect(res.params.denom_creation_fee[0].denom).toBe('untrn');
expect(res.params.denom_creation_fee[0].amount).toBe('1000000');
expect(res.params.denom_creation_gas_consume).toBe('0');
});

test('tokenfactory denom authority metadata should work', async () => {
Expand Down
Loading

0 comments on commit 7e6d67d

Please sign in to comment.