Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update TypeScript example Taker to use sdk@v0.0.11 #47

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions examples/rust/examples/maker/soft_quote_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn validate_soft_quote(rfq: QuoteRequest) -> Option<QuoteRequest> {

// Action needs to be valid
let action: Action = rfq.action.into();
if action != Action::Buy {
if action != Action::Buy && action != Action::Sell {
warn!("Received a RFQ with an invalid action.");
return None;
}
Expand Down Expand Up @@ -90,8 +90,33 @@ pub async fn handle_soft_quote_request<P: JsonRpcClient + 'static>(

(option, price)
}
Action::Sell => {
let option_id = U256::from(request_for_quote.identifier_or_criteria.clone().unwrap());
info!("Handling Sell Order for Option Id {:?}", option_id);

// We are offering the following price for the given option
let price = OfferItem {
item_type: i32::from(ItemType::Erc20 as u8),
token: Some(usdc_address.into()),
identifier_or_criteria: None,
start_amount: Some(U256::from(fee).mul(U256::exp10(6usize)).into()),
end_amount: Some(U256::from(fee).mul(U256::exp10(6usize)).into()),
};

// The option we want in return
let option = ConsiderationItem {
item_type: i32::from(ItemType::Erc1155 as u8),
token: Some(settlement_engine.address().into()),
identifier_or_criteria: Some(option_id.into()),
start_amount: request_for_quote.amount.clone(),
end_amount: request_for_quote.amount.clone(),
recipient: Some(signer.address().into()),
};

(price, option)
}
_ => {
info!("Received invalid action from the RFQ, returning no offer");
info!("Received invalid action {:?} from the RFQ, returning no offer", request_action);
let no_offer = create_soft_quote_no_offer(&request_for_quote, signer);
return Some(no_offer);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/rust/examples/maker/token_approvals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub async fn approve_tokens<P: JsonRpcClient + 'static>(
// Note: This approval logic is tied to what the example Taker is doing and may need to
// to be updated for your example
// Take gas estimation out of the equation which can be dicey on the Arbitrum testnet.
let gas = U256::from(500000u64);
let gas_price = U256::from(200).mul(U256::exp10(8usize));
let gas = U256::from(900000u64);
let gas_price = U256::from(300).mul(U256::exp10(8usize));

// Approval for the Seaport contract
let erc20_contract = bindings::erc20::Erc20::new(settings.usdc_address, Arc::clone(provider));
Expand Down
6 changes: 3 additions & 3 deletions examples/typescript/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"trailingComma": "es5",
"singleQuote": true
}
"trailingComma": "es5",
"singleQuote": true
}
2 changes: 1 addition & 1 deletion examples/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@bufbuild/protobuf": "^1.2.1",
"@connectrpc/connect": "^1.1.2",
"@connectrpc/connect-node": "^1.1.2",
"@valorem-labs-inc/sdk": "0.0.2-alpha.0",
"@valorem-labs-inc/sdk": "0.0.11",
"@wagmi/core": "^1.4.4",
"tsx": "^3.14.0",
"typescript": "^5.0.4",
Expand Down
29 changes: 12 additions & 17 deletions examples/typescript/src/RFQ_taker.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import {
Address,
createPublicClient,
createWalletClient,
http,
parseUnits,
} from 'viem';
import { createPublicClient, createWalletClient, http, parseUnits } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { arbitrumGoerli } from 'viem/chains';
import { arbitrumSepolia } from 'viem/chains';
import {
ERC20Contract,
ParsedQuoteResponse,
Expand All @@ -18,6 +12,7 @@ import {
trackCookieInterceptor,
Auth,
RFQ,
SupportedAsset,
} from '@valorem-labs-inc/sdk';
import { createPromiseClient } from '@connectrpc/connect';
import { createGrpcTransport } from '@connectrpc/connect-node';
Expand All @@ -31,12 +26,12 @@ const PRIVATE_KEY =
const account = privateKeyToAccount(PRIVATE_KEY);

const publicClient = createPublicClient({
chain: arbitrumGoerli,
chain: arbitrumSepolia,
transport: http(),
});
const walletClient = createWalletClient({
account,
chain: arbitrumGoerli,
chain: arbitrumSepolia,
transport: http(),
});

Expand Down Expand Up @@ -64,14 +59,14 @@ const valoremSDK = new ValoremSDK({
// get the WebTaker instance (essentially a wallet/account/signer, with some utility methods)
const webTaker = valoremSDK.webTaker;

// Our mock tokens on Arbitrum Goerli
const USDC_ADDRESS: Address = '0x8ae0eeedd35dbefe460df12a20823efde9e03458';
const WETH_ADDRESS: Address = '0x618b9a2db0cf23bb20a849daa2963c72770c1372';
// Our mock tokens on Arbitrum Sepolia
const USDC = SupportedAsset.fromSymbolAndChainId('USDC', 421614);
const WETH = SupportedAsset.fromSymbolAndChainId('WETH', 421614);

// contract instances
const clearinghouse = valoremSDK.clearinghouse;
const usdc = new ERC20Contract({
address: USDC_ADDRESS,
address: USDC.address,
publicClient,
walletClient,
});
Expand All @@ -95,10 +90,10 @@ async function authenticate() {
// 2. Initialize an option with Valorem Clearinghouse
async function createOptionType() {
// Configure your own option type here!
const underlyingAsset = WETH_ADDRESS;
const exerciseAsset = USDC_ADDRESS;
const underlyingAsset = WETH.address;
const exerciseAsset = USDC.address;
const underlyingAmount = 1000000000000n; // 1 WETH, divided by 1e6
const exerciseAmount = 1575n; // 1575 USDC, divided by 1e6
const exerciseAmount = 2500n; // 2500 USDC, divided by 1e6
const { exerciseTimestamp, expiryTimestamp } = get24HrTimestamps();

const optionInfo = {
Expand Down
Loading