diff --git a/contracts/factory/src/contract.rs b/contracts/factory/src/contract.rs index a2654547..c07599a7 100644 --- a/contracts/factory/src/contract.rs +++ b/contracts/factory/src/contract.rs @@ -419,7 +419,7 @@ fn execute_init( }), CosmosMsg::Wasm(WasmMsg::Instantiate2 { admin: Some(env.contract.address.to_string()), - code_id: config.rewards_manager_code_id, + code_id: config.code_ids.rewards_manager_code_id, label: get_contract_label("rewards manager"), msg: to_json_binary(&RewardsMangerInstantiateMsg { core_address: core_contract.to_string(), diff --git a/integration_tests/src/generated/contractLib/index.ts b/integration_tests/src/generated/contractLib/index.ts index aa66fc85..61e2564b 100644 --- a/integration_tests/src/generated/contractLib/index.ts +++ b/integration_tests/src/generated/contractLib/index.ts @@ -1,41 +1,47 @@ -import * as _0 from './lidoCore'; -export const LidoCore = _0; +import * as _0 from './lidoAstroportExchangeHandler'; +export const LidoAstroportExchangeHandler = _0; -import * as _1 from './lidoDistribution'; -export const LidoDistribution = _1; +import * as _1 from './lidoCore'; +export const LidoCore = _1; -import * as _2 from './lidoFactory'; -export const LidoFactory = _2; +import * as _2 from './lidoDistribution'; +export const LidoDistribution = _2; -import * as _3 from './lidoHookTester'; -export const LidoHookTester = _3; +import * as _3 from './lidoFactory'; +export const LidoFactory = _3; -import * as _4 from './lidoPump'; -export const LidoPump = _4; +import * as _4 from './lidoHookTester'; +export const LidoHookTester = _4; -import * as _5 from './lidoPuppeteerAuthz'; -export const LidoPuppeteerAuthz = _5; +import * as _5 from './lidoPump'; +export const LidoPump = _5; -import * as _6 from './lidoPuppeteer'; -export const LidoPuppeteer = _6; +import * as _6 from './lidoPuppeteerAuthz'; +export const LidoPuppeteerAuthz = _6; -import * as _7 from './lidoStargatePoc'; -export const LidoStargatePoc = _7; +import * as _7 from './lidoPuppeteer'; +export const LidoPuppeteer = _7; -import * as _8 from './lidoStrategy'; -export const LidoStrategy = _8; +import * as _8 from './lidoRewardsManager'; +export const LidoRewardsManager = _8; -import * as _9 from './lidoToken'; -export const LidoToken = _9; +import * as _9 from './lidoStargatePoc'; +export const LidoStargatePoc = _9; -import * as _10 from './lidoValidatorsSet'; -export const LidoValidatorsSet = _10; +import * as _10 from './lidoStrategy'; +export const LidoStrategy = _10; -import * as _11 from './lidoValidatorsStats'; -export const LidoValidatorsStats = _11; +import * as _11 from './lidoToken'; +export const LidoToken = _11; -import * as _12 from './lidoWithdrawalManager'; -export const LidoWithdrawalManager = _12; +import * as _12 from './lidoValidatorsSet'; +export const LidoValidatorsSet = _12; -import * as _13 from './lidoWithdrawalVoucher'; -export const LidoWithdrawalVoucher = _13; +import * as _13 from './lidoValidatorsStats'; +export const LidoValidatorsStats = _13; + +import * as _14 from './lidoWithdrawalManager'; +export const LidoWithdrawalManager = _14; + +import * as _15 from './lidoWithdrawalVoucher'; +export const LidoWithdrawalVoucher = _15; diff --git a/integration_tests/src/generated/contractLib/lidoAstroportExchangeHandler.ts b/integration_tests/src/generated/contractLib/lidoAstroportExchangeHandler.ts new file mode 100644 index 00000000..0d616e1c --- /dev/null +++ b/integration_tests/src/generated/contractLib/lidoAstroportExchangeHandler.ts @@ -0,0 +1,169 @@ +import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult, InstantiateResult } from "@cosmjs/cosmwasm-stargate"; +import { StdFee } from "@cosmjs/amino"; +import { Coin } from "@cosmjs/amino"; +/** + * A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq. + * + * # Examples + * + * Use `from` to create instances of this and `u128` to get the value out: + * + * ``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123); + * + * let b = Uint128::from(42u64); assert_eq!(b.u128(), 42); + * + * let c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ``` + */ +export type Uint128 = string; + +export interface InstantiateMsg { + core_contract: string; + cron_address: string; + from_denom: string; + min_rewards: Uint128; + owner: string; + pair_contract: string; + router_contract: string; +} +/** + * A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq. + * + * # Examples + * + * Use `from` to create instances of this and `u128` to get the value out: + * + * ``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123); + * + * let b = Uint128::from(42u64); assert_eq!(b.u128(), 42); + * + * let c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ``` + */ +export type Uint128 = string; +/** + * This enum describes a swap operation. + */ +export type SwapOperation = + | { + native_swap: { + /** + * The name (denomination) of the native asset to swap to + */ + ask_denom: string; + /** + * The name (denomination) of the native asset to swap from + */ + offer_denom: string; + }; + } + | { + astro_swap: { + /** + * Information about the asset we swap to + */ + ask_asset_info: AssetInfo; + /** + * Information about the asset being swapped + */ + offer_asset_info: AssetInfo; + }; + }; +/** + * This enum describes available Token types. ## Examples ``` # use cosmwasm_std::Addr; # use astroport::asset::AssetInfo::{NativeToken, Token}; Token { contract_addr: Addr::unchecked("stake...") }; NativeToken { denom: String::from("uluna") }; ``` + */ +export type AssetInfo = + | { + token: { + contract_addr: Addr; + }; + } + | { + native_token: { + denom: string; + }; + }; +/** + * A human readable address. + * + * In Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length. + * + * This type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances. + * + * This type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance. + */ +export type Addr = string; + +export interface LidoAstroportExchangeHandlerSchema { + responses: ConfigResponse; + execute: UpdateConfigArgs | UpdateSwapOperationsArgs; + [k: string]: unknown; +} +export interface ConfigResponse { + core_contract: string; + cron_address: string; + from_denom: string; + min_rewards: Uint128; + owner: string; + pair_contract: string; + router_contract: string; + swap_operations?: SwapOperation[] | null; +} +export interface UpdateConfigArgs { + core_contract?: string | null; + cron_address?: string | null; + from_denom?: string | null; + min_rewards?: Uint128 | null; + owner?: string | null; + pair_contract?: string | null; + router_contract?: string | null; +} +export interface UpdateSwapOperationsArgs { + operations?: SwapOperation[] | null; +} + + +function isSigningCosmWasmClient( + client: CosmWasmClient | SigningCosmWasmClient +): client is SigningCosmWasmClient { + return 'execute' in client; +} + +export class Client { + private readonly client: CosmWasmClient | SigningCosmWasmClient; + contractAddress: string; + constructor(client: CosmWasmClient | SigningCosmWasmClient, contractAddress: string) { + this.client = client; + this.contractAddress = contractAddress; + } + mustBeSigningClient() { + return new Error("This client is not a SigningCosmWasmClient"); + } + static async instantiate( + client: SigningCosmWasmClient, + sender: string, + codeId: number, + initMsg: InstantiateMsg, + label: string, + initCoins?: readonly Coin[], + fees?: StdFee | 'auto' | number, + ): Promise { + const res = await client.instantiate(sender, codeId, initMsg, label, fees, { + ...(initCoins && initCoins.length && { funds: initCoins }), + }); + return res; + } + queryConfig = async(): Promise => { + return this.client.queryContractSmart(this.contractAddress, { config: {} }); + } + updateConfig = async(sender:string, args: UpdateConfigArgs, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]): Promise => { + if (!isSigningCosmWasmClient(this.client)) { throw this.mustBeSigningClient(); } + return this.client.execute(sender, this.contractAddress, { update_config: args }, fee || "auto", memo, funds); + } + updateSwapOperations = async(sender:string, args: UpdateSwapOperationsArgs, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]): Promise => { + if (!isSigningCosmWasmClient(this.client)) { throw this.mustBeSigningClient(); } + return this.client.execute(sender, this.contractAddress, { update_swap_operations: args }, fee || "auto", memo, funds); + } + exchange = async(sender: string, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]): Promise => { + if (!isSigningCosmWasmClient(this.client)) { throw this.mustBeSigningClient(); } + return this.client.execute(sender, this.contractAddress, { exchange: {} }, fee || "auto", memo, funds); + } +} diff --git a/integration_tests/src/generated/contractLib/lidoFactory.ts b/integration_tests/src/generated/contractLib/lidoFactory.ts index 79f1a931..6adac5fb 100644 --- a/integration_tests/src/generated/contractLib/lidoFactory.ts +++ b/integration_tests/src/generated/contractLib/lidoFactory.ts @@ -11,6 +11,7 @@ export interface CodeIds { core_code_id: number; distribution_code_id: number; puppeteer_code_id: number; + rewards_manager_code_id: number; strategy_code_id: number; token_code_id: number; validators_set_code_id: number; @@ -85,6 +86,7 @@ export interface State { core_contract: string; distribution_contract: string; puppeteer_contract: string; + rewards_manager_contract: string; strategy_contract: string; token_contract: string; validators_set_contract: string; diff --git a/integration_tests/src/generated/contractLib/lidoRewardsManager.ts b/integration_tests/src/generated/contractLib/lidoRewardsManager.ts new file mode 100644 index 00000000..55231e31 --- /dev/null +++ b/integration_tests/src/generated/contractLib/lidoRewardsManager.ts @@ -0,0 +1,96 @@ +import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult, InstantiateResult } from "@cosmjs/cosmwasm-stargate"; +import { StdFee } from "@cosmjs/amino"; +import { Coin } from "@cosmjs/amino"; +export interface InstantiateMsg { + core_address: string; +} +/** + * A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq. + * + * # Examples + * + * Use `from` to create instances of this and `u128` to get the value out: + * + * ``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123); + * + * let b = Uint128::from(42u64); assert_eq!(b.u128(), 42); + * + * let c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ``` + */ +export type Uint128 = string; + +export interface LidoRewardsManagerSchema { + responses: ConfigResponse; + execute: UpdateConfigArgs | AddHandlerArgs | RemoveHandlerArgs; + [k: string]: unknown; +} +export interface ConfigResponse { + core_address: string; + handlers: HandlerConfig[]; +} +export interface HandlerConfig { + address: string; + denom: string; + min_rewards: Uint128; +} +export interface UpdateConfigArgs { + core_address?: string | null; +} +export interface AddHandlerArgs { + config: HandlerConfig; +} +export interface RemoveHandlerArgs { + denom: string; +} + + +function isSigningCosmWasmClient( + client: CosmWasmClient | SigningCosmWasmClient +): client is SigningCosmWasmClient { + return 'execute' in client; +} + +export class Client { + private readonly client: CosmWasmClient | SigningCosmWasmClient; + contractAddress: string; + constructor(client: CosmWasmClient | SigningCosmWasmClient, contractAddress: string) { + this.client = client; + this.contractAddress = contractAddress; + } + mustBeSigningClient() { + return new Error("This client is not a SigningCosmWasmClient"); + } + static async instantiate( + client: SigningCosmWasmClient, + sender: string, + codeId: number, + initMsg: InstantiateMsg, + label: string, + initCoins?: readonly Coin[], + fees?: StdFee | 'auto' | number, + ): Promise { + const res = await client.instantiate(sender, codeId, initMsg, label, fees, { + ...(initCoins && initCoins.length && { funds: initCoins }), + }); + return res; + } + queryConfig = async(): Promise => { + return this.client.queryContractSmart(this.contractAddress, { config: {} }); + } + updateConfig = async(sender:string, args: UpdateConfigArgs, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]): Promise => { + if (!isSigningCosmWasmClient(this.client)) { throw this.mustBeSigningClient(); } + return this.client.execute(sender, this.contractAddress, { update_config: args }, fee || "auto", memo, funds); + } + addHandler = async(sender:string, args: AddHandlerArgs, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]): Promise => { + if (!isSigningCosmWasmClient(this.client)) { throw this.mustBeSigningClient(); } + return this.client.execute(sender, this.contractAddress, { add_handler: args }, fee || "auto", memo, funds); + } + removeHandler = async(sender:string, args: RemoveHandlerArgs, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]): Promise => { + if (!isSigningCosmWasmClient(this.client)) { throw this.mustBeSigningClient(); } + return this.client.execute(sender, this.contractAddress, { remove_handler: args }, fee || "auto", memo, funds); + } + exchangeRewards = async(sender: string, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]): Promise => { + if (!isSigningCosmWasmClient(this.client)) { throw this.mustBeSigningClient(); } + return this.client.execute(sender, this.contractAddress, { exchange_rewards: {} }, fee || "auto", memo, funds); + } +} diff --git a/integration_tests/src/testcases/core.test.ts b/integration_tests/src/testcases/core.test.ts index 355a501f..1ab3df11 100644 --- a/integration_tests/src/testcases/core.test.ts +++ b/integration_tests/src/testcases/core.test.ts @@ -76,6 +76,7 @@ describe('Core', () => { puppeteer?: number; validatorsSet?: number; distribution?: number; + rewardsManager?: number; }; exchangeRate?: number; tokenContractAddress?: string; @@ -229,6 +230,17 @@ describe('Core', () => { expect(res.codeId).toBeGreaterThan(0); context.codeIds.puppeteer = res.codeId; } + { + const res = await client.upload( + account.address, + fs.readFileSync( + join(__dirname, '../../../artifacts/lido_rewards_manager.wasm'), + ), + 1.5, + ); + expect(res.codeId).toBeGreaterThan(0); + context.codeIds.rewardsManager = res.codeId; + } const res = await client.upload( account.address, fs.readFileSync(join(__dirname, '../../../artifacts/lido_factory.wasm')), @@ -249,6 +261,7 @@ describe('Core', () => { distribution_code_id: context.codeIds.distribution, validators_set_code_id: context.codeIds.validatorsSet, puppeteer_code_id: context.codeIds.puppeteer, + rewards_manager_code_id: context.codeIds.rewardsManager, }, remote_opts: { connection_id: 'connection-0', @@ -460,30 +473,9 @@ describe('Core', () => { }); it('add validators into validators set', async () => { - const { - neutronUserAddress, - factoryContractClient, - validatorAddress, - secondValidatorAddress, - } = context; + const { neutronUserAddress, factoryContractClient } = context; const res = await factoryContractClient.proxy( neutronUserAddress, - { - validator_set: { - update_validators: { - validators: [ - { - valoper_address: validatorAddress, - weight: 1, - }, - { - valoper_address: secondValidatorAddress, - weight: 1, - }, - ], - }, - }, - }, 1.5, undefined, [