diff --git a/contracts/neutron-flashloans-user/.cargo/config b/contracts/neutron-flashloans-user/.cargo/config new file mode 100644 index 0000000..5cea26c --- /dev/null +++ b/contracts/neutron-flashloans-user/.cargo/config @@ -0,0 +1,4 @@ +[alias] +wasm = "build --release --target wasm32-unknown-unknown" +unit-test = "test --lib" +schema = "run --example neutron-flashloans-user_schema" diff --git a/contracts/neutron-flashloans-user/.gitignore b/contracts/neutron-flashloans-user/.gitignore new file mode 100644 index 0000000..dfdaaa6 --- /dev/null +++ b/contracts/neutron-flashloans-user/.gitignore @@ -0,0 +1,15 @@ +# Build results +/target + +# Cargo+Git helper file (https://github.com/rust-lang/cargo/blob/0.44.1/src/cargo/sources/git/utils.rs#L320-L327) +.cargo-ok + +# Text file backups +**/*.rs.bk + +# macOS +.DS_Store + +# IDEs +*.iml +.idea diff --git a/contracts/neutron-flashloans-user/Cargo.toml b/contracts/neutron-flashloans-user/Cargo.toml new file mode 100644 index 0000000..1399f44 --- /dev/null +++ b/contracts/neutron-flashloans-user/Cargo.toml @@ -0,0 +1,38 @@ +[package] +authors = ["Andrei Zavgorodnii "] +description = "An implementation of a Flashloans user for Neutron" +edition = "2021" +name = "neutron-flashloans-user" +repository = "https://github.com/neutron-org/neutron-dao" +version = "0.3.0" + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +# for more explicit tests, cargo test --features=backtraces +backtraces = ["cosmwasm-std/backtraces"] +# use library feature to disable all instantiate/execute/query exports +library = [] + +[dependencies] +cosmwasm-schema = {version = "1.3.0"} +cosmwasm-std = {version = "1.3.0"} +cosmwasm-storage = {version = "1.3.0"} +cw-controllers = "1.1.0" +cw-storage-plus = "1.1.0" +cw-utils = {version = "1.0.1"} +cw2 = "1.1.0" +schemars = "0.8.8" +serde = {version = "1.0.175", default-features = false, features = ["derive"]} +serde_with = {version = "3.7.0", features = ["json"]} +thiserror = {version = "1.0"} +neutron-sdk = "0.8.0" +serde-json-wasm = "1.0.1" +prost = { version = "0.12.3", default-features = false } +prost-types = { version = "0.12.3", default-features = false } +cosmos-sdk-proto = { version = "0.20.0", default-features = false } + +[dev-dependencies] +anyhow = "1.0.57" +cw-multi-test = "0.16.5" diff --git a/contracts/neutron-flashloans-user/README.md b/contracts/neutron-flashloans-user/README.md new file mode 100644 index 0000000..279cc6e --- /dev/null +++ b/contracts/neutron-flashloans-user/README.md @@ -0,0 +1,6 @@ +### Neutron Flashloans User + +This is an internal contract used to test the functionality of the Neutron Flashloans contract. + +**This is not an example of a well-written borrower contract (since it does not implement any security checks) and +should not be used as a reference.** \ No newline at end of file diff --git a/contracts/neutron-flashloans-user/examples/neutron-flashloans-user_schema.rs b/contracts/neutron-flashloans-user/examples/neutron-flashloans-user_schema.rs new file mode 100644 index 0000000..b8afd51 --- /dev/null +++ b/contracts/neutron-flashloans-user/examples/neutron-flashloans-user_schema.rs @@ -0,0 +1,11 @@ +use cosmwasm_schema::write_api; +use neutron_flashloans_user::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; + +fn main() { + write_api! { + instantiate: InstantiateMsg, + query: QueryMsg, + execute: ExecuteMsg, + migrate: MigrateMsg + } +} diff --git a/contracts/neutron-flashloans-user/schema/neutron-flashloans-user.json b/contracts/neutron-flashloans-user/schema/neutron-flashloans-user.json new file mode 100644 index 0000000..5f7b701 --- /dev/null +++ b/contracts/neutron-flashloans-user/schema/neutron-flashloans-user.json @@ -0,0 +1,139 @@ +{ + "contract_name": "neutron-flashloans-user", + "contract_version": "0.3.0", + "idl_version": "1.0.0", + "instantiate": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "additionalProperties": false + }, + "execute": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "request_loan" + ], + "properties": { + "request_loan": { + "type": "object", + "required": [ + "amount", + "execution_mode", + "flashloans_contract" + ], + "properties": { + "amount": { + "description": "The amount to request.", + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "execution_mode": { + "description": "Determines how the loan should be processed.\n\nMODE_RETURN_LOAN = 0 (return the correct amount) MODE_WITHHOLD_LOAN = 1 (not return anything) MODE_RETURN_LOAN_MORE_THAN_NECESSARY = 2 (return more than expected) MODE_REQUEST_ANOTHER_LOAN_RECURSIVELY = 3 (request another loan while processing the existing loan)\n\nAny other value will result in returning an error.", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "flashloans_contract": { + "description": "Address to get the flashloans from.", + "allOf": [ + { + "$ref": "#/definitions/Addr" + } + ] + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "process_loan" + ], + "properties": { + "process_loan": { + "type": "object", + "required": [ + "fee", + "loan_amount", + "return_address" + ], + "properties": { + "fee": { + "description": "Specifies the fee which the borrower must pay to the return_address.", + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "loan_amount": { + "description": "Specifies the loan amount which the borrower must return to the return_address.", + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "return_address": { + "description": "Specifies the address to which the borrower must return the loan amount AND pay the fees.", + "allOf": [ + { + "$ref": "#/definitions/Addr" + } + ] + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ], + "definitions": { + "Addr": { + "description": "A human readable address.\n\nIn 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.\n\nThis 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.\n\nThis 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.", + "type": "string" + }, + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "Uint128": { + "description": "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.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", + "type": "string" + } + } + }, + "query": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "type": "string", + "enum": [] + }, + "migrate": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "MigrateMsg", + "type": "object", + "additionalProperties": false + }, + "sudo": null, + "responses": {} +} diff --git a/contracts/neutron-flashloans-user/schema/raw/execute.json b/contracts/neutron-flashloans-user/schema/raw/execute.json new file mode 100644 index 0000000..48d0151 --- /dev/null +++ b/contracts/neutron-flashloans-user/schema/raw/execute.json @@ -0,0 +1,114 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "request_loan" + ], + "properties": { + "request_loan": { + "type": "object", + "required": [ + "amount", + "execution_mode", + "flashloans_contract" + ], + "properties": { + "amount": { + "description": "The amount to request.", + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "execution_mode": { + "description": "Determines how the loan should be processed.\n\nMODE_RETURN_LOAN = 0 (return the correct amount) MODE_WITHHOLD_LOAN = 1 (not return anything) MODE_RETURN_LOAN_MORE_THAN_NECESSARY = 2 (return more than expected) MODE_REQUEST_ANOTHER_LOAN_RECURSIVELY = 3 (request another loan while processing the existing loan)\n\nAny other value will result in returning an error.", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "flashloans_contract": { + "description": "Address to get the flashloans from.", + "allOf": [ + { + "$ref": "#/definitions/Addr" + } + ] + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "process_loan" + ], + "properties": { + "process_loan": { + "type": "object", + "required": [ + "fee", + "loan_amount", + "return_address" + ], + "properties": { + "fee": { + "description": "Specifies the fee which the borrower must pay to the return_address.", + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "loan_amount": { + "description": "Specifies the loan amount which the borrower must return to the return_address.", + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "return_address": { + "description": "Specifies the address to which the borrower must return the loan amount AND pay the fees.", + "allOf": [ + { + "$ref": "#/definitions/Addr" + } + ] + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ], + "definitions": { + "Addr": { + "description": "A human readable address.\n\nIn 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.\n\nThis 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.\n\nThis 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.", + "type": "string" + }, + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "Uint128": { + "description": "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.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", + "type": "string" + } + } +} diff --git a/contracts/neutron-flashloans-user/schema/raw/instantiate.json b/contracts/neutron-flashloans-user/schema/raw/instantiate.json new file mode 100644 index 0000000..1352613 --- /dev/null +++ b/contracts/neutron-flashloans-user/schema/raw/instantiate.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "additionalProperties": false +} diff --git a/contracts/neutron-flashloans-user/schema/raw/migrate.json b/contracts/neutron-flashloans-user/schema/raw/migrate.json new file mode 100644 index 0000000..7fbe8c5 --- /dev/null +++ b/contracts/neutron-flashloans-user/schema/raw/migrate.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "MigrateMsg", + "type": "object", + "additionalProperties": false +} diff --git a/contracts/neutron-flashloans-user/schema/raw/query.json b/contracts/neutron-flashloans-user/schema/raw/query.json new file mode 100644 index 0000000..0f592a1 --- /dev/null +++ b/contracts/neutron-flashloans-user/schema/raw/query.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "type": "string", + "enum": [] +} diff --git a/contracts/neutron-flashloans-user/schema/raw/response_to_config.json b/contracts/neutron-flashloans-user/schema/raw/response_to_config.json new file mode 100644 index 0000000..0ea02c3 --- /dev/null +++ b/contracts/neutron-flashloans-user/schema/raw/response_to_config.json @@ -0,0 +1,47 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Config", + "type": "object", + "required": [ + "fee_rate", + "owner", + "source" + ], + "properties": { + "fee_rate": { + "description": "Defines the fee rate for the loans, e.g., fee_rate = 0.01 means that if you borrow 100untrn, you'll need to return 101untrn.", + "allOf": [ + { + "$ref": "#/definitions/Decimal" + } + ] + }, + "owner": { + "description": "Defines the address that can add and remove sources.", + "allOf": [ + { + "$ref": "#/definitions/Addr" + } + ] + }, + "source": { + "description": "Defines the address that is going to sponsor the loans. This address needs to grant a (Generic)Authorization to this contract to execute /cosmos.bank.v1beta1.MsgSend on its behalf.", + "allOf": [ + { + "$ref": "#/definitions/Addr" + } + ] + } + }, + "additionalProperties": false, + "definitions": { + "Addr": { + "description": "A human readable address.\n\nIn 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.\n\nThis 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.\n\nThis 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.", + "type": "string" + }, + "Decimal": { + "description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)", + "type": "string" + } + } +} diff --git a/contracts/neutron-flashloans-user/src/contract.rs b/contracts/neutron-flashloans-user/src/contract.rs new file mode 100644 index 0000000..9a87f12 --- /dev/null +++ b/contracts/neutron-flashloans-user/src/contract.rs @@ -0,0 +1,166 @@ +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; +use cosmwasm_std::{ + to_json_binary, Addr, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo, + Response, StdError, StdResult, Uint128, WasmMsg, +}; +use cw2::set_contract_version; +use neutron_sdk::bindings::msg::NeutronMsg; + +use crate::error::ContractError; +use crate::msg::FlashloansExecuteMsg::RequestLoan; +use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; +use crate::state::{EXECUTION_MODE, FLASHLOANS_CONTRACT}; + +pub(crate) const CONTRACT_NAME: &str = "crates.io:neutron-flashloans-user"; +pub(crate) const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); + +pub const MODE_RETURN_LOAN: u64 = 0; +pub const MODE_WITHHOLD_LOAN: u64 = 1; +pub const MODE_RETURN_LOAN_MORE_THAN_NECESSARY: u64 = 2; +pub const MODE_REQUEST_ANOTHER_LOAN_RECURSIVELY: u64 = 3; + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn instantiate( + deps: DepsMut, + _env: Env, + _info: MessageInfo, + _msg: InstantiateMsg, +) -> Result { + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + EXECUTION_MODE.save(deps.storage, &0u64)?; + Ok(Response::new().add_attribute("action", "instantiate")) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn execute( + deps: DepsMut, + _env: Env, + _info: MessageInfo, + msg: ExecuteMsg, +) -> Result, ContractError> { + match msg { + ExecuteMsg::RequestLoan { + flashloans_contract, + execution_mode, + amount, + } => execute_request_loan(deps, flashloans_contract, execution_mode, amount), + ExecuteMsg::ProcessLoan { + return_address, + loan_amount, + fee, + } => execute_process_loan(deps, return_address, loan_amount, fee), + } +} + +/// Makes the neutron-flashloans-user contract request a loan. Allows to +/// specify the execution mode (how the contract must behave while handling +/// the ProcessLoan message, see msg.rs), which is required for the integration +/// tests. Also allows to specify the loan amount. +pub fn execute_request_loan( + deps: DepsMut, + flashloans_contract: Addr, + execution_mode: u64, + amount: Vec, +) -> Result, ContractError> { + EXECUTION_MODE.save(deps.storage, &execution_mode)?; + // Saving the flashloans contract address is necessary for the + // MODE_REQUEST_ANOTHER_LOAN_RECURSIVELY execution mode. + FLASHLOANS_CONTRACT.save(deps.storage, &flashloans_contract)?; + + let msg = CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: flashloans_contract.to_string(), + msg: to_json_binary(&RequestLoan { amount }).unwrap(), + funds: vec![], + }); + Ok(Response::new() + .add_message(msg) + .add_attribute("action", "execute_request_loan")) +} + +pub fn execute_process_loan( + deps: DepsMut, + return_address: Addr, + loan_amount: Vec, + fee: Vec, +) -> Result, ContractError> { + let execution_mode = EXECUTION_MODE.load(deps.storage)?; + + match execution_mode { + // Return the correct amount + MODE_RETURN_LOAN => { + let mut return_amount: Vec = vec![]; + for (idx, coin) in loan_amount.iter().enumerate() { + return_amount.push(Coin::new( + (coin.amount + fee[idx].amount).u128(), + coin.denom.clone(), + )) + } + + let msg = CosmosMsg::Bank(BankMsg::Send { + to_address: return_address.to_string(), + amount: return_amount, + }); + + Ok(Response::new() + .add_message(msg) + .add_attribute("action", "execute_process_loan_MODE_RETURN_LOAN")) + } + // Do not return the loan + MODE_WITHHOLD_LOAN => { + Ok(Response::new().add_attribute("action", "execute_process_loan_MODE_WITHHOLD_LOAN")) + } + // Return more that necessary + MODE_RETURN_LOAN_MORE_THAN_NECESSARY => { + let mut return_amount: Vec = vec![]; + for (idx, coin) in loan_amount.iter().enumerate() { + return_amount.push(Coin::new( + // Simply add 1 + (coin.amount + fee[idx].amount + Uint128::one()).u128(), + coin.denom.clone(), + )) + } + + let msg = CosmosMsg::Bank(BankMsg::Send { + to_address: return_address.to_string(), + amount: return_amount, + }); + + Ok(Response::new().add_message(msg).add_attribute( + "action", + "execute_process_loan_MODE_RETURN_LOAN_MORE_THAN_NECESSARY", + )) + } + // Request another loan while processing the existing loan + MODE_REQUEST_ANOTHER_LOAN_RECURSIVELY => { + let flashloans_contract = FLASHLOANS_CONTRACT.load(deps.storage)?; + let msg = CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: flashloans_contract.to_string(), + msg: to_json_binary(&RequestLoan { + amount: vec![Coin::new(100u128, "untrn")], + }) + .unwrap(), + funds: vec![], + }); + Ok(Response::new().add_message(msg).add_attribute( + "action", + "execute_request_loan_MODE_REQUEST_ANOTHER_LOAN_RECURSIVELY", + )) + } + _ => Err(ContractError::Std(StdError::generic_err( + "The ProcessLoan handler failed", + ))), + } +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn query(_deps: Deps, _env: Env, _msg: QueryMsg) -> StdResult { + Ok(Binary::default()) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { + // Set contract to version to latest + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + Ok(Response::default()) +} diff --git a/contracts/neutron-flashloans-user/src/error.rs b/contracts/neutron-flashloans-user/src/error.rs new file mode 100644 index 0000000..7155f59 --- /dev/null +++ b/contracts/neutron-flashloans-user/src/error.rs @@ -0,0 +1,8 @@ +use cosmwasm_std::StdError; +use thiserror::Error; + +#[derive(Error, Debug, PartialEq)] +pub enum ContractError { + #[error("{0}")] + Std(#[from] StdError), +} diff --git a/contracts/neutron-flashloans-user/src/lib.rs b/contracts/neutron-flashloans-user/src/lib.rs new file mode 100644 index 0000000..d78159f --- /dev/null +++ b/contracts/neutron-flashloans-user/src/lib.rs @@ -0,0 +1,4 @@ +pub mod contract; +mod error; +pub mod msg; +pub mod state; diff --git a/contracts/neutron-flashloans-user/src/msg.rs b/contracts/neutron-flashloans-user/src/msg.rs new file mode 100644 index 0000000..60193c2 --- /dev/null +++ b/contracts/neutron-flashloans-user/src/msg.rs @@ -0,0 +1,50 @@ +use cosmwasm_schema::{cw_serde, QueryResponses}; +use cosmwasm_std::{Addr, Coin}; + +#[cw_serde] +#[serde(rename_all = "snake_case")] +pub struct InstantiateMsg {} + +#[cw_serde] +pub enum ExecuteMsg { + RequestLoan { + /// Address to get the flashloans from. + flashloans_contract: Addr, + + /// Determines how the loan should be processed. + /// + /// MODE_RETURN_LOAN = 0 (return the correct amount) + /// MODE_WITHHOLD_LOAN = 1 (not return anything) + /// MODE_RETURN_LOAN_MORE_THAN_NECESSARY = 2 (return more than expected) + /// MODE_REQUEST_ANOTHER_LOAN_RECURSIVELY = 3 (request another loan while processing the existing loan) + /// + /// Any other value will result in returning an error. + execution_mode: u64, + + /// The amount to request. + amount: Vec, + }, + ProcessLoan { + /// Specifies the address to which the borrower must return the loan amount AND pay the fees. + return_address: Addr, + /// Specifies the loan amount which the borrower must return to the return_address. + loan_amount: Vec, + /// Specifies the fee which the borrower must pay to the return_address. + fee: Vec, + }, +} + +#[cw_serde] +#[derive(QueryResponses)] +pub enum QueryMsg {} + +#[cw_serde] +pub enum FlashloansExecuteMsg { + /// This message duplicates the neutron-flashloan RequestLoan message + /// to avoid moving it to packages. + RequestLoan { amount: Vec }, +} + +#[cw_serde] +#[serde(rename_all = "snake_case")] +pub struct MigrateMsg {} diff --git a/contracts/neutron-flashloans-user/src/state.rs b/contracts/neutron-flashloans-user/src/state.rs new file mode 100644 index 0000000..d43ae43 --- /dev/null +++ b/contracts/neutron-flashloans-user/src/state.rs @@ -0,0 +1,10 @@ +use cosmwasm_std::Addr; +use cw_storage_plus::Item; + +/// Stores the execution mode of the neutron-flashloans-user contract. See msg.rs for more details. +pub const EXECUTION_MODE: Item = Item::new("neutron-flashloans-user-execution-mode"); + +/// Stores the address of the flashloans contract. It is necessary for the +/// MODE_REQUEST_ANOTHER_LOAN_RECURSIVELY execution mode. +pub const FLASHLOANS_CONTRACT: Item = + Item::new("neutron-flashloans-user-flashloans-contract");