Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: flashloans #105

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 61 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
members = [
"contracts/dao/cwd-core",
"contracts/dao/neutron-chain-manager",
"contracts/dao/neutron-flashloans",
"contracts/dao/neutron-flashloans-user",
"contracts/dao/proposal/*",
"contracts/dao/pre-propose/*",
"contracts/dao/voting/*",
Expand Down
4 changes: 4 additions & 0 deletions contracts/dao/neutron-flashloans-user/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --example neutron-flashloans-user_schema"
15 changes: 15 additions & 0 deletions contracts/dao/neutron-flashloans-user/.gitignore
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions contracts/dao/neutron-flashloans-user/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
authors = ["Andrei Zavgorodnii <andrei.z@hadronlans.org>"]
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-paginate = {path = "../../../packages/cw-paginate"}
cw-storage-plus = "1.1.0"
cw-utils = {version = "1.0.1"}
cw2 = "1.1.0"
cwd-interface = {path = "../../../packages/cwd-interface"}
cwd-macros = {path = "../../../packages/cwd-macros"}
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"
6 changes: 6 additions & 0 deletions contracts/dao/neutron-flashloans-user/README.md
Original file line number Diff line number Diff line change
@@ -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.**
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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": {}
}
Loading
Loading