Skip to content

Commit

Permalink
Merge pull request #6 from ergoplatform/feature/update-dexy-sdk
Browse files Browse the repository at this point in the history
update the Dexy SDK and address any related side effects
  • Loading branch information
deadit authored Jun 7, 2024
2 parents 32f8111 + f3b7b79 commit fcdeb6e
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 70 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"@ergolabs/ergo-dex-sdk": "^1.9.67-beta.2",
"@ergolabs/ergo-sdk": "^0.5.7",
"@ergolabs/ui-kit": "^2.4.31",
"@fleet-sdk/common": "^0.3.4",
"@fleet-sdk/core": "^0.3.4",
"@rollup/plugin-inject": "^5.0.3",
"@types/jest": "^27.0.1",
"@types/lodash": "^4.14.172",
Expand All @@ -20,7 +22,7 @@
"axios": "^0.24.0",
"axios-hooks": "^4.0.0",
"craco-less": "^1.20.0",
"dexy-sdk-ts": "0.2.4",
"dexy-sdk-ts": "0.3.3",
"ergo-lib-wasm-browser": "^0.23.0",
"eslint-plugin-react-hooks": "^4.2.0",
"lodash": "^4.17.21",
Expand Down
6 changes: 1 addition & 5 deletions src/components/BankInfo/BankInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { RustModule } from '@ergolabs/ergo-sdk';
import { Box, Flex, Typography, useDevice } from '@ergolabs/ui-kit';
import { Mint } from 'dexy-sdk-ts';
import React from 'react';
Expand All @@ -20,10 +19,7 @@ const BankInfo = () => {
return null;
}

const mint = new Mint(
RustModule.SigmaRust.ErgoBox.from_json(JSON.stringify(oracle)),
RustModule.SigmaRust.ErgoBox.from_json(JSON.stringify(lpBox)),
);
const mint = new Mint(oracle, lpBox);

return (
<Box borderRadius={'xl'} padding={4}>
Expand Down
8 changes: 2 additions & 6 deletions src/components/MintForm/MintForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ErgoBox, RustModule } from '@ergolabs/ergo-sdk';
import {
ArrowLeftOutlined,
Box,
Expand All @@ -12,7 +11,7 @@ import {
useDevice,
useForm,
} from '@ergolabs/ui-kit';
import { ArbitrageMint, Mint } from 'dexy-sdk-ts';
import { Mint } from 'dexy-sdk-ts';
import React, { FC, ReactNode, useMemo, useState } from 'react';
import { skip } from 'rxjs';

Expand Down Expand Up @@ -238,10 +237,7 @@ export const MintForm = () => {
return null;
}

const mint = new Mint(
RustModule.SigmaRust.ErgoBox.from_json(JSON.stringify(oracle)),
RustModule.SigmaRust.ErgoBox.from_json(JSON.stringify(lpBox)),
);
const mint = new Mint(oracle, lpBox);

return <MintFormContainer mint={mint} />;
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
ergoBoxToProxy,
ErgoTx,
RustModule,
UnsignedErgoTx,
} from '@ergolabs/ergo-sdk';
import { ergoBoxToProxy, UnsignedErgoTx } from '@ergolabs/ergo-sdk';
import {
Box,
Button,
Expand All @@ -12,12 +7,8 @@ import {
Modal,
Typography,
} from '@ergolabs/ui-kit';
import {
ArbitrageMint,
FreeMint,
Mint,
unsignedTxConnectorProxy,
} from 'dexy-sdk-ts';
import { ErgoAddress } from '@fleet-sdk/core';
import { ArbitrageMint, FreeMint, Mint } from 'dexy-sdk-ts';
import React, { FC } from 'react';
import { Observable } from 'rxjs';

Expand Down Expand Up @@ -97,26 +88,14 @@ export const MintConfirmationModal: FC<MintConfirmationModalProps> = ({

const txData = {
txFee: 1000000,
arbitrageMintIn: RustModule.SigmaRust.ErgoBox.from_json(
JSON.stringify(goldMintBox),
),
freeMintBox: RustModule.SigmaRust.ErgoBox.from_json(
JSON.stringify(freeMintBox),
),
lpIn: RustModule.SigmaRust.ErgoBox.from_json(JSON.stringify(lpBox)),
tracking101: RustModule.SigmaRust.ErgoBox.from_json(
JSON.stringify(trackingBox),
),
oracleBox: RustModule.SigmaRust.ErgoBox.from_json(
JSON.stringify(oracleBox),
),
bankIn: RustModule.SigmaRust.ErgoBox.from_json(JSON.stringify(bankBox)),
userIn: RustModule.SigmaRust.ErgoBoxes.from_boxes_json(
utxos.map((utxo) => ergoBoxToProxy(utxo)),
),
buybackBox: RustModule.SigmaRust.ErgoBox.from_json(
JSON.stringify(buybackBox),
),
arbitrageMintIn: goldMintBox,
freeMintBox: freeMintBox,
lpIn: lpBox,
tracking101: trackingBox,
oracleBox: oracleBox,
bankIn: bankBox,
userIn: utxos.map((utxo) => ergoBoxToProxy(utxo) as any),
buybackBox: buybackBox,
};

const mint = new Mint(txData.oracleBox, txData.lpIn);
Expand All @@ -130,14 +109,14 @@ export const MintConfirmationModal: FC<MintConfirmationModalProps> = ({
txData.buybackBox,
txData.bankIn,
txData.userIn,
RustModule.SigmaRust.Address.from_base58(address[0]),
ErgoAddress.fromBase58(address[0]),
txData.tracking101,
networkContext.height,
);

const tx = unsignedTxConnectorProxy(arbitrageMintTX);
const unsignedArbMintTx = arbitrageMintTX as unknown as UnsignedErgoTx;

onClose(submitMintTx(tx));
onClose(submitMintTx(unsignedArbMintTx));
} else {
const freeMint = mint.getMintObject() as FreeMint;
const freeMintTx = freeMint.createFreeMintTransaction(
Expand All @@ -147,12 +126,13 @@ export const MintConfirmationModal: FC<MintConfirmationModalProps> = ({
txData.buybackBox,
txData.bankIn,
txData.userIn,
RustModule.SigmaRust.Address.from_base58(address[0]),
ErgoAddress.fromBase58(address[0]),
networkContext.height,
);
const unsignedTx = unsignedTxConnectorProxy(freeMintTx);
const unsignedFreeMintTx =
freeMintTx.toEIP12Object() as unknown as UnsignedErgoTx;

onClose(submitMintTx(unsignedTx));
onClose(submitMintTx(unsignedFreeMintTx));
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useGold101.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Amount, Box } from '@fleet-sdk/common';
import { useCallback } from 'react';

import { applicationConfig } from '../applicationConfig';
import { useAxios } from '../utils/axios';

export const useGold101 = () => {
const [requestState, runRequest] = useAxios<any>(
const [requestState, runRequest] = useAxios<Box<Amount>>(
{
url: `${applicationConfig.dexybankUrl}/gold/tracking101Box`,
method: 'GET',
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useGoldBank.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Amount, Box } from '@fleet-sdk/common';
import { useCallback } from 'react';

import { applicationConfig } from '../applicationConfig';
import { useAxios } from '../utils/axios';

export const useGoldBank = () => {
const [requestState, runRequest] = useAxios<any>(
const [requestState, runRequest] = useAxios<Box<Amount>>(
{
url: `${applicationConfig.dexybankUrl}/gold/bank?ui=1`,
method: 'GET',
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useGoldBuyback.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Amount, Box } from '@fleet-sdk/common';
import { useCallback } from 'react';

import { applicationConfig } from '../applicationConfig';
import { useAxios } from '../utils/axios';

export const useGoldBuyback = () => {
const [requestState, runRequest] = useAxios<any>(
const [requestState, runRequest] = useAxios<Box<Amount>>(
{
url: `${applicationConfig.dexybankUrl}/gold/buyback?ui=1`,
method: 'GET',
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useGoldLp.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Amount, Box } from '@fleet-sdk/common';
import { useCallback } from 'react';

import { applicationConfig } from '../applicationConfig';
import { useAxios } from '../utils/axios';

export const useGoldLp = () => {
const [requestState, runRequest] = useAxios<any>(
const [requestState, runRequest] = useAxios<Box<Amount>>(
{
url: `${applicationConfig.dexybankUrl}/gold/lp`,
method: 'GET',
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useGoldMintArbitrage.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Amount, Box } from '@fleet-sdk/common';
import { useCallback } from 'react';

import { applicationConfig } from '../applicationConfig';
import { useAxios } from '../utils/axios';

export const useGoldMintArbitrage = () => {
const [requestState, runRequest] = useAxios<any>(
const [requestState, runRequest] = useAxios<Box<Amount>>(
{
url: `${applicationConfig.dexybankUrl}/gold/mint/arbitrage?ui=1`,
method: 'GET',
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useGoldMintFree.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Amount, Box } from '@fleet-sdk/common';
import { useCallback } from 'react';

import { applicationConfig } from '../applicationConfig';
import { useAxios } from '../utils/axios';

export const useGoldMintFree = () => {
const [requestState, runRequest] = useAxios<any>(
const [requestState, runRequest] = useAxios<Box<Amount>>(
{
url: `${applicationConfig.dexybankUrl}/gold/mint/free?ui=1`,
method: 'GET',
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useGoldOracle.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Amount, Box } from '@fleet-sdk/common';
import { useCallback } from 'react';

import { applicationConfig } from '../applicationConfig';
import { useAxios } from '../utils/axios';

export const useGoldOracle = () => {
const [requestState, runRequest] = useAxios<any>(
const [requestState, runRequest] = useAxios<Box<Amount>>(
{
url: `${applicationConfig.dexybankUrl}/gold/oracle`,
method: 'GET',
Expand Down
9 changes: 9 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ export default defineConfig({
find: /^~(.*)$/,
replacement: '$1',
},
{
find: /@fleet-sdk\/common/,
replacement: path.resolve(
__dirname,
'node_modules',
'@fleet-sdk',
'common',
),
},
],
},
css: {
Expand Down
Loading

0 comments on commit fcdeb6e

Please sign in to comment.