Skip to content

Commit

Permalink
Merge pull request #150 from djeck1432/feat/add-extra-deposit-withdraw
Browse files Browse the repository at this point in the history
Add extra deposit and withdraw methods
  • Loading branch information
djeck1432 authored Nov 7, 2024
2 parents 027caf4 + 4c7fc1e commit 9fa84d1
Show file tree
Hide file tree
Showing 10 changed files with 805 additions and 219 deletions.
48 changes: 21 additions & 27 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,50 @@ name = "ekubo"
version = "0.1.0"
source = "git+https://github.com/ekuboprotocol/abis?rev=edb6de8#edb6de8c9baf515f1053bbab3d86825d54a63bc3"

[[package]]
name = "openzeppelin_access"
version = "0.17.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:541bb8fdf1ad17fe0d275b00acb9f0d7f56ea5534741e21535ac3fda2c600281"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_account"
version = "0.17.0"
version = "0.18.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:c4e11609fdd1f4c3d3004cd1468711bd2ea664739c9e59a4b270567fe4c23ee3"
checksum = "sha256:83e6571cac4c67049c8d0ab4e3c7ad146d582d7605e7354248835833e1d26c4a"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_governance"
version = "0.17.0"
name = "openzeppelin_introspection"
version = "0.18.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:b7e0142d88d69a8c367aea8c9dc7f659f27372551efc23f39a0cf71a189c1302"
dependencies = [
"openzeppelin_access",
"openzeppelin_introspection",
]
checksum = "sha256:46c4cc6c95c9baa4c7d5cc0ed2bdaf334f46c25a8c92b3012829fff936e3042b"

[[package]]
name = "openzeppelin_introspection"
version = "0.17.0"
name = "openzeppelin_security"
version = "0.18.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:892433a4a1ea0fc9cf7cdb01e06ddc2782182abcc188e4ea5dd480906d006cf8"
checksum = "sha256:1db3a41e02ed48806587981340ed01ee7d552c3ad52cb33a6d81c1ed5cba9ee0"

[[package]]
name = "openzeppelin_token"
version = "0.17.0"
version = "0.18.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:77997a7e217b69674c34b402dc0c7b2210540db66a56087572679c31896eaabb"
checksum = "sha256:eafbe13f6a0487ce212459e25a81ae07f340ba76208ad4616626eb2d25a9625e"
dependencies = [
"openzeppelin_account",
"openzeppelin_governance",
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_upgrades"
version = "0.18.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:33c9d0865364fc18a5e7b471fe53c3b0f3e0aec56a94f435089638fad2a4a35b"

[[package]]
name = "openzeppelin_utils"
version = "0.17.0"
version = "0.18.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:36d93e353f42fd6b824abcd8b4b51c3f5d02c893c5f886ae81403b0368aa5fde"
checksum = "sha256:725b212839f3eddc32791408609099c5e808c167ca0cf331d8c1d778b07a4e21"

[[package]]
name = "pragma_lib"
Expand All @@ -88,7 +80,9 @@ version = "0.1.0"
dependencies = [
"alexandria_math",
"ekubo",
"openzeppelin_security",
"openzeppelin_token",
"openzeppelin_upgrades",
"pragma_lib",
"snforge_std",
]
16 changes: 13 additions & 3 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ cairo-version = "2.8.2"
starknet = "2.8.2"
ekubo = { git = "https://github.com/ekuboprotocol/abis", rev = "edb6de8" }
alexandria_math = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "8208871" }
openzeppelin_token = "0.17.0"
openzeppelin_token = "0.18.0"
openzeppelin_security = "0.18.0"
openzeppelin_upgrades = "0.18.0"

[dev-dependencies]
pragma_lib = { git = "https://github.com/astraly-labs/pragma-lib", tag = "2.8.2" }
Expand All @@ -23,12 +25,20 @@ snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag
[tool.fmt]
sort-module-level-items = true

[tool.snforge]
fuzzer_runs = 10

[[tool.snforge.fork]]
name = "SEPOLIA"
url = "http://178.32.172.148:6062/v0_7"
url = "http://51.195.57.196:6062/v0_7"
block_id.tag = "latest"

[[tool.snforge.fork]]
name = "MAINNET"
url = "http://127.0.0.1:5050"
url = "http://51.195.57.196:6060/v0_7"
block_id.tag = "latest"

[[tool.snforge.fork]]
name = "MAINNET_FIXED_BLOCK"
url = "http://51.195.57.196:6060/v0_7"
block_id.number = "863242"
46 changes: 41 additions & 5 deletions docs/spotnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ This method has next parameters:
* `ekubo_limits`: EkuboSlippageLimits - Object of internal type which represents upper and lower sqrt_ratio values on Ekubo. Used to control slippage while swapping.
* `pool_price`: felt252 - Price of `deposit` token in terms of `debt` token(so for ex. 2400000000 USDC for ETH when depositing ETH).

It's flow can be described as follows:
We can trust the passed values, such as pool_price, because this function can be only called by the owner of the contract.

Its flow can be described as follows:

```
assertions
Expand Down Expand Up @@ -57,10 +59,11 @@ The method has next parameters:
* `debt_token`: ContractAddress - Address of the token used as borrowing.
* `pool_key`: PoolKey - Ekubo type for obtaining info about the pool and swapping tokens.
* `ekubo_limits`: EkuboSlippageLimits - Object of internal type which represents upper and lower sqrt_ratio values on Ekubo. Used to control slippage while swapping.
* `repay_const`: u8 - Sets how much to borrow from free amount. Parameter is used for dealing with price error on zklend or for pairs where debt interest rate accumulates faster than supply interest rate.
* `supply_price`: TokenPrice - Price of `supply` token in terms of `debt` token(so for ex. 2400000000 USDC for ETH).
* `debt_price`: TokenPrice - Price of `debt` token in terms of `supply` token(for ex. 410000000000000 ETH for USDC).

It's flow can be described as follows:
Its flow can be described as follows:
```
assertions
Expand Down Expand Up @@ -89,13 +92,45 @@ This method has next parameters:
* `proof`: Span<felt252> - proof used to validate the claim
* `airdrop_addr`: ContractAddress - address of a contract responsible for claim

Ir's flow can be described as follow
Its flow can be described as follows:

```
assertions
airdrop claim
claim tokens from airdrop contract
if treasury address is non-zero {
calculate and transfer 80% to treasury
}
approve zkLend to spend remaining tokens
deposit remaining tokens into zkLend
enable STRK as collateral
```

The method can be called by anyone (e.g., a keeper) to claim rewards. If the treasury address is set to zero when deploying the contract, all claimed rewards will be deposited into zkLend on behalf of the user instead of being split with the treasury. This is intended behavior; sophisticated users wanting to bypass the functionality could deploy their modified contract anyway. This serves to avoid burning the STRK.


### extra_deposit

The `extra_deposit` method allows depositing additional tokens into an open zkLend position for increased stability. This method can be called by anyone, not just the position owner.

Parameters:
* `token`: ContractAddress - Address of the token to deposit
* `amount`: TokenAmount - Amount of tokens to deposit

It's flow can be described as follows:

```
assertions (position must be open, amount must be non-zero)
transfer tokens from caller to contract
approve zkLend to spend the tokens
transfer half of reward to the treasury
deposit tokens into zkLend position
```

## Important types, events and constants
Expand Down Expand Up @@ -138,3 +173,4 @@ struct PositionClosed {

### Constants
* ZK_SCALE_DECIMALS is used for scaling down values obtained by multiplying on zklend collateral and borrow factors.
* STRK_ADDRESS is the same across Sepolia and Mainnet.
2 changes: 2 additions & 0 deletions src/constants.cairo
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pub const ZK_SCALE_DECIMALS: u256 = 1000000000000000000000000000;
pub const STRK_ADDRESS: felt252 =
0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d;
Loading

0 comments on commit 9fa84d1

Please sign in to comment.