From 9c0bc24dc53938d487df28e017d45d96fc414af9 Mon Sep 17 00:00:00 2001 From: Nick Adamson Date: Mon, 15 Jan 2024 11:27:53 -0800 Subject: [PATCH 1/2] fix: rust mm example; increase gas + handle sell orders --- .../rust/examples/maker/soft_quote_request.rs | 29 +++++++++++++++++-- .../rust/examples/maker/token_approvals.rs | 4 +-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/examples/rust/examples/maker/soft_quote_request.rs b/examples/rust/examples/maker/soft_quote_request.rs index 2301265..3c12920 100644 --- a/examples/rust/examples/maker/soft_quote_request.rs +++ b/examples/rust/examples/maker/soft_quote_request.rs @@ -43,7 +43,7 @@ pub fn validate_soft_quote(rfq: QuoteRequest) -> Option { // 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; } @@ -90,8 +90,33 @@ pub async fn handle_soft_quote_request( (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); } diff --git a/examples/rust/examples/maker/token_approvals.rs b/examples/rust/examples/maker/token_approvals.rs index 9a82638..65fe26b 100644 --- a/examples/rust/examples/maker/token_approvals.rs +++ b/examples/rust/examples/maker/token_approvals.rs @@ -14,8 +14,8 @@ pub async fn approve_tokens( // 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)); From b5a3d5ff7844d8d6298f2b288e1c44083db501b4 Mon Sep 17 00:00:00 2001 From: Nick Adamson Date: Mon, 15 Jan 2024 11:28:55 -0800 Subject: [PATCH 2/2] fix: update taker example to use v0.0.11 sdk - use Arb Sepolia - use SupportedAsset class --- examples/typescript/.prettierrc.json | 6 +++--- examples/typescript/package.json | 2 +- examples/typescript/src/RFQ_taker.ts | 29 ++++++++++++---------------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/examples/typescript/.prettierrc.json b/examples/typescript/.prettierrc.json index ca5084c..c6a1376 100644 --- a/examples/typescript/.prettierrc.json +++ b/examples/typescript/.prettierrc.json @@ -1,4 +1,4 @@ { - "trailingComma": "es5", - "singleQuote": true - } \ No newline at end of file + "trailingComma": "es5", + "singleQuote": true +} diff --git a/examples/typescript/package.json b/examples/typescript/package.json index a79f34e..8253f5f 100644 --- a/examples/typescript/package.json +++ b/examples/typescript/package.json @@ -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", diff --git a/examples/typescript/src/RFQ_taker.ts b/examples/typescript/src/RFQ_taker.ts index 7e1308a..f47dcee 100644 --- a/examples/typescript/src/RFQ_taker.ts +++ b/examples/typescript/src/RFQ_taker.ts @@ -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, @@ -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'; @@ -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(), }); @@ -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, }); @@ -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 = {