1use std::sync::Arc;
2
3use reqwest::Method;
4
5use crate::client::ClientInner;
6use crate::error::Result;
7use crate::types::*;
8
9pub struct PlanApi {
10 pub(crate) inner: Arc<ClientInner>,
11}
12
13impl PlanApi {
14 pub async fn earn(&self, account_id: &str, params: &EarnParams) -> Result<Plan> {
15 self.inner
16 .request(
17 Method::POST,
18 &format!("/accounts/{account_id}/plan/earn"),
19 Some(params),
20 )
21 .await
22 }
23
24 pub async fn withdraw(&self, account_id: &str, params: &WithdrawParams) -> Result<Plan> {
25 self.inner
26 .request(
27 Method::POST,
28 &format!("/accounts/{account_id}/plan/withdraw"),
29 Some(params),
30 )
31 .await
32 }
33
34 pub async fn transfer(&self, account_id: &str, params: &TransferParams) -> Result<Plan> {
35 self.inner
36 .request(
37 Method::POST,
38 &format!("/accounts/{account_id}/plan/transfer"),
39 Some(params),
40 )
41 .await
42 }
43
44 pub async fn claim_rewards(
45 &self,
46 account_id: &str,
47 params: &ClaimRewardsParams,
48 ) -> Result<Plan> {
49 self.inner
50 .request(
51 Method::POST,
52 &format!("/accounts/{account_id}/plan/claim-rewards"),
53 Some(params),
54 )
55 .await
56 }
57
58 pub async fn borrow(&self, account_id: &str, params: &BorrowParams) -> Result<Plan> {
59 self.inner
60 .request(
61 Method::POST,
62 &format!("/accounts/{account_id}/plan/borrow"),
63 Some(params),
64 )
65 .await
66 }
67
68 pub async fn repay(&self, account_id: &str, params: &RepayParams) -> Result<Plan> {
69 self.inner
70 .request(
71 Method::POST,
72 &format!("/accounts/{account_id}/plan/repay"),
73 Some(params),
74 )
75 .await
76 }
77
78 pub async fn swap(&self, account_id: &str, params: &SwapParams) -> Result<Plan> {
79 self.inner
80 .request(
81 Method::POST,
82 &format!("/accounts/{account_id}/plan/swap"),
83 Some(params),
84 )
85 .await
86 }
87
88 pub async fn loop_long(&self, account_id: &str, params: &LoopLongParams) -> Result<Plan> {
89 self.inner
90 .request(
91 Method::POST,
92 &format!("/accounts/{account_id}/plan/loop-long"),
93 Some(params),
94 )
95 .await
96 }
97
98 pub async fn unloop_long(&self, account_id: &str, params: &UnloopLongParams) -> Result<Plan> {
99 self.inner
100 .request(
101 Method::POST,
102 &format!("/accounts/{account_id}/plan/unloop-long"),
103 Some(params),
104 )
105 .await
106 }
107
108 pub async fn add_backing(&self, account_id: &str, params: &AddBackingParams) -> Result<Plan> {
109 self.inner
110 .request(
111 Method::POST,
112 &format!("/accounts/{account_id}/plan/add-backing"),
113 Some(params),
114 )
115 .await
116 }
117
118 pub async fn withdraw_backing(
119 &self,
120 account_id: &str,
121 params: &WithdrawBackingParams,
122 ) -> Result<Plan> {
123 self.inner
124 .request(
125 Method::POST,
126 &format!("/accounts/{account_id}/plan/withdraw-backing"),
127 Some(params),
128 )
129 .await
130 }
131
132 pub async fn migrate(&self, account_id: &str, params: &MigrateParams) -> Result<Plan> {
133 self.inner
134 .request(
135 Method::POST,
136 &format!("/accounts/{account_id}/plan/migrate"),
137 Some(params),
138 )
139 .await
140 }
141
142 pub async fn swap_and_supply(
143 &self,
144 account_id: &str,
145 params: &SwapAndSupplyParams,
146 ) -> Result<Plan> {
147 self.inner
148 .request(
149 Method::POST,
150 &format!("/accounts/{account_id}/plan/swap-and-supply"),
151 Some(params),
152 )
153 .await
154 }
155
156 pub async fn reinvest_rewards(
157 &self,
158 account_id: &str,
159 params: &ReinvestRewardsParams,
160 ) -> Result<Plan> {
161 self.inner
162 .request(
163 Method::POST,
164 &format!("/accounts/{account_id}/plan/reinvest_rewards"),
165 Some(params),
166 )
167 .await
168 }
169
170 pub async fn execute(&self, account_id: &str, params: &ExecuteParams) -> Result<ExecuteResult> {
171 self.inner
172 .request(
173 Method::POST,
174 &format!("/accounts/{account_id}/plan/execute"),
175 Some(params),
176 )
177 .await
178 }
179}