Skip to content

Commit 68e0105

Browse files
Merge pull request #11 from ThreeDotsTech/fix/sc-rpc-building
Fix transaction building process and update SC invocation methods
2 parents 21c6758 + 734bb7b commit 68e0105

4 files changed

Lines changed: 44 additions & 30 deletions

File tree

src/components/AddLiquiditySection/index.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { useState, useEffect } from 'react';
22
import { useNetwork } from '../../context/NetworkContext';
33
import { useSwap } from '../../context/SwapContext';
4-
import { to } from 'dero-xswd-api';
5-
import { DERO_SCID, GHOST_EXCHANGE_SCID } from '../../constants/addresses';
4+
import { gasEstimateSCArgs, to } from 'dero-xswd-api';
5+
import { GHOST_EXCHANGE_SCID } from '../../constants/addresses';
66
import PrimaryButton from '../PrimaryButton';
77
import InputField from '../InputField';
88

@@ -37,7 +37,7 @@ const AddLiquiditySection: React.FC<AddLiquiditySectionProps> = ({ pair, setStat
3737
const assetValue = trimToFiveDecimals(e.target.value);
3838
setAssetAmount(assetValue);
3939
if (currentRatio && assetValue) {
40-
setDeroAmount((parseFloat(assetValue) * currentRatio).toFixed(5));
40+
setDeroAmount((parseFloat(assetValue) * currentRatio - 0.00001 ).toFixed(5));
4141
} else {
4242
setDeroAmount('');
4343
}
@@ -47,7 +47,7 @@ const AddLiquiditySection: React.FC<AddLiquiditySectionProps> = ({ pair, setStat
4747
const deroValue = trimToFiveDecimals(e.target.value);
4848
setDeroAmount(deroValue);
4949
if (currentRatio && deroValue) {
50-
setAssetAmount((parseFloat(deroValue) / currentRatio).toFixed(5));
50+
setAssetAmount((parseFloat(deroValue) / currentRatio + 0.00001).toFixed(5));
5151
} else {
5252
setAssetAmount('');
5353
}
@@ -62,20 +62,26 @@ const AddLiquiditySection: React.FC<AddLiquiditySectionProps> = ({ pair, setStat
6262
setButtonDisabled(true);
6363
setStatusMessage('Processing transaction...');
6464

65-
const assetAmountNum = Math.round(parseFloat(assetAmount) * 1e5);
65+
const assetAmountNum = Math.round(parseFloat(assetAmount) * 1e5 );
6666
const deroAmountNum = Math.round(parseFloat(deroAmount) * 1e5);
6767

6868
const response = await xswd.wallet.transfer({
6969
scid: GHOST_EXCHANGE_SCID,
7070
transfers: [
71-
{ scid: pair, burn: assetAmountNum },
72-
{ scid: DERO_SCID, burn: deroAmountNum },
73-
],
74-
sc_rpc: [
75-
{ name: 'entrypoint', datatype: 'S', value: 'AddLiquidity' },
76-
{ name: 't', datatype: 'S', value: pair },
77-
{ name: 'u', datatype: 'U', value: 1 },
71+
// The "destination" parameter requires a valid DERO address DIFFERENT FROM THE SENDER'S but, in this context, it serves solely
72+
// to satisfy the RPC syntax. Rest assured, the DERO specified will be transferred to the Smart Contract, not the random address provided.
73+
// In this case, the random address used is Captain's address, as disclosed in the genesis block:
74+
// https://github.com/deroproject/derohe/blob/e9df1205b6603c62f0651d0e18e5e77a2584b15e/config/config.go#L103C28-L103C94
75+
{ burn: deroAmountNum, destination: "dero1qykyta6ntpd27nl0yq4xtzaf4ls6p5e9pqu0k2x4x3pqq5xavjsdxqgny8270" },
76+
{ scid: pair, burn: assetAmountNum }
7877
],
78+
sc_rpc: gasEstimateSCArgs(
79+
GHOST_EXCHANGE_SCID,
80+
"AddLiquidity", [
81+
{ name: "u", value: 1 },
82+
{ name: "t", value: pair },
83+
84+
]),
7985
ringsize: 2,
8086
});
8187

src/components/CreatePairModalContent/index.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22
import { useNetwork } from '../../context/NetworkContext';
3-
import { to } from 'dero-xswd-api';
4-
import { DERO_SCID, GHOST_EXCHANGE_SCID } from '../../constants/addresses';
3+
import { gasEstimateSCArgs, to } from 'dero-xswd-api';
4+
import { GHOST_EXCHANGE_SCID } from '../../constants/addresses';
55
import InputField from '../InputField';
66
import PrimaryButton from '../PrimaryButton';
77

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

4141
const response = await xswd.wallet.transfer({
42-
scid: GHOST_EXCHANGE_SCID, // Replace with actual SCID
42+
scid: GHOST_EXCHANGE_SCID,
4343
transfers: [
44+
// The "destination" parameter requires a valid DERO address DIFFERENT FROM THE SENDER'S but, in this context, it serves solely
45+
// to satisfy the RPC syntax. Rest assured, the DERO specified will be transferred to the Smart Contract, not the random address provided.
46+
// In this case, the random address used is Captain's address, as disclosed in the genesis block:
47+
// https://github.com/deroproject/derohe/blob/e9df1205b6603c62f0651d0e18e5e77a2584b15e/config/config.go#L103C28-L103C94
48+
{ burn: deroAmountNum, destination: "dero1qykyta6ntpd27nl0yq4xtzaf4ls6p5e9pqu0k2x4x3pqq5xavjsdxqgny8270" },
4449
{ scid: assetSCID, burn: assetAmountNum },
45-
{ scid: DERO_SCID, burn: deroAmountNum }, // Replace with actual DERO SCID
46-
],
47-
sc_rpc: [
48-
{ name: 'entrypoint', datatype: 'S', value: 'AddLiquidity' },
49-
{ name: 't', datatype: 'S', value: assetSCID },
50-
{ name: 'u', datatype: 'U', value: 1 },
5150
],
51+
sc_rpc: gasEstimateSCArgs(
52+
GHOST_EXCHANGE_SCID,
53+
"AddLiquidity", [
54+
{ name: "u", value: 1 },
55+
{ name: "t", value: assetSCID },
56+
57+
]),
5258
ringsize: 2,
5359
});
5460

src/components/RemoveLiquiditySection/index.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react';
22
import { useNetwork } from '../../context/NetworkContext';
3-
import { to } from 'dero-xswd-api';
3+
import { gasEstimateSCArgs, to } from 'dero-xswd-api';
44
import { GHOST_EXCHANGE_SCID } from '../../constants/addresses';
55
import PrimaryButton from '../PrimaryButton';
66
import InputField from '../InputField';
@@ -57,13 +57,15 @@ const RemoveLiquiditySection: React.FC<RemoveLiquiditySectionProps> = ({ pair, s
5757

5858
const response = await xswd.wallet.scinvoke({
5959
scid: GHOST_EXCHANGE_SCID,
60-
sc_rpc: [
61-
{ name: 'entrypoint', datatype: 'S', value: 'RemoveLiquidity' },
62-
{ name: 't', datatype: 'S', value: pair },
63-
{ name: 'v', datatype: 'U', value: amountNum },
64-
{ name: 'w', datatype: 'U', value: 1 },
65-
{ name: 'y2', datatype: 'U', value: 1 },
66-
],
60+
sc_rpc: gasEstimateSCArgs(
61+
GHOST_EXCHANGE_SCID,
62+
"RemoveLiquidity", [
63+
{ name: 't', value: pair },
64+
{ name: 'v', value: amountNum },
65+
{ name: 'w', value: 1 },
66+
{ name: 'y2', value: 1 },
67+
68+
]),
6769
ringsize: 2,
6870
});
6971

src/components/SwapForm/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ const SwapForm: React.FC = () => {
302302
aria-label="Change direction"
303303
style={{ background: 'none', border: 'none', outline: 'none' }}
304304
>
305-
<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">
305+
<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">
306306
<line x1="12" y1="5" x2="12" y2="19"></line>
307307
<polyline points="19 12 12 19 5 12"></polyline>
308308
</svg>

0 commit comments

Comments
 (0)