How to calculate maximum profitable trade amount when cross DEX arbitrage? - ethereum

For example Token A costs 1.00$ on Uniswap and 1.05$ on Sushiswap.
So I can buy Token A on Uniswap and sell on Sushiswap for profit.
Let's suppose the next conditions:
Uniswap reserve pool = 100 ETH / 100000 USDC. 1 ETH = 1000 USDC
Sushiswap reserve pool = 97 ETH / 105000 USDC. 1 ETH = 1082 USDC
How to calculate an optimal swap amount (accounting price impact) on Uniswap to sell for the maximum profit on Sushiswap?

Related

How to Manage FIFO rule for reducing stock in a Point of Sale

How to manage FIFO rule for reducing the stock after selling of their items.
The requirement is that when an item is sold in a large quantity let say 10000 units then system should reduce the stock according FIFO rule.
Now i explain in detail.
In below example when 10000 units of a same item are sold and system has 12000 units available in stock but these 12000 units were purchased in four different creditors at different stock i.e.
in 1st purchase 3000 units
in 2nd purchase 3000 units
in 3rd purchase 3000 units
in 4th purchase 3000 units
now when 10000 units are going to be sold i want that system should reduce the stock of these 10000 units of the item as following
3000 units (from 1st purchase) Current Stock will be 0 units
3000 units (from 2nd purchase) Current Stock will be 0 units
3000 units (from 3rd purchase) Current Stock will be 0 units
1000 units (from 4nd purchase) Current Stock will be 2000 units
how can I manage it?
I am using vb.net and mySQL 5.7 database server.
Use ordered UPDATE and use user-defined variable.
Demo:
UPDATE stock
SET sell = CASE WHEN #sell < purchase - sell
THEN sell + #sell + (#sell := 0)
ELSE 0 * (#sell := #sell - purchase + sell) + purchase
END
ORDER BY stock_id;
For parametrized query use
UPDATE stock
SET sell = CASE WHEN #sell < purchase - sell
THEN sell + #sell + (#sell := 0)
ELSE 0 * (#sell := #sell - purchase + sell) + purchase
END
WHERE (#sell := ?) -- <<- the amount to be sold
ORDER BY stock_id;
fiddle

How do I calculate the capacity factor of a company that uses trucks to do delivery in SQL

hope you are well.
I am trying to do an exercises where I have to calculate the capacity factor of the company that does deliveries around the word.
The total capacity factor must be expresses in %.
Data provided:
Kerb weight of the vehicle is its nladen (empty) weight
-GVM stands for gross vehicle weight. This is the maximum allowable laden weight for the vehicle.
-A single trip may last between 2 and 10 days.
-Departure_date
-Return_date
Does anybody now How to figure out at least the operation to calculate the capacity factor?
Every help is appreciate it.
¦ Capacity ¦
¦ 42% ¦

I want to get Opening & closing balance from my Transaction Table in MS Access Query

I have a table in MS access database with
Table name :
Transaction(*Trns_id, Trns_type, Tr_amount, Trns_date)
The table data is below
Trns_id Trns_type Tr_amount Trns_date
T001 Deposit 500 01-11-2016
T002 Deposit 2500 01-12-2016
T003 Withdrawal 2000 01-01-2017
T004 Deposit 1500 01-02-2017
T005 Deposit 1000 01-03-2017
T006 Deposit 1500 04-03-2017
T007 Withdrawal 1800 06-03-2017
T008 Withdrawal 2000 04-02-2017
I want to get a query with another two column Opening & Closing Balance
Opening of 1st row is 0 and opening of 2nd & next row is closing of previous row.
Closing calculated by
opening+(if trns_type=deposit then Tr_amount)- (if trns_type=withdrawal then Tr_amount)
Please MS Access query for this problem.
Output Like
Trns_id Trns_type Opening Tr_amount Trns_date Closing
T001 Deposit 0 500 01-11-2016 500
T002 Deposit 500 2500 01-12-2016 3000
T003 Withdrawal 3000 2000 01-01-2017 1000
T004 Deposit 1000 1500 01-02-2017 2500
T005 Deposit 2500 1000 01-03-2017 3500
T006 Deposit 3500 1500 04-03-2017 5000
T007 Withdrawal 5000 1800 06-03-2017 3200
T008 Withdrawal 3200 2000 04-02-2017 1200
Please help me
Thanks in advance
Query to pull values from previous record would be like:
SELECT *, (SELECT TOP 1 Tr_amount FROM Table1 AS Dup WHERE Dup.Trns_ID<Table1.Trns_id ORDER BY Trns_date DESC) AS PrevAmt, (SELECT TOP 1 Trns_type FROM Table1 AS Dup WHERE Dup.Trns_ID<Table1.Trns_id ORDER BY Trns_date DESC) AS PrevType FROM Table1;
Be aware this sort of nested query can perform slowly with large dataset.
Now use that query as RecordSource for report. Use textbox RunningSum property set to OverAll. Expressions in textboxes:
OpeningBal:
=Nz([PrevAmt],0)*IIf([PrevType]="Withdrawal",-1,1)
ClosingBal:
=[Tr_amount]*IIf([Trns_type]="Withdrawal",-1,1)

Can MySQL scale for hot record use case?

I am building a gaming system where users can exchange tokens in real time. Some of these users are super users who can receive millions of tokens from other users. I need persistent data store that keeps following user-token snapshot:
U1 300
U2 480
U3 900
U4 190000
If U1 sends 100 tokens to U4, following txns needs to happen as atomic
1. U1 debit 100
2. U4 credit 100
Now U4 being a superuser could have thousands of txns per second with various users. That is u4 record will be a hot record.
Can I use MySQL for persistence data store of U - token value? Will it scale? Remember I need ACID compliance since token is essentially money here so no room for error? Any suggestions?

Quality Measurement

Suppose we are using DPMO system of quality and if a person has done 100 points and the opportunity is 9 and the person has got 10 qfails out of 70 as 70 transaction got selected for quality audit, then what would be the formula of measuring his quality by DPMO system ? 10 errors , 100 transactions , 9 opportunity per transaction, transaction QC'd 70?
DPMO = (1,000,000 * number of defects)/(number of units * number of opportunities)
What does that give you?