Skip to content

Commit

Permalink
feat: updated factory
Browse files Browse the repository at this point in the history
  • Loading branch information
ratik committed Dec 18, 2023
1 parent e4b4d49 commit 91bd23f
Show file tree
Hide file tree
Showing 7 changed files with 499 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

schema:
@find contracts/* -maxdepth 2 -type f -name Cargo.toml -execdir cargo schema \;
@cd integration_tests && yarn build-ts-client
test:
@cargo test

Expand All @@ -27,6 +28,7 @@ compile_arm64:
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
--platform linux/arm64 \
cosmwasm/workspace-optimizer-arm64:0.15.0
@cd artifacts && for file in *-aarch64.wasm; do cp -f "$$file" "${file%-aarch64.wasm}.wasm"; done

check_contracts:
@cargo install cosmwasm-check
Expand Down
32 changes: 29 additions & 3 deletions contracts/factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ use cosmwasm_std::{
Deps, DepsMut, Env, HexBinary, MessageInfo, Response, StdResult, WasmMsg,
};
use cw2::set_contract_version;
use lido_staking_base::msg::token::InstantiateMsg as TokenInstantiateMsg;

use lido_staking_base::{
helpers::answer::response, msg::core::InstantiateMsg as CoreInstantiateMsg,
msg::token::InstantiateMsg as TokenInstantiateMsg,
msg::voucher::InstantiateMsg as VoucherInstantiateMsg,
};
use neutron_sdk::{
bindings::{msg::NeutronMsg, query::NeutronQuery},
Expand All @@ -35,6 +37,7 @@ pub fn instantiate(
salt: msg.salt.to_string(),
token_code_id: msg.token_code_id,
core_code_id: msg.core_code_id,
voucher_code_id: msg.voucher_code_id,
owner: info.sender.to_string(),
subdenom: msg.subdenom.to_string(),
},
Expand All @@ -44,6 +47,7 @@ pub fn instantiate(
attr("salt", msg.salt),
attr("token_code_id", msg.token_code_id.to_string()),
attr("core_code_id", msg.core_code_id.to_string()),
attr("voucher_code_id", msg.voucher_code_id.to_string()),
attr("owner", info.sender),
attr("subdenom", msg.subdenom),
];
Expand Down Expand Up @@ -80,6 +84,7 @@ fn execute_init(

let token_contract_checksum = get_code_checksum(deps.as_ref(), config.token_code_id)?;
let core_contract_checksum = get_code_checksum(deps.as_ref(), config.core_code_id)?;
let voucher_contract_checksum = get_code_checksum(deps.as_ref(), config.voucher_code_id)?;
let salt = config.salt.as_bytes();

let token_address =
Expand All @@ -88,20 +93,25 @@ fn execute_init(
let core_address =
instantiate2_address(&core_contract_checksum, &canonical_self_address, salt)?;
attrs.push(attr("core_address", core_address.to_string()));
let voucher_address =
instantiate2_address(&voucher_contract_checksum, &canonical_self_address, salt)?;
attrs.push(attr("voucher_address", voucher_address.to_string()));

let core_contract = deps.api.addr_humanize(&core_address)?.to_string();
let token_contract = deps.api.addr_humanize(&token_address)?.to_string();
let voucher_contract = deps.api.addr_humanize(&voucher_address)?.to_string();
let state = State {
token_contract: token_contract.to_string(),
core_contract: core_contract.to_string(),
voucher_contract: voucher_contract.to_string(),
};

STATE.save(deps.storage, &state)?;
let msgs = vec![
CosmosMsg::Wasm(WasmMsg::Instantiate2 {
admin: Some(env.contract.address.to_string()),
code_id: config.token_code_id,
label: "token".to_string(),
label: get_contract_label("token"),
msg: to_json_binary(&TokenInstantiateMsg {
core_address: core_contract,
subdenom: config.subdenom,
Expand All @@ -112,7 +122,7 @@ fn execute_init(
CosmosMsg::Wasm(WasmMsg::Instantiate2 {
admin: Some(env.contract.address.to_string()),
code_id: config.core_code_id,
label: "core".to_string(),
label: get_contract_label("core"),
msg: to_json_binary(&CoreInstantiateMsg {
token_contract: token_contract.to_string(),
puppeteer_contract: "".to_string(),
Expand All @@ -122,6 +132,18 @@ fn execute_init(
funds: vec![],
salt: Binary::from(salt),
}),
CosmosMsg::Wasm(WasmMsg::Instantiate2 {
admin: Some(env.contract.address.to_string()),
code_id: config.voucher_code_id,
label: get_contract_label("voucher"),
msg: to_json_binary(&VoucherInstantiateMsg {
name: "Lido Voucher".to_string(),
symbol: "LDOV".to_string(),
minter: core_address.to_string(),
})?,
funds: vec![],
salt: Binary::from(salt),
}),
];

Ok(response("execute-init", CONTRACT_NAME, attrs).add_messages(msgs))
Expand All @@ -131,3 +153,7 @@ fn get_code_checksum(deps: Deps, code_id: u64) -> NeutronResult<HexBinary> {
let CodeInfoResponse { checksum, .. } = deps.querier.query_wasm_code_info(code_id)?;
Ok(checksum)
}

fn get_contract_label(base: &str) -> String {
format!("LIDO-staking-{}", base)
}
1 change: 1 addition & 0 deletions contracts/factory/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::state::State;
pub struct InstantiateMsg {
pub token_code_id: u64,
pub core_code_id: u64,
pub voucher_code_id: u64,
pub salt: String,
pub subdenom: String,
}
Expand Down
2 changes: 2 additions & 0 deletions contracts/factory/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use cw_storage_plus::Item;
pub struct Config {
pub token_code_id: u64,
pub core_code_id: u64,
pub voucher_code_id: u64,
pub owner: String,
pub salt: String,
pub subdenom: String,
Expand All @@ -14,6 +15,7 @@ pub struct Config {
pub struct State {
pub token_contract: String,
pub core_contract: String,
pub voucher_contract: String,
}

pub const CONFIG: Item<Config> = Item::new("config");
Expand Down
3 changes: 3 additions & 0 deletions integration_tests/src/generated/contractLib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ export const LidoValidatorsSet = _8;

import * as _9 from './lidoValidatorsStats';
export const LidoValidatorsStats = _9;

import * as _10 from './lidoWithdrawalVoucher';
export const LidoWithdrawalVoucher = _10;
2 changes: 2 additions & 0 deletions integration_tests/src/generated/contractLib/lidoFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface InstantiateMsg {
salt: string;
subdenom: string;
token_code_id: number;
voucher_code_id: number;
}
export interface LidoFactorySchema {
responses: State;
Expand All @@ -14,6 +15,7 @@ export interface LidoFactorySchema {
export interface State {
core_contract: string;
token_contract: string;
voucher_contract: string;
}


Expand Down
Loading

0 comments on commit 91bd23f

Please sign in to comment.