Skip to content
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
30 changes: 18 additions & 12 deletions src/components/AddLiquiditySection/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState, useEffect } from 'react';
import { useNetwork } from '../../context/NetworkContext';
import { useSwap } from '../../context/SwapContext';
import { to } from 'dero-xswd-api';
import { DERO_SCID, GHOST_EXCHANGE_SCID } from '../../constants/addresses';
import { gasEstimateSCArgs, to } from 'dero-xswd-api';
import { GHOST_EXCHANGE_SCID } from '../../constants/addresses';
import PrimaryButton from '../PrimaryButton';
import InputField from '../InputField';

Expand Down Expand Up @@ -37,7 +37,7 @@ const AddLiquiditySection: React.FC<AddLiquiditySectionProps> = ({ pair, setStat
const assetValue = trimToFiveDecimals(e.target.value);
setAssetAmount(assetValue);
if (currentRatio && assetValue) {
setDeroAmount((parseFloat(assetValue) * currentRatio).toFixed(5));
setDeroAmount((parseFloat(assetValue) * currentRatio - 0.00001 ).toFixed(5));
} else {
setDeroAmount('');
}
Expand All @@ -47,7 +47,7 @@ const AddLiquiditySection: React.FC<AddLiquiditySectionProps> = ({ pair, setStat
const deroValue = trimToFiveDecimals(e.target.value);
setDeroAmount(deroValue);
if (currentRatio && deroValue) {
setAssetAmount((parseFloat(deroValue) / currentRatio).toFixed(5));
setAssetAmount((parseFloat(deroValue) / currentRatio + 0.00001).toFixed(5));
} else {
setAssetAmount('');
}
Expand All @@ -62,20 +62,26 @@ const AddLiquiditySection: React.FC<AddLiquiditySectionProps> = ({ pair, setStat
setButtonDisabled(true);
setStatusMessage('Processing transaction...');

const assetAmountNum = Math.round(parseFloat(assetAmount) * 1e5);
const assetAmountNum = Math.round(parseFloat(assetAmount) * 1e5 );
const deroAmountNum = Math.round(parseFloat(deroAmount) * 1e5);

const response = await xswd.wallet.transfer({
scid: GHOST_EXCHANGE_SCID,
transfers: [
{ scid: pair, burn: assetAmountNum },
{ scid: DERO_SCID, burn: deroAmountNum },
],
sc_rpc: [
{ name: 'entrypoint', datatype: 'S', value: 'AddLiquidity' },
{ name: 't', datatype: 'S', value: pair },
{ name: 'u', datatype: 'U', value: 1 },
// The "destination" parameter requires a valid DERO address DIFFERENT FROM THE SENDER'S but, in this context, it serves solely
// to satisfy the RPC syntax. Rest assured, the DERO specified will be transferred to the Smart Contract, not the random address provided.
// In this case, the random address used is Captain's address, as disclosed in the genesis block:
// https://github.com/deroproject/derohe/blob/e9df1205b6603c62f0651d0e18e5e77a2584b15e/config/config.go#L103C28-L103C94
{ burn: deroAmountNum, destination: "dero1qykyta6ntpd27nl0yq4xtzaf4ls6p5e9pqu0k2x4x3pqq5xavjsdxqgny8270" },
{ scid: pair, burn: assetAmountNum }
],
sc_rpc: gasEstimateSCArgs(
GHOST_EXCHANGE_SCID,
"AddLiquidity", [
{ name: "u", value: 1 },
{ name: "t", value: pair },

]),
ringsize: 2,
});

Expand Down
24 changes: 15 additions & 9 deletions src/components/CreatePairModalContent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react';
import { useNetwork } from '../../context/NetworkContext';
import { to } from 'dero-xswd-api';
import { DERO_SCID, GHOST_EXCHANGE_SCID } from '../../constants/addresses';
import { gasEstimateSCArgs, to } from 'dero-xswd-api';
import { GHOST_EXCHANGE_SCID } from '../../constants/addresses';
import InputField from '../InputField';
import PrimaryButton from '../PrimaryButton';

Expand Down Expand Up @@ -39,16 +39,22 @@ const CreateTradingPairModalContent: React.FC = () => {
const deroAmountNum = Math.round(parseFloat(deroAmount) * 1e5);

const response = await xswd.wallet.transfer({
scid: GHOST_EXCHANGE_SCID, // Replace with actual SCID
scid: GHOST_EXCHANGE_SCID,
transfers: [
// The "destination" parameter requires a valid DERO address DIFFERENT FROM THE SENDER'S but, in this context, it serves solely
// to satisfy the RPC syntax. Rest assured, the DERO specified will be transferred to the Smart Contract, not the random address provided.
// In this case, the random address used is Captain's address, as disclosed in the genesis block:
// https://github.com/deroproject/derohe/blob/e9df1205b6603c62f0651d0e18e5e77a2584b15e/config/config.go#L103C28-L103C94
{ burn: deroAmountNum, destination: "dero1qykyta6ntpd27nl0yq4xtzaf4ls6p5e9pqu0k2x4x3pqq5xavjsdxqgny8270" },
{ scid: assetSCID, burn: assetAmountNum },
{ scid: DERO_SCID, burn: deroAmountNum }, // Replace with actual DERO SCID
],
sc_rpc: [
{ name: 'entrypoint', datatype: 'S', value: 'AddLiquidity' },
{ name: 't', datatype: 'S', value: assetSCID },
{ name: 'u', datatype: 'U', value: 1 },
],
sc_rpc: gasEstimateSCArgs(
GHOST_EXCHANGE_SCID,
"AddLiquidity", [
{ name: "u", value: 1 },
{ name: "t", value: assetSCID },

]),
ringsize: 2,
});

Expand Down
18 changes: 10 additions & 8 deletions src/components/RemoveLiquiditySection/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { useNetwork } from '../../context/NetworkContext';
import { to } from 'dero-xswd-api';
import { gasEstimateSCArgs, to } from 'dero-xswd-api';
import { GHOST_EXCHANGE_SCID } from '../../constants/addresses';
import PrimaryButton from '../PrimaryButton';
import InputField from '../InputField';
Expand Down Expand Up @@ -57,13 +57,15 @@ const RemoveLiquiditySection: React.FC<RemoveLiquiditySectionProps> = ({ pair, s

const response = await xswd.wallet.scinvoke({
scid: GHOST_EXCHANGE_SCID,
sc_rpc: [
{ name: 'entrypoint', datatype: 'S', value: 'RemoveLiquidity' },
{ name: 't', datatype: 'S', value: pair },
{ name: 'v', datatype: 'U', value: amountNum },
{ name: 'w', datatype: 'U', value: 1 },
{ name: 'y2', datatype: 'U', value: 1 },
],
sc_rpc: gasEstimateSCArgs(
GHOST_EXCHANGE_SCID,
"RemoveLiquidity", [
{ name: 't', value: pair },
{ name: 'v', value: amountNum },
{ name: 'w', value: 1 },
{ name: 'y2', value: 1 },

]),
ringsize: 2,
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/SwapForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ const SwapForm: React.FC = () => {
aria-label="Change direction"
style={{ background: 'none', border: 'none', outline: 'none' }}
>
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<line x1="12" y1="5" x2="12" y2="19"></line>
<polyline points="19 12 12 19 5 12"></polyline>
</svg>
Expand Down