Struct Token

Source
pub struct Token<T, P>{ /* private fields */ }

Implementations§

Source§

impl<T, P> Token<T, P>

Source

pub fn new( name: &str, address: &str, provider: P, ) -> Result<Self, Box<dyn Error>>

Examples found in repository?
examples/create_limit_orders.rs (line 150)
128async fn main() -> Result<()> {
129    let run_type: RunType = RunType::Local;
130
131    let localhost_margin_acc = "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318";
132    let localhost_orderbook = "0x6620454f509ce29875953ecdb1765E8Bf54422CC";
133    let localhost_forwarder = "0x0165878A594ca255338adfa4d48449f69242Eb8F";
134    let localhost_token_a = "0x5FbDB2315678afecb367f032d93F642f64180aa3";
135    let localhost_token_b = "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512";
136
137    let devnet_margin_acc = "0x2A3e86DF318d37895e320Ff49b22B1610D0Eb8Dc";
138    let devnet_orderbook = "0x3935fd532c12ad0cc5410b5a07b827c2a0feb869";
139    let devnet_forwarder = "";
140    let devnet_token_a = "0x962EfdaB911D02F6c7a73D84200FEb9Fe763770c";
141    let devnet_token_b = "0x962EfdaB911D02F6c7a73D84200FEb9Fe763770c";
142
143    let (provider, wallet) = setup();
144    let user = wallet.default_signer().address();
145
146    let (margin_account, orderbook, forwarder, wbtc, usdc) = match run_type {
147        RunType::Local => {
148            let margin_account =
149                MarginAccount::new("margin acc", localhost_margin_acc, provider.clone()).unwrap();
150            let wbtc = Token::new("wbtc", localhost_token_a, provider.clone()).unwrap();
151            let usdc = Token::new("usdc", localhost_token_b, provider.clone()).unwrap();
152
153            let orderbook = Arc::new(
154                Orderbook::new(localhost_orderbook, Arc::clone(&provider))
155                    .await
156                    .unwrap(),
157            );
158            let forwarder = Arc::new(
159                KuruForwarder::new(&localhost_forwarder, Arc::clone(&provider), wallet.clone())
160                    .unwrap(),
161            );
162
163            (margin_account, orderbook, forwarder, wbtc, usdc)
164        }
165        RunType::Devnet => {
166            let margin_account =
167                MarginAccount::new("margin acc", devnet_margin_acc, provider.clone()).unwrap();
168            let wbtc = Token::new("wbtc", devnet_token_a, provider.clone()).unwrap();
169            let usdc = Token::new("usdc", devnet_token_b, provider.clone()).unwrap();
170
171            let orderbook = Arc::new(
172                Orderbook::new(devnet_orderbook, Arc::clone(&provider))
173                    .await
174                    .unwrap(),
175            );
176            let forwarder = Arc::new(
177                KuruForwarder::new(&devnet_forwarder, Arc::clone(&provider), wallet.clone())
178                    .unwrap(),
179            );
180
181            (margin_account, orderbook, forwarder, wbtc, usdc)
182        }
183    };
184
185    let amount: alloy::primitives::Uint<256, 4> =
186        U256::from(100000000) * U256::from(10).pow(U256::from(18));
187    let _ = margin_account.deposit(&user, &usdc, &amount).await;
188    let _ = margin_account.deposit(&user, &wbtc, &amount).await;
189
190    let orders = generate_random_orders(100);
191
192    let order_id = process_orders(Arc::clone(&orderbook), Arc::new(provider), orders).await;
193    dbg!(order_id);
194
195    Ok(())
196}
More examples
Hide additional examples
examples/process_order.rs (line 161)
139async fn main() -> Result<()> {
140    let run_type: RunType = RunType::Local;
141
142    let localhost_margin_acc = "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318";
143    let localhost_orderbook = "0x29BdC6fc3Bb87fb461Bd41DBc50f9097123f6aef";
144    let localhost_forwarder = "0x0165878A594ca255338adfa4d48449f69242Eb8F";
145    let localhost_token_a = "0x5FbDB2315678afecb367f032d93F642f64180aa3";
146    let localhost_token_b = "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512";
147
148    let devnet_margin_acc = "0x2A3e86DF318d37895e320Ff49b22B1610D0Eb8Dc";
149    let devnet_orderbook = "0x3935fd532c12ad0cc5410b5a07b827c2a0feb869";
150    let devnet_forwarder = "";
151    let devnet_token_a = "0x962EfdaB911D02F6c7a73D84200FEb9Fe763770c";
152    let devnet_token_b = "0x962EfdaB911D02F6c7a73D84200FEb9Fe763770c";
153
154    let (provider, wallet) = setup();
155    let user = wallet.default_signer().address();
156
157    let (margin_account, orderbook, forwarder, wbtc, usdc) = match run_type {
158        RunType::Local => {
159            let margin_account =
160                MarginAccount::new("margin acc", localhost_margin_acc, provider.clone()).unwrap();
161            let wbtc = Token::new("wbtc", localhost_token_a, provider.clone()).unwrap();
162            let usdc = Token::new("usdc", localhost_token_b, provider.clone()).unwrap();
163
164            let orderbook = Arc::new(
165                Orderbook::new(localhost_orderbook, Arc::clone(&provider))
166                    .await
167                    .unwrap(),
168            );
169            let forwarder = Arc::new(
170                KuruForwarder::new(&localhost_forwarder, Arc::clone(&provider), wallet.clone())
171                    .unwrap(),
172            );
173
174            (margin_account, orderbook, forwarder, wbtc, usdc)
175        }
176        RunType::Devnet => {
177            let margin_account =
178                MarginAccount::new("margin acc", devnet_margin_acc, provider.clone()).unwrap();
179            let wbtc = Token::new("wbtc", devnet_token_a, provider.clone()).unwrap();
180            let usdc = Token::new("usdc", devnet_token_b, provider.clone()).unwrap();
181
182            let orderbook = Arc::new(
183                Orderbook::new(devnet_orderbook, Arc::clone(&provider))
184                    .await
185                    .unwrap(),
186            );
187            let forwarder = Arc::new(
188                KuruForwarder::new(&devnet_forwarder, Arc::clone(&provider), wallet.clone())
189                    .unwrap(),
190            );
191
192            (margin_account, orderbook, forwarder, wbtc, usdc)
193        }
194    };
195
196    let amount: alloy::primitives::Uint<256, 4> =
197        U256::from(100000000) * U256::from(10).pow(U256::from(18));
198    let _ = margin_account.deposit(&user, &usdc, &amount).await;
199    let _ = margin_account.deposit(&user, &wbtc, &amount).await;
200
201    let orders = generate_random_orders(100);
202
203    let order_id = process_orders(Arc::clone(&orderbook), Arc::new(provider), orders).await;
204    dbg!(order_id);
205
206    Ok(())
207}
examples/forwarder_test.rs (line 160)
138async fn main() -> Result<()> {
139    let run_type: RunType = RunType::Local;
140
141    let localhost_margin_acc = "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318";
142    let localhost_orderbook = "0x6620454f509ce29875953ecdb1765E8Bf54422CC";
143    let localhost_forwarder = "0x0165878A594ca255338adfa4d48449f69242Eb8F";
144    let localhost_token_a = "0x5FbDB2315678afecb367f032d93F642f64180aa3";
145    let localhost_token_b = "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512";
146
147    let devnet_margin_acc = "0x2A3e86DF318d37895e320Ff49b22B1610D0Eb8Dc";
148    let devnet_orderbook = "0x3935fd532c12ad0cc5410b5a07b827c2a0feb869";
149    let devnet_forwarder = "";
150    let devnet_token_a = "0x962EfdaB911D02F6c7a73D84200FEb9Fe763770c";
151    let devnet_token_b = "0x962EfdaB911D02F6c7a73D84200FEb9Fe763770c";
152
153    let (provider, wallet) = setup();
154    let user = wallet.default_signer().address();
155
156    let (margin_account, orderbook, forwarder, wbtc, usdc) = match run_type {
157        RunType::Local => {
158            let margin_account =
159                MarginAccount::new("margin acc", localhost_margin_acc, provider.clone()).unwrap();
160            let wbtc = Token::new("wbtc", localhost_token_a, provider.clone()).unwrap();
161            let usdc = Token::new("usdc", localhost_token_b, provider.clone()).unwrap();
162
163            let orderbook = Arc::new(
164                Orderbook::new(localhost_orderbook, Arc::clone(&provider))
165                    .await
166                    .unwrap(),
167            );
168            let forwarder = Arc::new(
169                KuruForwarder::new(&localhost_forwarder, Arc::clone(&provider), wallet.clone())
170                    .unwrap(),
171            );
172
173            (margin_account, orderbook, forwarder, wbtc, usdc)
174        }
175        RunType::Devnet => {
176            let margin_account =
177                MarginAccount::new("margin acc", devnet_margin_acc, provider.clone()).unwrap();
178            let wbtc = Token::new("wbtc", devnet_token_a, provider.clone()).unwrap();
179            let usdc = Token::new("usdc", devnet_token_b, provider.clone()).unwrap();
180
181            let orderbook = Arc::new(
182                Orderbook::new(devnet_orderbook, Arc::clone(&provider))
183                    .await
184                    .unwrap(),
185            );
186            let forwarder = Arc::new(
187                KuruForwarder::new(&devnet_forwarder, Arc::clone(&provider), wallet.clone())
188                    .unwrap(),
189            );
190
191            (margin_account, orderbook, forwarder, wbtc, usdc)
192        }
193    };
194
195    let amount: alloy::primitives::Uint<256, 4> =
196        U256::from(100000000) * U256::from(10).pow(U256::from(18));
197    let _ = margin_account.deposit(&user, &usdc, &amount).await;
198    let _ = margin_account.deposit(&user, &wbtc, &amount).await;
199
200    let data = "0x532c46db00000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001";
201
202    let forward_request = ForwardRequest {
203        from: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266".parse()?,
204        market: "0x6620454f509ce29875953ecdb1765E8Bf54422CC".parse()?,
205        value: U256::ZERO,
206        nonce: U256::ZERO,
207        data: data_str_to_bytes(data).unwrap(),
208    };
209    let signature = "0x489f2e040775c5c03a11b52e45d0143d2525772537a6c97be31bd29a1f51d1f6022471b865c08fe3bfd686ac20cee45a6e5a46b32d25d3aa20e6515adf7bb31b1c";
210
211    let tx_receipt = forwarder
212        .execute(
213            KuruRequest::ForwardRequest(forward_request),
214            signature.to_string(),
215        )
216        .await
217        .unwrap();
218
219    dbg!(tx_receipt);
220    Ok(())
221}
Source

pub fn address(&self) -> Address

Source

pub async fn token_supply(&self) -> Result<U256, Box<dyn Error>>

Source

pub async fn balance_of(&self, user: &Address) -> Result<U256, Box<dyn Error>>

Source

pub async fn allowance( &self, user: &Address, spender: &Address, ) -> Result<U256, Box<dyn Error>>

Source

pub async fn increase_allowance( &self, spender: &Address, amount: &U256, ) -> Result<FixedBytes<32>, Box<dyn Error>>

Auto Trait Implementations§

§

impl<T, P> Freeze for Token<T, P>

§

impl<T, P> RefUnwindSafe for Token<T, P>

§

impl<T, P> Send for Token<T, P>

§

impl<T, P> Sync for Token<T, P>

§

impl<T, P> Unpin for Token<T, P>

§

impl<T, P> UnwindSafe for Token<T, P>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,