mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
add decimals to pool calls (#1393)
* add decimals to pool calls Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * fix lock Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * fix ssh Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * update ocean Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * update ocean Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * remove screen fixes * update lib, contracts Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * fix package-lock Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * fix Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
This commit is contained in:
parent
1fcc3b1356
commit
aa54795c2b
17702
package-lock.json
generated
17702
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -24,7 +24,7 @@
|
||||
"@coingecko/cryptoformat": "^0.4.4",
|
||||
"@loadable/component": "^5.15.2",
|
||||
"@oceanprotocol/art": "^3.2.0",
|
||||
"@oceanprotocol/lib": "^1.0.0-next.37",
|
||||
"@oceanprotocol/lib": "^1.0.0-next.42",
|
||||
"@oceanprotocol/typographies": "^0.1.0",
|
||||
"@portis/web3": "^4.0.7",
|
||||
"@storybook/addon-storyshots": "^6.4.22",
|
||||
|
@ -16,12 +16,14 @@ export const poolDataQuery = gql`
|
||||
baseToken {
|
||||
address
|
||||
symbol
|
||||
decimals
|
||||
}
|
||||
baseTokenWeight
|
||||
baseTokenLiquidity
|
||||
datatoken {
|
||||
address
|
||||
symbol
|
||||
decimals
|
||||
}
|
||||
datatokenWeight
|
||||
datatokenLiquidity
|
||||
@ -43,10 +45,12 @@ export const poolDataQuery = gql`
|
||||
baseToken {
|
||||
address
|
||||
symbol
|
||||
decimals
|
||||
}
|
||||
datatoken {
|
||||
address
|
||||
symbol
|
||||
decimals
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,10 @@ export interface PoolInfo {
|
||||
weightDt: string
|
||||
datatokenSymbol: string
|
||||
datatokenAddress: string
|
||||
datatokenDecimals: number
|
||||
baseTokenSymbol: string
|
||||
baseTokenAddress: string
|
||||
baseTokenDecimals: number
|
||||
totalPoolTokens: string
|
||||
}
|
||||
|
||||
|
@ -99,8 +99,10 @@ function PoolProvider({ children }: { children: ReactNode }): ReactElement {
|
||||
weightDt: getWeight(poolData.datatokenWeight),
|
||||
datatokenSymbol: poolData.datatoken.symbol,
|
||||
datatokenAddress: poolData.datatoken.address,
|
||||
datatokenDecimals: poolData.datatoken.decimals,
|
||||
baseTokenSymbol: poolData.baseToken.symbol,
|
||||
baseTokenAddress: poolData.baseToken.address,
|
||||
baseTokenDecimals: poolData.baseToken.decimals,
|
||||
totalPoolTokens: poolData.totalShares
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,9 @@ export async function calculateBuyPrice(
|
||||
accessDetails.baseToken.address,
|
||||
accessDetails.datatoken.address,
|
||||
'1',
|
||||
consumeMarketPoolSwapFee
|
||||
consumeMarketPoolSwapFee,
|
||||
accessDetails.baseToken.decimals,
|
||||
accessDetails.datatoken.decimals
|
||||
)
|
||||
|
||||
return estimatedPrice
|
||||
@ -52,7 +54,8 @@ export async function buyDtFromPool(
|
||||
accessDetails.baseToken.address,
|
||||
accessDetails.addressOrId,
|
||||
dtPrice.tokenAmount,
|
||||
false
|
||||
false,
|
||||
accessDetails.baseToken.decimals
|
||||
)
|
||||
if (!approveTx) {
|
||||
return
|
||||
@ -63,7 +66,9 @@ export async function buyDtFromPool(
|
||||
{
|
||||
marketFeeAddress,
|
||||
tokenIn: accessDetails.baseToken.address,
|
||||
tokenOut: accessDetails.datatoken.address
|
||||
tokenOut: accessDetails.datatoken.address,
|
||||
tokenInDecimals: accessDetails.baseToken.decimals,
|
||||
tokenOutDecimals: accessDetails.datatoken.decimals
|
||||
},
|
||||
{
|
||||
// this is just to be safe
|
||||
@ -163,6 +168,7 @@ export function calcSingleOutGivenPoolIn(
|
||||
export async function getLiquidityByShares(
|
||||
pool: string,
|
||||
tokenAddress: string,
|
||||
tokenDecimals: number,
|
||||
shares: string,
|
||||
chainId: number
|
||||
): Promise<string> {
|
||||
@ -174,7 +180,9 @@ export async function getLiquidityByShares(
|
||||
const amountBaseToken = await poolInstance.calcSingleOutGivenPoolIn(
|
||||
pool,
|
||||
tokenAddress,
|
||||
shares
|
||||
shares,
|
||||
18,
|
||||
tokenDecimals
|
||||
)
|
||||
|
||||
return amountBaseToken
|
||||
|
@ -49,7 +49,9 @@ export default function FormAdd({
|
||||
const poolTokens = await poolInstance.calcPoolOutGivenSingleIn(
|
||||
poolData.id,
|
||||
poolInfo.baseTokenAddress,
|
||||
values.amount.toString()
|
||||
values.amount.toString(),
|
||||
18,
|
||||
poolInfo.baseTokenDecimals
|
||||
)
|
||||
setNewPoolTokens(poolTokens)
|
||||
const newPoolShareDecimal =
|
||||
@ -68,6 +70,7 @@ export default function FormAdd({
|
||||
calculatePoolShares()
|
||||
}, [
|
||||
poolInfo?.baseTokenAddress,
|
||||
poolInfo?.baseTokenDecimals,
|
||||
web3,
|
||||
values.amount,
|
||||
poolInfo?.totalPoolTokens,
|
||||
|
@ -77,7 +77,8 @@ export default function Add({
|
||||
|
||||
const poolReserve = await poolInstance.getReserve(
|
||||
poolData.id,
|
||||
poolInfo.baseTokenAddress
|
||||
poolInfo.baseTokenAddress,
|
||||
poolInfo.baseTokenDecimals
|
||||
)
|
||||
|
||||
const amountMaxPool = calcMaxExactIn(poolReserve)
|
||||
@ -97,6 +98,7 @@ export default function Add({
|
||||
isAssetNetwork,
|
||||
poolData?.id,
|
||||
poolInfo?.baseTokenAddress,
|
||||
poolInfo?.baseTokenDecimals,
|
||||
balance?.ocean
|
||||
])
|
||||
|
||||
|
@ -40,10 +40,14 @@ export default function Remove({
|
||||
const [amountOcean, setAmountOcean] = useState('0')
|
||||
const [isLoading, setIsLoading] = useState<boolean>()
|
||||
const [txId, setTxId] = useState<string>()
|
||||
const [slippage, setSlippage] = useState<string>('5')
|
||||
const [slippage, setSlippage] = useState(slippagePresets[0])
|
||||
const [minOceanAmount, setMinOceanAmount] = useState<string>('0')
|
||||
const [poolInstance, setPoolInstance] = useState<Pool>()
|
||||
|
||||
const poolInstance = new Pool(web3)
|
||||
useEffect(() => {
|
||||
if (!web3) return
|
||||
setPoolInstance(new Pool(web3))
|
||||
}, [web3])
|
||||
|
||||
async function handleRemoveLiquidity() {
|
||||
setIsLoading(true)
|
||||
@ -74,28 +78,21 @@ export default function Remove({
|
||||
// Calculate and set maximum shares user is able to remove
|
||||
//
|
||||
useEffect(() => {
|
||||
if (!accountId || !poolInfoUser?.poolShares || !poolInfo?.totalPoolTokens)
|
||||
return
|
||||
if (!accountId || !poolInfoUser || !poolInfo || !poolInstance) return
|
||||
|
||||
getMax(poolInstance, poolInfo, poolInfoUser, poolData).then((max) =>
|
||||
setAmountMaxPercent(max)
|
||||
)
|
||||
}, [
|
||||
accountId,
|
||||
poolInfoUser?.poolShares,
|
||||
poolInfo?.totalPoolTokens,
|
||||
poolInfoUser,
|
||||
poolInfo,
|
||||
poolInstance,
|
||||
poolData
|
||||
])
|
||||
}, [accountId, poolInfoUser, poolInfo, poolInstance, poolData])
|
||||
|
||||
const getValues = useRef(
|
||||
debounce(async (newAmountPoolShares) => {
|
||||
debounce(async (poolInstance, id, poolInfo, newAmountPoolShares) => {
|
||||
const newAmountOcean = await poolInstance.calcSingleOutGivenPoolIn(
|
||||
poolData?.id,
|
||||
poolInfo?.baseTokenAddress,
|
||||
newAmountPoolShares
|
||||
id,
|
||||
poolInfo.baseTokenAddress,
|
||||
newAmountPoolShares,
|
||||
18,
|
||||
poolInfo.baseTokenDecimals
|
||||
)
|
||||
setAmountOcean(newAmountOcean)
|
||||
}, 150)
|
||||
@ -103,21 +100,9 @@ export default function Remove({
|
||||
|
||||
// Check and set outputs when amountPoolShares changes
|
||||
useEffect(() => {
|
||||
if (
|
||||
!accountId ||
|
||||
!poolInfoUser?.poolShares ||
|
||||
!poolInfo?.totalPoolTokens ||
|
||||
!poolData?.id
|
||||
)
|
||||
return
|
||||
getValues.current(amountPoolShares)
|
||||
}, [
|
||||
amountPoolShares,
|
||||
accountId,
|
||||
poolInfoUser?.poolShares,
|
||||
poolData?.id,
|
||||
poolInfo?.totalPoolTokens
|
||||
])
|
||||
if (!accountId || !poolInfo || !poolData?.id || !poolInstance) return
|
||||
getValues.current(poolInstance, poolData?.id, poolInfo, amountPoolShares)
|
||||
}, [amountPoolShares, accountId, poolInfo, poolData?.id, poolInstance])
|
||||
|
||||
useEffect(() => {
|
||||
if (!amountOcean || amountPercent === '0') {
|
||||
|
@ -82,7 +82,15 @@ export default function FormTrade({
|
||||
values.type === 'sell'
|
||||
? poolInfo.baseTokenAddress
|
||||
: poolInfo.datatokenAddress,
|
||||
marketFeeAddress: appConfig.marketFeeAddress
|
||||
marketFeeAddress: appConfig.marketFeeAddress,
|
||||
tokenInDecimals:
|
||||
values.type === 'sell'
|
||||
? poolInfo.datatokenDecimals
|
||||
: poolInfo.baseTokenDecimals,
|
||||
tokenOutDecimals:
|
||||
values.type === 'sell'
|
||||
? poolInfo.baseTokenDecimals
|
||||
: poolInfo.datatokenDecimals
|
||||
}
|
||||
|
||||
const amountsInOutMaxFee: AmountsInMaxFee = {
|
||||
@ -120,7 +128,15 @@ export default function FormTrade({
|
||||
values.type === 'sell'
|
||||
? poolInfo.baseTokenAddress
|
||||
: poolInfo.datatokenAddress,
|
||||
marketFeeAddress: appConfig.marketFeeAddress
|
||||
marketFeeAddress: appConfig.marketFeeAddress,
|
||||
tokenInDecimals:
|
||||
values.type === 'sell'
|
||||
? poolInfo.datatokenDecimals
|
||||
: poolInfo.baseTokenDecimals,
|
||||
tokenOutDecimals:
|
||||
values.type === 'sell'
|
||||
? poolInfo.baseTokenDecimals
|
||||
: poolInfo.datatokenDecimals
|
||||
}
|
||||
|
||||
const amountsOutMaxFee: AmountsOutMaxFee = {
|
||||
|
@ -78,11 +78,13 @@ export default function Swap({
|
||||
async function calculateMaximum() {
|
||||
const datatokenLiquidity = await poolInstance.getReserve(
|
||||
poolData.id,
|
||||
poolData.datatoken.address
|
||||
poolData.datatoken.address,
|
||||
poolData.datatoken.decimals
|
||||
)
|
||||
const baseTokenLiquidity = await poolInstance.getReserve(
|
||||
poolData.id,
|
||||
poolData.baseToken.address
|
||||
poolData.baseToken.address,
|
||||
poolData.baseToken.decimals
|
||||
)
|
||||
if (values.type === 'buy') {
|
||||
const maxBaseTokenFromPool = calcMaxExactIn(baseTokenLiquidity)
|
||||
@ -98,7 +100,9 @@ export default function Swap({
|
||||
poolInfo.baseTokenAddress,
|
||||
poolInfo.datatokenAddress,
|
||||
maxBaseTokens.toString(),
|
||||
appConfig.consumeMarketPoolSwapFee
|
||||
appConfig.consumeMarketPoolSwapFee,
|
||||
poolInfo.baseTokenDecimals,
|
||||
poolInfo.datatokenDecimals
|
||||
)
|
||||
const maximumDt = new Decimal(maxDt.tokenAmount)
|
||||
.toDecimalPlaces(MAX_DECIMALS)
|
||||
@ -130,7 +134,9 @@ export default function Swap({
|
||||
poolInfo?.datatokenAddress,
|
||||
poolInfo?.baseTokenAddress,
|
||||
maxDatatokens.toString(),
|
||||
appConfig.consumeMarketPoolSwapFee
|
||||
appConfig.consumeMarketPoolSwapFee,
|
||||
poolInfo.datatokenDecimals,
|
||||
poolInfo.baseTokenDecimals
|
||||
)
|
||||
const maximumBasetokens = new Decimal(maxBaseTokens.tokenAmount)
|
||||
.toDecimalPlaces(MAX_DECIMALS)
|
||||
|
Loading…
Reference in New Issue
Block a user