Skip to content

Commit

Permalink
deploy ob with less code from client
Browse files Browse the repository at this point in the history
  • Loading branch information
NanezX committed Dec 6, 2023
1 parent 7006898 commit 6d3911a
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions subgraph/tests/utils/deploy/orderbook/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,36 @@
use crate::{
generated::{Orderbook, ORDERBOOK_ABI, ORDERBOOK_BYTECODE},
utils::{deploy::touch_deployer, get_provider, get_wallet},
utils::{deploy::touch_deployer, get_client},
};
use ethers::{
abi::Token,
contract::ContractFactory,
core::k256::ecdsa::SigningKey,
prelude::SignerMiddleware,
providers::{Http, Middleware, Provider},
signers::{Signer, Wallet},
providers::{Http, Provider},
signers::Wallet,
};
use std::sync::Arc;

pub async fn deploy_orderbook(
) -> anyhow::Result<Orderbook<SignerMiddleware<Provider<Http>, Wallet<SigningKey>>>> {
let wallet = get_wallet(0)?;
let provider = get_provider().await?;
let chain_id = provider.get_chainid().await?;

let client = Arc::new(SignerMiddleware::new(
provider.clone(),
wallet.clone().with_chain_id(chain_id.as_u64()),
));

// Deploying DISpair
let expression_deployer = touch_deployer().await?;

// Obtaining OB Meta bytes
let meta = std::fs::read("../meta/OrderBook.rain.meta")?;

let args = vec![Token::Tuple(vec![
Token::Address(expression_deployer.address()),
Token::Bytes(meta),
])];

let client = get_client(None).await?;

// Obtaining OB deploy transaction
let deploy_transaction = ContractFactory::new(
ORDERBOOK_ABI.clone(),
ORDERBOOK_BYTECODE.clone(),
client.clone(),
);

let contract = deploy_transaction.deploy_tokens(args)?.send().await?;

Ok(Orderbook::new(contract.address(), client))
Expand All @@ -51,14 +41,7 @@ impl Orderbook<SignerMiddleware<Provider<Http>, Wallet<SigningKey>>> {
&self,
wallet: &Wallet<SigningKey>,
) -> anyhow::Result<Orderbook<SignerMiddleware<Provider<Http>, Wallet<SigningKey>>>> {
let provider = get_provider().await?;
let chain_id = provider.get_chainid().await?;

let client = Arc::new(SignerMiddleware::new(
provider.clone(),
wallet.clone().with_chain_id(chain_id.as_u64()),
));

let client = get_client(Some(wallet.to_owned())).await?;
Ok(Orderbook::new(self.address(), client))
}
}

0 comments on commit 6d3911a

Please sign in to comment.