Skip to content
Open
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
940 changes: 656 additions & 284 deletions src/abis/future-option-power/OrderBook.json

Large diffs are not rendered by default.

144 changes: 129 additions & 15 deletions src/abis/future-option-power/Reader.json

Large diffs are not rendered by default.

1,681 changes: 167 additions & 1,514 deletions src/acy-dex-futures/abis/OrderBook.json

Large diffs are not rendered by default.

74 changes: 73 additions & 1 deletion src/acy-dex-futures/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2080,7 +2080,7 @@ function getToken(address) {
}

export function formatNumber(number){
// number = number.toLocaleString('fullwide', {useGrouping:false})
if (number=="0.0"){return number}
let negative = false;
if (number<0){
negative = true;
Expand Down Expand Up @@ -2149,4 +2149,76 @@ export async function getOracleSignature(){
});
console.log("signatures",signatures)
return signatures
}

function safeDiv(a, b) {
return b.isZero() ? BigNumber.from(0) : a.div(b);
}
function safeDiv2(a, b) {
return b == 0 ? 0 : a / b;
}

export function getPosition(rawPositionData, symbolData) {
if (!rawPositionData || !symbolData) {
return
}
let positionQuery = []
for (let i = 0; i < rawPositionData.positions.length; i++) {
const temp = rawPositionData.positions[i]
const volume = ethers.utils.formatUnits(temp.volume, 18)
if (volume != 0) {
const symbol = symbolData.find(obj => {
return obj.address === temp[0]
})
const { markPrice, initialMarginRatio, indexPrice, curIndexPrice, minTradeVolume } = symbol

const cost = ethers.utils.formatUnits(temp.cost, 18)
const cumulativeFundingPerVolume = ethers.utils.formatUnits(temp.cumulativeFundingPerVolume, 18)
const marginUsage = ethers.utils.formatUnits(temp.marginUsed, 18)
const unrealizedPnl = volume * curIndexPrice - cost
const _accountFunding = temp.cumulativeFundingPerVolume.mul(temp.volume)
const accountFunding = ethers.utils.formatUnits(_accountFunding, 36)
const entryPrice = safeDiv2(cost, volume)
const liquidationPrice = ethers.utils.formatUnits(temp.liquidationPrice, 18)

const position = {
symbol: temp[1],
address: temp[0],
position: Math.abs(volume),
entryPrice: entryPrice,
markPrice: markPrice,
marginUsage: marginUsage,
unrealizedPnl: unrealizedPnl,
accountFunding: accountFunding,
type: volume >= 0 ? "Long" : "Short",
minTradeVolume: minTradeVolume,
liquidationPrice: liquidationPrice,
};
positionQuery.push(position)
}
}
return positionQuery;
}

export function getSymbol(rawSymbolData) {
if (!rawSymbolData) {
return
}
let symbolQuery = []
for (let i = 0; i < rawSymbolData.length; i++) {
const temp = rawSymbolData[i]
const symbol = {
tokenname: temp[1]?.substring(0, 3),
symbol: temp[1],
address: temp[2],
markPrice: ethers.utils.formatUnits(temp.markPrice, 18),
indexPrice: ethers.utils.formatUnits(temp.indexPrice, 18),
curIndexPrice: ethers.utils.formatUnits(temp.curIndexPrice, 18),
initialMarginRatio: ethers.utils.formatUnits(temp.initialMarginRatio, 18), //0.1
minTradeVolume: ethers.utils.formatUnits(temp.minTradeVolume, 18)

};
symbolQuery.push(symbol)
}
return symbolQuery;
}
7 changes: 4 additions & 3 deletions src/components/AcyPool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ const AcyPool = props => {
updateTokenInfo,
])

const alpPrice = poolInfo ? poolInfo.totalSupply.gt(0) ? parseInt(poolInfo.liquidity) / parseInt(poolInfo.totalSupply) : expandDecimals(1, USD_DECIMALS) : bigNumberify(0)
const alpBalanceUsd = alpBalance ? alpBalance.mul(parseValue(alpPrice, ALP_DECIMALS)) : bigNumberify(0)
const alpSupplyUsd = alpSupply ? alpSupply.mul(parseValue(alpPrice, ALP_DECIMALS)) : bigNumberify(0)
let alpPrice = poolInfo ? poolInfo.totalSupply.gt(0) ? parseInt(poolInfo.liquidity) / parseInt(poolInfo.totalSupply) : expandDecimals(1, USD_DECIMALS) : bigNumberify(0)
alpPrice = parseValue(alpPrice, ALP_DECIMALS)
const alpBalanceUsd = alpBalance ? alpBalance.mul(alpPrice) : bigNumberify(0)
const alpSupplyUsd = alpSupply ? alpSupply.mul(alpPrice) : bigNumberify(0)
const aum = lpInfo ? lpInfo.liquidity : bigNumberify(0)

return (
Expand Down
6 changes: 4 additions & 2 deletions src/components/ClosePositionModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ export const ClosePositionModal = ({isModalVisible,onCancel,position,chainId, ..
account,
position.symbol,
ethers.utils.parseUnits(tokenAmount.toString(),18).mul(bigNumberify(-1)),
ethers.utils.parseUnits(markPrice,18).mul(bigNumberify(10000 - INITIAL_ALLOWED_SLIPPAGE * 100)).div(bigNumberify(10000))
ethers.utils.parseUnits(markPrice,18).mul(bigNumberify(10000 - INITIAL_ALLOWED_SLIPPAGE * 100)).div(bigNumberify(10000)),
[]
)
onCancel();
}else{
Expand All @@ -171,7 +172,8 @@ export const ClosePositionModal = ({isModalVisible,onCancel,position,chainId, ..
account,
position.symbol,
ethers.utils.parseUnits(tokenAmount.toString(),18),
ethers.utils.parseUnits(markPrice,18).mul(bigNumberify(10000 + INITIAL_ALLOWED_SLIPPAGE * 100)).div(bigNumberify(10000))
ethers.utils.parseUnits(markPrice,18).mul(bigNumberify(10000 + INITIAL_ALLOWED_SLIPPAGE * 100)).div(bigNumberify(10000)),
[]
)
onCancel();
}
Expand Down
17 changes: 0 additions & 17 deletions src/components/OptionComponent/TableComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,6 @@ export function PositionTable(props){
},
visible: true,
},
{
title: (
<div
className={styles.tableHeader}
// onClick={() => { setCurrentKey('marginUsage') }}
>
Margin Usage
</div>
),
dataIndex: 'marginUsage',
// key: 'marginUsage',
render: (text, entry) => {
let res = formatNumber(entry.marginUsage)
return <div className={styles.tableData}>{res}</div>;
},
visible: true,
},
{
title: (
<div
Expand Down
36 changes: 26 additions & 10 deletions src/constants/future_option_power.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,37 @@ const contracts = {

},
80001: {
Vault: '0xF2703340D15564e498E5Ece20e2451C78b1B99b3',
NATIVE_TOKEN: '0x01a1F94C1Ab2f308Aeb10C623B865d83bf1befdB',
Vault: '0x49941617e8D6014568b789D78Dc159A8D9e70b5A',
NATIVE_TOKEN: '0x95E9b1583eb004F02F16a9449455dd605e834a55',

oracleManager: '0x0682E645A264c7Afba84b79365A4f6c0D4a38765',
pool: '0xA6177E34ab046007b75e887569108aa7809EE50F',
poolImplementation: '0x133B3425033759C649F8A894983D21B44A0Fb732',
symbolManager: "0xd85aA6DcaEfECd49C8b64f5888d9961208AF4a19",
symbolManagerImplementation: "0x639A5C58FEd6319a8414e7F36d512b02e2159a91",
alp: "0xaC56beE2F6D0cfb9555bdC191DE1C4311C6675da",
symbolsLens: "0x0FDa27b043793e2658Bf0F795400c65aF7Aa8A2A",
reader: "0x21de483f50ED649Cc78a7148Aed1cA1D954E3521",
pool: '0x17C930cA189b4ae30B52A387fE2E9276639fdDdE',
poolImplementation: '0x9F25cf90F0BF9828f0b472Cd281D71b997e5Bbees',
symbolManager: "0xAd3a726c70bEDF463996fdd8484c2350403ac0bc",
symbolManagerImplementation: "0x4712C4F56991EdE8C8a27E7a45496912547788F0",
alp: "0xD3CB938cE8CEA584B63dA0e5a7F4C230d8Aa83a1",
symbolsLens: "0x5Ac237B55D872076Ee9fA98f7798f42bF9336fAf",
reader: "0x73298651AEB48344b43a08Fd577350fa4c4E6f8b",
router: "0xcd628fEe33E06d1A53a2fAebe791eD8fB8aC620b",

orderbook: "0x9e6a49898F719B6491A64B2e23Fafa465C5Bd1D1",
orderbook: "0xEBcBcfC385841bF5053d8313AD3f84b6E4A1deb0",
},
421613: {
Vault: '0x4B3C4C41c2B5Be2e5126b9EF124D6b705cbF03eD',
NATIVE_TOKEN: '0xE971616d94335dec2E54939118AdFcB68E6dCAd6',

oracleManager: '0xc13D02F8134F4AeA81e9434DA0cBf37D101FC58E',
pool: '0x941c97E5A11B6674549965057cB61E5dB0D6E5c2',
poolImplementation: '0x0528C05204096D1F240c6Af7bDEfD899F07A9784',
symbolManager: "0x42aD6CB121eDAF9B05551DC5D0F1cB4B422DC3aa",
symbolManagerImplementation: "0x0c9c80A9B88A628284392B7Fe470EB377580C5aa",
alp: "0xC759054466d321e2F93137657435B1c752c2e427",
symbolsLens: "0x3227CC3235C41a62aAD597b56A9174984b1040C0",
reader: "0x545FE5455e37977960E4d5c2A6e5feaC2cbFBf55",
router: "0xcd628fEe33E06d1A53a2fAebe791eD8fB8aC620b",

orderbook: "0xeC3142E07C211FCB261D37eB82B20e0A595EbB25",
}
}

const tokenLists = {
Expand Down
34 changes: 32 additions & 2 deletions src/pages/Future/Index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import { useChainId } from '@/utils/helpers';
import { getTokens, getContract } from '@/constants/future_option_power.js';
import AcySymbolNav from '@/components/AcySymbolNav';
import AcySymbol from '@/components/AcySymbol';
import { fetcher } from '@/acy-dex-futures/utils';
import { fetcher, getSymbol, getPosition } from '@/acy-dex-futures/utils';
import Reader from '@/abis/future-option-power/Reader.json'
import styles from './styles.less'
import { PositionTable } from '@/components/OptionComponent/TableComponent';


const Future = props => {
Expand All @@ -36,18 +37,26 @@ const Future = props => {
const { data: symbolsInfo, mutate: updateSymbolsInfo } = useSWR([chainId, readerAddress, "getSymbolsInfo", poolAddress, []], {
fetcher: fetcher(library, Reader)
});

const { data: rawPositionData, mutate: updatePosition } = useSWR([chainId, readerAddress, 'getTdInfo', poolAddress, account], {
fetcher: fetcher(library, Reader)
})
const symbolData = getSymbol(symbolsInfo)
const positionData = getPosition(rawPositionData, symbolData)
const [tableContent, setTableContent] = useState("Positions");

useEffect(() => {
if (active) {
library.on('block', () => {
updateSymbolsInfo(undefined, true)
updatePosition()
})
return () => {
library.removeAllListeners('block')
}
}
}, [active, library, chainId,
updateSymbolsInfo]
updateSymbolsInfo,updatePosition]
)

const future_tokens_symbol = useMemo(() => {
Expand Down Expand Up @@ -104,6 +113,27 @@ const Future = props => {
setDailyVol={setDailyVol}
/>
</div>
<div className={styles.bottomWrapper}>
<div className={styles.bottomTab}>
<ComponentTabs
option={tableContent}
options={["Positions", "Orders"]}
onChange={item => { setTableContent(item) }}
/>
</div>
</div>
<AcyCard style={{ backgroundColor: 'transparent', padding: '10px', width: '100%', borderTop: '0.75px solid #333333', borderRadius: '0' }}>
<div className={`${styles.colItem} ${styles.priceChart}`}>
<div className={styles.positionsTable}>
{tableContent == "Positions" && (
<PositionTable dataSource={positionData} chainId={chainId} />
)}
{tableContent == "Orders" && (
<div>ORDERS</div>
)}
</div>
</div>
</AcyCard>
</div>
}

Expand Down
14 changes: 14 additions & 0 deletions src/pages/Future/styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
margin: auto;
flex-wrap: wrap;
justify-content: space-between;

.bottomWrapper {
display: flex;
flex-direction: column;
justify-content: stretch;

.bottomTab {
border-top: 0.75px solid #444444;
border-bottom: 0.75px solid #444444;
padding-right: 60%;
margin-bottom: 0px;
font-size: 5px;
}
}
}

@media screen and (min-width: 1024px) {
Expand Down
80 changes: 1 addition & 79 deletions src/pages/Option/Index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ComponentTabs from '@/components/ComponentTabs';
import ExchangeTVChart from '@/components/ExchangeTVChart/ExchangeTVChart';
import AcyPool from '@/components/AcyPool';
import * as Api from '@/acy-dex-futures/Api';
import { fetcher, getProvider, bigNumberify } from '@/acy-dex-futures/utils';
import { fetcher, getProvider, bigNumberify, getSymbol, getPosition } from '@/acy-dex-futures/utils';
import { useConstantLoader } from '@/constants';
import { BigNumber, ethers } from 'ethers'
import Pool from '@/acy-dex-futures/abis/Pool.json'
Expand All @@ -20,84 +20,6 @@ import Reader from '@/abis/future-option-power/Reader.json'
import useSWR from 'swr'
import { useWeb3React } from '@web3-react/core';

function safeDiv(a, b) {
return b.isZero() ? BigNumber.from(0) : a.div(b);
}
function safeDiv2(a, b) {
return b == 0 ? 0 : a / b;
}

export function getPosition(rawPositionData, symbolData) {
if (!rawPositionData || !symbolData) {
return
}
let positionQuery = []
for (let i = 0; i < rawPositionData.positions.length; i++) {
const temp = rawPositionData.positions[i]
const volume = ethers.utils.formatUnits(temp[2], 18)
if (volume != 0) {
const symbol = symbolData.find(obj => {
return obj.address === temp[0]
})
const { markPrice, initialMarginRatio, indexPrice, minTradeVolume } = symbol

const cost = ethers.utils.formatUnits(temp.cost, 18)
const cumulativeFundingPerVolume = ethers.utils.formatUnits(temp.cumulativeFundingPerVolume, 18)
const marginUsage = Math.abs(volume * indexPrice) * initialMarginRatio
const unrealizedPnl = volume * indexPrice - cost
const _accountFunding = temp.cumulativeFundingPerVolume.mul(temp[2])
const accountFunding = ethers.utils.formatUnits(_accountFunding, 36)
const _entryPrice = safeDiv(temp.cost, temp[2])
// const entryPrice = ethers.utils.formatUnits(_entryPrice,0)
const entryPrice = safeDiv2(cost, volume)
let liquidationPrice
if (volume >= 0) {
liquidationPrice = markPrice * (1 - initialMarginRatio / 2) - (marginUsage - cost) / (volume * (1 - initialMarginRatio / 2))
} else {
liquidationPrice = markPrice * (1 + initialMarginRatio / 2) + (marginUsage - cost) / (volume * (1 + initialMarginRatio / 2))
}

const position = {
symbol: temp[1],
address: temp[0],
position: Math.abs(volume),
entryPrice: entryPrice,
markPrice: markPrice,
marginUsage: marginUsage,
unrealizedPnl: unrealizedPnl,
accountFunding: accountFunding,
type: volume >= 0 ? "Long" : "Short",
minTradeVolume: minTradeVolume,
liquidationPrice: liquidationPrice,
};
positionQuery.push(position)
}
}
return positionQuery;
}

export function getSymbol(rawSymbolData) {
if (!rawSymbolData) {
return
}
let symbolQuery = []
for (let i = 0; i < rawSymbolData.length; i++) {
const temp = rawSymbolData[i]
const symbol = {
tokenname: temp[1]?.substring(0, 3),
symbol: temp[1],
address: temp[2],
markPrice: ethers.utils.formatUnits(temp.markPrice, 18),
indexPrice: ethers.utils.formatUnits(temp.indexPrice, 18),
initialMarginRatio: ethers.utils.formatUnits(temp.initialMarginRatio, 18), //0.1
minTradeVolume: ethers.utils.formatUnits(temp.minTradeVolume, 18)

};
symbolQuery.push(symbol)
}
return symbolQuery;
}

const Option = props => {
const { account, library, active } = useWeb3React();
let { chainId } = useChainId();
Expand Down
Loading