DeFiPy 1.0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. defipy/__init__.py +51 -0
  2. defipy/agents/ImpermanentLossAgent.py +182 -0
  3. defipy/agents/PriceThresholdSwapAgent.py +169 -0
  4. defipy/agents/TVLBasedLiquidityExitAgent.py +174 -0
  5. defipy/agents/VolumeSpikeNotifierAgent.py +190 -0
  6. defipy/agents/__init__.py +4 -0
  7. defipy/agents/config/ImpermanentLossConfig.py +28 -0
  8. defipy/agents/config/PriceThresholdConfig.py +27 -0
  9. defipy/agents/config/TVLExitConfig.py +28 -0
  10. defipy/agents/config/VolumeSpikeConfig.py +27 -0
  11. defipy/agents/config/__init__.py +7 -0
  12. defipy/agents/data/UniswapPoolData.py +26 -0
  13. defipy/agents/data/__init__.py +1 -0
  14. defipy/analytics/risk/__init__.py +1 -0
  15. defipy/analytics/simulate/__init__.py +1 -0
  16. defipy/erc/__init__.py +1 -0
  17. defipy/math/basic/__init__.py +1 -0
  18. defipy/math/interest/__init__.py +1 -0
  19. defipy/math/interest/ips/__init__.py +1 -0
  20. defipy/math/interest/ips/aggregate/__init__.py +1 -0
  21. defipy/math/model/__init__.py +1 -0
  22. defipy/math/risk/__init__.py +1 -0
  23. defipy/process/__init__.py +1 -0
  24. defipy/process/burn/__init__.py +1 -0
  25. defipy/process/deposit/__init__.py +1 -0
  26. defipy/process/join/Join.py +57 -0
  27. defipy/process/join/__init__.py +2 -0
  28. defipy/process/liquidity/AddLiquidity.py +57 -0
  29. defipy/process/liquidity/RemoveLiquidity.py +57 -0
  30. defipy/process/liquidity/__init__.py +2 -0
  31. defipy/process/mint/__init__.py +1 -0
  32. defipy/process/swap/Swap.py +57 -0
  33. defipy/process/swap/__init__.py +2 -0
  34. defipy/utils/client/__init__.py +1 -0
  35. defipy/utils/client/contract/ExecuteScript.py +57 -0
  36. defipy/utils/client/contract/__init__.py +1 -0
  37. defipy/utils/data/__init__.py +1 -0
  38. defipy/utils/interfaces/__init__.py +1 -0
  39. defipy/utils/tools/UniswapScriptHelper.py +81 -0
  40. defipy/utils/tools/__init__.py +2 -0
  41. defipy/utils/tools/v3/__init__.py +1 -0
  42. defipy-1.0.9.dist-info/METADATA +247 -0
  43. defipy-1.0.9.dist-info/RECORD +47 -0
  44. defipy-1.0.9.dist-info/WHEEL +5 -0
  45. defipy-1.0.9.dist-info/licenses/LICENSE +178 -0
  46. defipy-1.0.9.dist-info/licenses/NOTICE +16 -0
  47. defipy-1.0.9.dist-info/top_level.txt +1 -0
@@ -0,0 +1,190 @@
1
+ # ─────────────────────────────────────────────────────────────────────────────
2
+ # Apache 2.0 License (DeFiPy)
3
+ # ─────────────────────────────────────────────────────────────────────────────
4
+ # Copyright 2023–2025 Ian Moore
5
+ # Email: defipy.devs@gmail.com
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ from pydantic import BaseModel
20
+ from web3scout.utils.connect import ConnectW3
21
+ from web3scout.abi.abi_load import ABILoad
22
+ from web3scout.event.process.retrieve_events import RetrieveEvents
23
+ from web3scout.token.fetch.fetch_token import FetchToken
24
+ from .config import VolumeSpikeConfig
25
+ from .data import UniswapPoolData
26
+ from uniswappy import *
27
+ from web3 import Web3
28
+
29
+ class VolumeSpikeNotifierAgent:
30
+ def __init__(self, config: VolumeSpikeConfig, verbose: bool = False):
31
+ self.config = config
32
+ self.abi = ABILoad(self.config.platform, self.config.abi_name) # Load ABI here
33
+ self.connector = ConnectW3(self.config.provider_url) # Web3Scout setup
34
+ self.connector.apply()
35
+ self.verbose = verbose
36
+ self.pool_volume = None
37
+ self.lp_contract = None
38
+ self.lp_data = None
39
+ self.lp_state = None
40
+
41
+ def init(self):
42
+ self.lp_contract = self._init_lp_contract()
43
+
44
+ reserves = self.lp_contract.functions.getReserves().call()
45
+ token0_address = self.lp_contract.functions.token0().call()
46
+ token1_address = self.lp_contract.functions.token1().call()
47
+ reserve0 = reserves[0]; reserve1 = reserves[1]
48
+
49
+ w3 = self.connector.get_w3()
50
+ FetchERC20 = FetchToken(w3)
51
+ TKN0 = FetchERC20.apply(token0_address)
52
+ TKN1 = FetchERC20.apply(token1_address)
53
+
54
+ self.lp_data = UniswapPoolData(TKN0, TKN1, reserves)
55
+
56
+ def get_connector(self):
57
+ return self.connector
58
+
59
+ def get_abi(self):
60
+ return self.abi
61
+
62
+ def get_w3(self):
63
+ return self.connector.get_w3()
64
+
65
+ def get_contract_instance(self):
66
+ return self.lp_contract
67
+
68
+ def get_lp_data(self):
69
+ return self.lp_data
70
+
71
+ def prime_mock_pool(self, start_block, user_nm = None):
72
+ w3 = self.get_w3()
73
+ fetch_tkn = FetchToken(w3)
74
+
75
+ lp_contract = self._init_lp_contract()
76
+ tkn0_addr = lp_contract.functions.token0().call()
77
+ tkn1_addr = lp_contract.functions.token1().call()
78
+ total_supply = lp_contract.functions.totalSupply().call(block_identifier=start_block)
79
+ reserves = lp_contract.functions.getReserves().call(block_identifier=start_block)
80
+
81
+ # Step 2: Define tokens
82
+ tkn0 = fetch_tkn.apply(tkn0_addr)
83
+ tkn1 = fetch_tkn.apply(tkn1_addr)
84
+
85
+ amt0 = fetch_tkn.amt_to_decimal(tkn0, reserves[0])
86
+ amt1 = fetch_tkn.amt_to_decimal(tkn1, reserves[1])
87
+
88
+ # Step 3: Initialize factory
89
+ factory = UniswapFactory("Pool factory", "0x2")
90
+
91
+ # Step 4: Set up exchange data for V2
92
+ exch_data = UniswapExchangeData(tkn0=tkn0, tkn1=tkn1, symbol="LP", address=self.config.pool_address)
93
+
94
+ # Step 5: Deploy pool
95
+ self.lp_state = factory.deploy(exch_data)
96
+
97
+ # Step 6: Add initial liquidity
98
+ join = Join()
99
+ join.apply(self.lp_state, user_nm, amt0, amt1)
100
+ self.lp_state.total_supply = total_supply # override total supply
101
+
102
+ return self.lp_state
103
+
104
+ def update_mock_pool(self, lp, cur_block):
105
+ w3 = self.get_w3()
106
+ fetch_tkn = FetchToken(w3)
107
+
108
+ lp_contract = self._init_lp_contract()
109
+ tkn0_addr = lp_contract.functions.token0().call()
110
+ tkn1_addr = lp_contract.functions.token1().call()
111
+ total_supply = lp_contract.functions.totalSupply().call(block_identifier=int(cur_block))
112
+ reserves = lp_contract.functions.getReserves().call(block_identifier=int(cur_block))
113
+
114
+ tkn0 = self.get_lp_data().tkn0
115
+ tkn1 = self.get_lp_data().tkn1
116
+ amt0 = fetch_tkn.amt_to_decimal(tkn0, reserves[0])
117
+ amt1 = fetch_tkn.amt_to_decimal(tkn1, reserves[1])
118
+
119
+ prev_total_supply = lp.total_supply
120
+ lp.reserve0 = lp.convert_to_machine(amt0) # override reserve0
121
+ lp.reserve1 = lp.convert_to_machine(amt1) # override reserve1
122
+ lp.total_supply = total_supply # override total supply
123
+ lp.last_liquidity_deposit = abs(prev_total_supply - lp.total_supply)
124
+
125
+ return lp
126
+
127
+ def run_batch(self, lp, tkn, user_nm, events: dict):
128
+ """Process batched Sync events to check TVL and trigger exits."""
129
+ if not events:
130
+ print("No Sync events found in range.")
131
+ return
132
+ for k in events:
133
+ block_num = events[k]['blockNumber']
134
+ self.apply(lp, tkn, user_nm, block_num)
135
+
136
+ def apply(self, lp, tkn, user_nm, block_num):
137
+ """Execute liquidity exit if condition met."""
138
+ if self.check_condition(lp, tkn, self.config.volume_threshold, block_num):
139
+ vol = self.pool_volume
140
+ print(f"Block {block_num}: Volume ({tkn.token_name}) = {vol}, outside threshold {self.config.volume_threshold}")
141
+ return vol
142
+ else:
143
+ print(f"Block {block_num}: Volume threshold condition met for {lp.name} LP")
144
+ return None
145
+
146
+ def take_mock_position(self, lp, tkn, user_nm, amt):
147
+ SwapDeposit().apply(lp, tkn, user_nm, amt)
148
+ self.mock_lp_pos_amt = lp.get_last_liquidity_deposit()
149
+ return self.mock_lp_pos_amt
150
+
151
+ def withdraw_mock_position(self, lp, tkn, user_nm, lp_amt = None):
152
+ assert self.mock_lp_pos_amt != None, 'TVLBasedLiquidityExitAgent: MOCK_POSITION_UNAVAILABLE'
153
+ lp_amt = self.mock_lp_pos_amt if lp_amt == None else lp_amt
154
+ tkn_amt = LPQuote(False).get_amount_from_lp(lp, tkn0, lp_amt)
155
+ amount_out = WithdrawSwap().apply(lp, tkn0, user_nm, tkn_amt)
156
+ return amount_out
157
+
158
+ def get_pool_volume(self, lp, tkn, block_num):
159
+ """Calculate TVL from reserves (sum in USD, assuming base_token normalization)."""
160
+
161
+ tkn0 = self.get_lp_data().tkn0
162
+ tkn1 = self.get_lp_data().tkn1
163
+ prev_tkn0 = lp.get_reserve(tkn0)
164
+ prev_tkn1 = lp.get_reserve(tkn1)
165
+
166
+ lp = self.update_mock_pool(lp, block_num)
167
+
168
+ dtkn0 = abs(lp.get_reserve(tkn0) - prev_tkn0)
169
+ dtkn1 = abs(lp.get_reserve(tkn1) - prev_tkn1)
170
+
171
+ if(tkn.token_name == tkn0.token_name):
172
+ volume = dtkn0 + LPQuote().get_amount(lp, tkn1, dtkn1)
173
+ elif(tkn.token_name == tkn1.token_name):
174
+ volume = dtkn1 + LPQuote().get_amount(lp, tkn0, dtkn0)
175
+
176
+ self.pool_volume = volume
177
+ return volume
178
+
179
+ def check_condition(self, lp, tkn, threshold, block_num = None):
180
+ """Check if TVL is below threshold."""
181
+ block_num = self.get_w3().eth.block_number if block_num == None else block_num
182
+ volume = self.get_pool_volume(lp, tkn, block_num)
183
+ return volume > threshold
184
+
185
+ def _init_lp_contract(self):
186
+ pair_address = self.config.pool_address
187
+ w3 = self.get_w3()
188
+ abi_obj = self.get_abi()
189
+ lp_contract = abi_obj.apply(w3, pair_address)
190
+ return lp_contract
@@ -0,0 +1,4 @@
1
+ from .PriceThresholdSwapAgent import PriceThresholdSwapAgent
2
+ from .TVLBasedLiquidityExitAgent import TVLBasedLiquidityExitAgent
3
+ from .VolumeSpikeNotifierAgent import VolumeSpikeNotifierAgent
4
+ from .ImpermanentLossAgent import ImpermanentLossAgent
@@ -0,0 +1,28 @@
1
+ # ─────────────────────────────────────────────────────────────────────────────
2
+ # Apache 2.0 License (DeFiPy)
3
+ # ─────────────────────────────────────────────────────────────────────────────
4
+ # Copyright 2023–2025 Ian Moore
5
+ # Email: defipy.devs@gmail.com
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ from pydantic import BaseModel
20
+
21
+ class ImpermanentLossConfig(BaseModel):
22
+ il_threshold: float # Impermanent loss threshold percentage (e.g., 5.0 for 5%)
23
+ pool_address: str # Uniswap V2 pool address
24
+ provider_url: str # Web3 provider URL (e.g., Infura)
25
+ abi_name: str # e.g., 'UniswapV2Pair' (new field for ABI identifier)
26
+ platform: str # e.g., 'UNI' or 'SUSHI' for the protocoll
27
+ user_position: float # Initial mock position amount for off-chain testing
28
+ exit_percentage: float # Percentage of position to exit upon trigger (e.g., 1.0 for 100%)
@@ -0,0 +1,27 @@
1
+ # ─────────────────────────────────────────────────────────────────────────────
2
+ # Apache 2.0 License (DeFiPy)
3
+ # ─────────────────────────────────────────────────────────────────────────────
4
+ # Copyright 2023–2025 Ian Moore
5
+ # Email: defipy.devs@gmail.com
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ from pydantic import BaseModel
20
+
21
+ class PriceThresholdConfig(BaseModel):
22
+ threshold: float # e.g., 3000.0 (price above which to swap)
23
+ swap_amount: float # e.g., 1.0 (swap amount if threshold met)
24
+ pool_address: str # Uniswap V2 pool
25
+ provider_url: str # e.g., Infura for Web3Scout
26
+ abi_name: str # e.g., 'UniswapV2Pair' (new field for ABI identifier)
27
+ platform: str # e.g., 'UNI' or 'SUSHI' for the protocoll
@@ -0,0 +1,28 @@
1
+ # ─────────────────────────────────────────────────────────────────────────────
2
+ # Apache 2.0 License (DeFiPy)
3
+ # ─────────────────────────────────────────────────────────────────────────────
4
+ # Copyright 2023–2025 Ian Moore
5
+ # Email: defipy.devs@gmail.com
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ from pydantic import BaseModel
20
+
21
+ class TVLExitConfig(BaseModel):
22
+ tvl_threshold: float # e.g., 1000000.0 (minimum TVL in USD)
23
+ exit_percentage: float # e.g., 1.0 (full exit) or 0.5 (half)
24
+ pool_address: str # Pool contract address
25
+ provider_url: str # Web3 provider URL
26
+ abi_name: str # e.g., 'UniswapV2Pair' (new field for ABI identifier)
27
+ platform: str # e.g., 'UNI' or 'SUSHI' for the protocoll
28
+ user_position: float # User's LP shares or amount
@@ -0,0 +1,27 @@
1
+ # ─────────────────────────────────────────────────────────────────────────────
2
+ # Apache 2.0 License (DeFiPy)
3
+ # ─────────────────────────────────────────────────────────────────────────────
4
+ # Copyright 2023–2025 Ian Moore
5
+ # Email: defipy.devs@gmail.com
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ from pydantic import BaseModel
20
+
21
+ class VolumeSpikeConfig(BaseModel):
22
+ volume_threshold: float # Volume threshold for notification (e.g., USD value of trades)
23
+ pool_address: str # Uniswap V2 pool address
24
+ provider_url: str # Web3 provider URL (e.g., Infura)
25
+ abi_name: str # e.g., 'UniswapV2Pair' (new field for ABI identifier)
26
+ platform: str # e.g., 'UNI' or 'SUSHI' for the protocoll
27
+ user_position: float # User's LP shares or amount
@@ -0,0 +1,7 @@
1
+ from .PriceThresholdConfig import PriceThresholdConfig
2
+ from .TVLExitConfig import TVLExitConfig
3
+ from .VolumeSpikeConfig import VolumeSpikeConfig
4
+ from .ImpermanentLossConfig import ImpermanentLossConfig
5
+
6
+
7
+
@@ -0,0 +1,26 @@
1
+ # ─────────────────────────────────────────────────────────────────────────────
2
+ # Apache 2.0 License (DeFiPy)
3
+ # ─────────────────────────────────────────────────────────────────────────────
4
+ # Copyright 2023–2025 Ian Moore
5
+ # Email: defipy.devs@gmail.com
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ from dataclasses import dataclass
20
+ from uniswappy.erc import ERC20
21
+
22
+ @dataclass
23
+ class UniswapPoolData:
24
+ tkn0: ERC20 = None
25
+ tkn1: ERC20 = None
26
+ reserves: list = None
@@ -0,0 +1 @@
1
+ from .UniswapPoolData import UniswapPoolData
@@ -0,0 +1 @@
1
+ from uniswappy.analytics.risk import *
@@ -0,0 +1 @@
1
+ from uniswappy.analytics.simulate import *
defipy/erc/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from uniswappy.erc import *
@@ -0,0 +1 @@
1
+ from uniswappy.math.basic import *
@@ -0,0 +1 @@
1
+ from uniswappy.math.interest import *
@@ -0,0 +1 @@
1
+ from uniswappy.math.interest.ips import *
@@ -0,0 +1 @@
1
+ from uniswappy.math.interest.ips.aggregate import *
@@ -0,0 +1 @@
1
+ from uniswappy.math.model import *
@@ -0,0 +1 @@
1
+ from uniswappy.math.risk import *
@@ -0,0 +1 @@
1
+ from uniswappy.process import *
@@ -0,0 +1 @@
1
+ from uniswappy.process.burn import *
@@ -0,0 +1 @@
1
+ from uniswappy.process.deposit import *
@@ -0,0 +1,57 @@
1
+ # ─────────────────────────────────────────────────────────────────────────────
2
+ # Apache 2.0 License (DeFiPy)
3
+ # ─────────────────────────────────────────────────────────────────────────────
4
+ # Copyright 2023–2025 Ian Moore
5
+ # Email: defipy.devs@gmail.com
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ from uniswappy.process.join import Join as UniswapJoin
20
+ from balancerpy.process.join import Join as BalancerJoin
21
+ from stableswappy.process.join import Join as StableswapJoin
22
+
23
+ class Join():
24
+
25
+ """ Process to join x and y amounts to pool
26
+ """
27
+
28
+ def __init__(self):
29
+ pass
30
+
31
+ def apply(self, lp, v1 = None, v2 = None, v3 = None, v4 = None, v5 = None):
32
+ """ apply
33
+
34
+ Join x and y amounts to pool
35
+
36
+ UniswapJoin().apply(lp, user_nm, amount0, amount1, lwr_tick = None, upr_tick = None):
37
+
38
+ BalancerJoin().apply(lp, user_nm, shares)
39
+
40
+ StableswapJoin().apply(lp, user_nm, shares)
41
+
42
+ Returns
43
+ -------
44
+ out : dictionary
45
+ join output
46
+ """
47
+
48
+ if type(lp).__name__ == 'UniswapExchange' or type(lp).__name__ == 'UniswapV3Exchange':
49
+ out = UniswapJoin().apply(lp, v1, v2, v3, v4, v5)
50
+ elif type(lp).__name__ == 'BalancerExchange':
51
+ out = BalancerJoin().apply(lp, v1, v2)
52
+ elif type(lp).__name__ == 'StableswapExchange':
53
+ out = StableswapJoin().apply(lp, v1, v2)
54
+ else:
55
+ print('DeFiPy: WRONG EXCHANGE TYPE OR VARIABLES')
56
+
57
+ return out
@@ -0,0 +1,2 @@
1
+ from .Join import Join
2
+ from uniswappy.process.join import JoinTree
@@ -0,0 +1,57 @@
1
+ # ─────────────────────────────────────────────────────────────────────────────
2
+ # Apache 2.0 License (DeFiPy)
3
+ # ─────────────────────────────────────────────────────────────────────────────
4
+ # Copyright 2023–2025 Ian Moore
5
+ # Email: defipy.devs@gmail.com
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ from uniswappy.process.liquidity import AddLiquidity as UniswapAddLiquidity
20
+ from balancerpy.process.liquidity import AddLiquidity as BalancerAddLiquidity
21
+ from stableswappy.process.liquidity import AddLiquidity as StableswapAddLiquidity
22
+
23
+ class AddLiquidity():
24
+
25
+ """ Add liquidity process
26
+ """
27
+
28
+ def __init__(self, global_var1 = None):
29
+ self.gvar = global_var1
30
+
31
+ def apply(self, lp, v1 = None, v2 = None, v3 = None, v4 = None, v5 = None):
32
+ """ apply
33
+
34
+ Add liquidity process
35
+
36
+ UniswapAddLiquidity().apply(lp, user_nm, amount0, amount1, lwr_tick = None, upr_tick = None):
37
+
38
+ BalancerAddLiquidity(Proc.ADDTKN).apply(lp, tkn_in, user_nm, amt_tkn_in)
39
+
40
+ StableswapAddLiquidity().apply(lp, tkn_in, user_nm, amt_tkn_in)
41
+
42
+ Returns
43
+ -------
44
+ out : dictionary
45
+ join output
46
+ """
47
+
48
+ if type(lp).__name__ == 'UniswapExchange' or type(lp).__name__ == 'UniswapV3Exchange':
49
+ out = UniswapAddLiquidity().apply(lp, v1, v2, v3, v4, v5)
50
+ elif type(lp).__name__ == 'BalancerExchange':
51
+ out = BalancerAddLiquidity(self.gvar).apply(lp, v1, v2, v3)
52
+ elif type(lp).__name__ == 'StableswapExchange':
53
+ out = StableswapAddLiquidity().apply(lp, v1, v2, v3)
54
+ else:
55
+ print('DeFiPy: WRONG EXCHANGE TYPE OR VARIABLES')
56
+
57
+ return out
@@ -0,0 +1,57 @@
1
+ # ─────────────────────────────────────────────────────────────────────────────
2
+ # Apache 2.0 License (DeFiPy)
3
+ # ─────────────────────────────────────────────────────────────────────────────
4
+ # Copyright 2023–2025 Ian Moore
5
+ # Email: defipy.devs@gmail.com
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ from uniswappy.process.liquidity import RemoveLiquidity as UniswapRemoveLiquidity
20
+ from balancerpy.process.liquidity import RemoveLiquidity as BalancerRemoveLiquidity
21
+ from stableswappy.process.liquidity import RemoveLiquidity as StableswapRemoveLiquidity
22
+
23
+ class RemoveLiquidity():
24
+
25
+ """ Process to join x and y amounts to pool
26
+ """
27
+
28
+ def __init__(self, global_var1 = None):
29
+ self.gvar = global_var1
30
+
31
+ def apply(self, lp, v1 = None, v2 = None, v3 = None, v4 = None, v5 = None):
32
+ """ apply
33
+
34
+ Join x and y amounts to pool
35
+
36
+ UniswapRemoveLiquidity().apply(lp, user_nm, amount0, amount1, lwr_tick = None, upr_tick = None):
37
+
38
+ BalancerRemoveLiquidity(Proc.ADDTKN).apply(lp, tkn_in, user_nm, amt_tkn_in)
39
+
40
+ StableswapRemoveLiquidity().apply(lp, tkn_in, user_nm, amt_tkn_in)
41
+
42
+ Returns
43
+ -------
44
+ out : dictionary
45
+ join output
46
+ """
47
+
48
+ if type(lp).__name__ == 'UniswapExchange' or type(lp).__name__ == 'UniswapV3Exchange':
49
+ out = UniswapRemoveLiquidity().apply(lp, v1, v2, v3, v4, v5)
50
+ elif type(lp).__name__ == 'BalancerExchange':
51
+ out = BalancerRemoveLiquidity(self.gvar).apply(lp, v1, v2, v3)
52
+ elif type(lp).__name__ == 'StableswapExchange':
53
+ out = StableswapRemoveLiquidity().apply(lp, v1, v2, v3)
54
+ else:
55
+ print('DeFiPy: WRONG EXCHANGE TYPE OR VARIABLES')
56
+
57
+ return out
@@ -0,0 +1,2 @@
1
+ from .AddLiquidity import AddLiquidity
2
+ from .RemoveLiquidity import RemoveLiquidity
@@ -0,0 +1 @@
1
+ from uniswappy.process.mint import *
@@ -0,0 +1,57 @@
1
+ # ─────────────────────────────────────────────────────────────────────────────
2
+ # Apache 2.0 License (DeFiPy)
3
+ # ─────────────────────────────────────────────────────────────────────────────
4
+ # Copyright 2023–2025 Ian Moore
5
+ # Email: defipy.devs@gmail.com
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ from uniswappy.process.swap import Swap as UniswapSwap
20
+ from balancerpy.process.swap import Swap as BalancerSwap
21
+ from stableswappy.process.swap import Swap as StableswapSwap
22
+
23
+ class Swap():
24
+
25
+ """ Process to swap token X for token Y (and vice verse)
26
+ """
27
+
28
+ def __init__(self, global_var1 = None):
29
+ self.gvar = global_var1
30
+
31
+ def apply(self, lp, v1 = None, v2 = None, v3 = None, v4 = None):
32
+ """ apply
33
+
34
+ Swap token X for token Y (and vice verse)
35
+
36
+ UniswapSwap().apply(lp, token_in, user_nm, amount)
37
+
38
+ BalancerSwap().apply(lp, token_in, token_out, user_nm, amount)
39
+
40
+ StableswapSwap().apply(lp, token_in, token_out, user_nm, amount)
41
+
42
+ Returns
43
+ -------
44
+ out : dictionary
45
+ join output
46
+ """
47
+
48
+ if type(lp).__name__ == 'UniswapExchange' or type(lp).__name__ == 'UniswapV3Exchange':
49
+ out = UniswapSwap().apply(lp, v1, v2, v3)
50
+ elif type(lp).__name__ == 'BalancerExchange':
51
+ out = BalancerSwap(self.gvar).apply(lp, v1, v2, v3, v4)
52
+ elif type(lp).__name__ == 'StableswapExchange':
53
+ out = StableswapSwap().apply(lp, v1, v2, v3, v4)
54
+ else:
55
+ print('DeFiPy: WRONG EXCHANGE TYPE OR VARIABLES')
56
+
57
+ return out
@@ -0,0 +1,2 @@
1
+ from .Swap import Swap
2
+ from uniswappy.process.swap import WithdrawSwap
@@ -0,0 +1 @@
1
+ from uniswappy.utils.client import *