Skip to content

Commit

Permalink
Merge pull request #37 from hadronlabs-org/feat/factory-proxy-all
Browse files Browse the repository at this point in the history
Feat/factory proxy all
  • Loading branch information
oldremez authored Feb 26, 2024
2 parents 7114df3 + 95e8763 commit 8d7d9f9
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runner_label: ${{ fromJSON('["lionco-runner-1", "lionco-runner-2", "lionco-runner-3", "lionco-runner-4", "lionco-runner-5", "lionco-runner-6"]') }}
steps:
- name: Stop old containers
run: docker ps -q | grep -q . && docker stop $(docker ps -q) || echo "No containers to stop"
run: docker ps -q | grep -q . && docker stop $(docker ps -q) -t0 || echo "No containers to stop"
- name: Remove old containers
run: docker ps -a -q | grep -q . && docker rm $(docker ps -a -q) || echo "No containers to remove"
- name: Delete old images
Expand Down
18 changes: 18 additions & 0 deletions contracts/factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,27 @@ pub fn execute(
},
ExecuteMsg::UpdateConfig(msg) => execute_update_config(deps, env, info, *msg),
ExecuteMsg::Proxy(msg) => execute_proxy_msg(deps, env, info, msg),
ExecuteMsg::AdminExecute { addr, msg } => execute_admin_execute(deps, env, info, addr, msg),
}
}

fn execute_admin_execute(
deps: DepsMut,
_env: Env,
info: MessageInfo,
addr: String,
msg: Binary,
) -> ContractResult<Response<NeutronMsg>> {
let attrs = vec![attr("action", "admin-execute")];
cw_ownable::assert_owner(deps.storage, &info.sender)?;
let msg = CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: addr,
msg,
funds: vec![],
});
Ok(response("execute-admin", CONTRACT_NAME, attrs).add_message(msg))
}

fn execute_update_config(
deps: DepsMut,
_env: Env,
Expand Down
6 changes: 5 additions & 1 deletion contracts/factory/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::state::{CodeIds, RemoteOpts};
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::Uint128;
use cosmwasm_std::{Binary, Uint128};
use lido_staking_base::msg::token::DenomMetadata;

#[cw_serde]
Expand Down Expand Up @@ -65,6 +65,10 @@ pub enum ExecuteMsg {
Callback(CallbackMsg),
UpdateConfig(Box<UpdateConfigMsg>),
Proxy(ProxyMsg),
AdminExecute {
addr: String,
msg: Binary,
},
}
#[cw_serde]
pub enum MigrateMsg {}
Expand Down
14 changes: 13 additions & 1 deletion contracts/puppeteer/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use lido_puppeteer_base::{
},
};
use lido_staking_base::{
msg::puppeteer::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryExtMsg},
msg::puppeteer::{ExecuteMsg, FeesResponse, InstantiateMsg, MigrateMsg, QueryExtMsg},
state::puppeteer::{Config, KVQueryType, DELEGATIONS_AND_BALANCE},
};
use neutron_sdk::interchain_queries::v045::new_register_delegator_unbonding_delegations_query_msg;
Expand Down Expand Up @@ -115,11 +115,23 @@ pub fn query(
.collect::<StdResult<Vec<_>>>()?,
)
.map_err(ContractError::Std),
QueryExtMsg::Fees {} => query_fees(deps),
},
_ => Puppeteer::default().query(deps, env, msg),
}
}

fn query_fees(deps: Deps<NeutronQuery>) -> ContractResult<Binary> {
let fees = Puppeteer::default().ibc_fee.load(deps.storage)?;
let register_fee = Puppeteer::default().register_fee.load(deps.storage)?;
Ok(to_json_binary(&FeesResponse {
recv_fee: fees.recv_fee,
ack_fee: fees.ack_fee,
timeout_fee: fees.timeout_fee,
register_fee,
})?)
}

fn query_delegations(deps: Deps<NeutronQuery>) -> ContractResult<Binary> {
let data = DELEGATIONS_AND_BALANCE.load(deps.storage)?;
to_json_binary(&(data.0, data.2)).map_err(ContractError::Std)
Expand Down
16 changes: 15 additions & 1 deletion integration_tests/src/generated/contractLib/lidoFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,16 @@ export type ValidatorSetMsg =
validator: ValidatorData;
};
};
/**
* Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.
*
* This is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>. See also <https://github.com/CosmWasm/cosmwasm/blob/main/docs/MESSAGE_TYPES.md>.
*/
export type Binary = string;

export interface LidoFactorySchema {
responses: State;
execute: InitArgs | CallbackArgs | UpdateConfigArgs | ProxyArgs;
execute: InitArgs | CallbackArgs | UpdateConfigArgs | ProxyArgs | AdminExecuteArgs;
[k: string]: unknown;
}
export interface State {
Expand Down Expand Up @@ -168,6 +174,10 @@ export interface ValidatorData {
valoper_address: string;
weight: number;
}
export interface AdminExecuteArgs {
addr: string;
msg: Binary;
}


function isSigningCosmWasmClient(
Expand Down Expand Up @@ -219,4 +229,8 @@ export class Client {
if (!isSigningCosmWasmClient(this.client)) { throw this.mustBeSigningClient(); }
return this.client.execute(sender, this.contractAddress, { proxy: args }, fee || "auto", memo, funds);
}
adminExecute = async(sender:string, args: AdminExecuteArgs, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]): Promise<ExecuteResult> => {
if (!isSigningCosmWasmClient(this.client)) { throw this.mustBeSigningClient(); }
return this.client.execute(sender, this.contractAddress, { admin_execute: args }, fee || "auto", memo, funds);
}
}
3 changes: 3 additions & 0 deletions integration_tests/src/generated/contractLib/lidoPuppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ export type QueryExtMsg =
| {
balances: {};
}
| {
fees: {};
}
| {
unbonding_delegations: {};
};
Expand Down
41 changes: 35 additions & 6 deletions integration_tests/src/testcases/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,18 +435,49 @@ describe('Core', () => {
);
});
it('set fees for puppeteer', async () => {
const { neutronUserAddress, factoryContractClient: contractClient } =
context;
const res = await contractClient.updateConfig(neutronUserAddress, {
const { neutronUserAddress, factoryContractClient } = context;
const res = await factoryContractClient.updateConfig(neutronUserAddress, {
puppeteer_fees: {
timeout_fee: '10000',
timeout_fee: '20000',
ack_fee: '10000',
recv_fee: '0',
register_fee: '1000000',
},
});
expect(res.transactionHash).toHaveLength(64);
});
it('update by factory admin execute', async () => {
const { neutronUserAddress, factoryContractClient: contractClient } =
context;
const res = await contractClient.adminExecute(
neutronUserAddress,
{
addr: context.puppeteerContractClient.contractAddress,
msg: Buffer.from(
JSON.stringify({
set_fees: {
timeout_fee: '10000',
ack_fee: '10000',
recv_fee: '0',
register_fee: '1000000',
},
}),
).toString('base64'),
},
1.5,
);
expect(res.transactionHash).toHaveLength(64);
const fees: any = await context.puppeteerContractClient.queryExtention({
msg: { fees: {} },
});
expect(fees).toEqual({
recv_fee: [{ denom: 'untrn', amount: '0' }],
ack_fee: [{ denom: 'untrn', amount: '10000' }],
timeout_fee: [{ denom: 'untrn', amount: '10000' }],
register_fee: { denom: 'untrn', amount: '1000000' },
});
});

it('register ICA', async () => {
const { puppeteerContractClient, neutronUserAddress } = context;
const res = await puppeteerContractClient.registerICA(
Expand Down Expand Up @@ -632,7 +663,6 @@ describe('Core', () => {
owner: context.neutronUserAddress,
});
expect(vouchers.tokens.length).toBe(2);

expect(vouchers.tokens[0]).toBe(`0_${neutronUserAddress}_1`);
let tokenId = vouchers.tokens[0];
let voucher = await withdrawalVoucherContractClient.queryNftInfo({
Expand Down Expand Up @@ -671,7 +701,6 @@ describe('Core', () => {
},
token_uri: null,
});

expect(vouchers.tokens[1]).toBe(`0_${neutronUserAddress}_2`);
tokenId = vouchers.tokens[1];
voucher = await withdrawalVoucherContractClient.queryNftInfo({
Expand Down
10 changes: 10 additions & 0 deletions packages/base/src/msg/puppeteer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,23 @@ pub type DelegationsResponse = (Delegations, u64);

pub type BalancesResponse = (Balances, u64);

#[cw_serde]
pub struct FeesResponse {
pub recv_fee: Vec<cosmwasm_std::Coin>,
pub ack_fee: Vec<cosmwasm_std::Coin>,
pub timeout_fee: Vec<cosmwasm_std::Coin>,
pub register_fee: cosmwasm_std::Coin,
}

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryExtMsg {
#[returns(DelegationsResponse)]
Delegations {},
#[returns(BalancesResponse)]
Balances {},
#[returns(FeesResponse)]
Fees {},
#[returns(Vec<lido_puppeteer_base::state::UnbondingDelegation>)]
UnbondingDelegations {},
}

0 comments on commit 8d7d9f9

Please sign in to comment.