Skip to content

Commit

Permalink
Merge pull request #153 from compolabs/feat/release-0.5.1
Browse files Browse the repository at this point in the history
[1710] Update smart contract to 0.5.1
  • Loading branch information
EchoDex authored Oct 7, 2024
2 parents 2548767 + 982b741 commit 97c8a0a
Show file tree
Hide file tree
Showing 13 changed files with 367 additions and 357 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"pnpm": ">=9.7.0"
},
"dependencies": {
"@compolabs/spark-orderbook-ts-sdk": "^1.8.8",
"@compolabs/spark-orderbook-ts-sdk": "^1.9.1",
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@fuels/connectors": "^0.9.1",
Expand All @@ -34,7 +34,7 @@
"copy-to-clipboard": "^3.3.3",
"dayjs": "^1.11.10",
"framer-motion": "^11.0.3",
"fuels": "^0.93.0",
"fuels": "^0.94.8",
"gh-pages": "^6.1.1",
"lodash": "^4.17.21",
"mixpanel-browser": "^2.53.0",
Expand Down
615 changes: 316 additions & 299 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion script/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default function getConfig() {
return {
name: "download-config",
async buildStart() {
const url = "https://raw.githubusercontent.com/compolabs/spark-frontend-config/main/config.json";
const url = "https://raw.githubusercontent.com/compolabs/spark-frontend-config/refs/heads/main/config.json";
const res = await fetch(url);
const json = await res.json();

Expand Down
10 changes: 3 additions & 7 deletions src/blockchain/FuelNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class FuelNetwork {
this.orderbookSdk = new SparkOrderBookSdk({
networkUrl: CONFIG.APP.networkUrl,
contractAddresses: {
orderbook: CONFIG.APP.contracts.orderbook,
registry: CONFIG.APP.contracts.registry,
multiAsset: CONFIG.APP.contracts.multiAsset,
},
});
Expand Down Expand Up @@ -161,10 +161,6 @@ export class FuelNetwork {
return this.orderbookSdk.subscribeTradeOrderEvents(...params);
};

fetchSpotMarketPrice = async (...params: Parameters<typeof this.orderbookSdk.fetchMarketPrice>): Promise<BN> => {
return this.orderbookSdk.fetchMarketPrice(...params);
};

fetchSpotOrders = async (params: GetActiveOrdersParams): Promise<SpotMarketOrder[]> => {
const { data } = await this.orderbookSdk.fetchActiveOrders(params);

Expand All @@ -181,8 +177,8 @@ export class FuelNetwork {
}
};

fetchSpotVolume = async (): Promise<SpotMarketVolume> => {
const data = await this.orderbookSdk.fetchVolume();
fetchSpotVolume = async (...params: Parameters<typeof this.orderbookSdk.fetchVolume>): Promise<SpotMarketVolume> => {
const data = await this.orderbookSdk.fetchVolume(...params);

return {
low: new BN(data.low24h),
Expand Down
30 changes: 15 additions & 15 deletions src/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "1.2.0",
"contractVer": 769,
"version": "1.3.0",
"contractVer": 1280,
"tokens": [
{
"name": "Ethereum",
Expand Down Expand Up @@ -30,39 +30,39 @@
"markets": [
{
"marketName": "ETHUSDC",
"owner": "0xd1ebb551a2d58f024875bcc6798e4e2f8c8feec9da718a9f29d362f14531a3ef",
"owner": "0xf47e0ef744ac8c993550e03d17f1c4844494553a12cac11ab8c568c8999fdbbf",
"baseAssetId": "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07",
"baseAssetDecimals": 9,
"quoteAssetId": "0x336b7c06352a4b736ff6f688ba6885788b3df16e136e95310ade51aa32dc6f05",
"quoteAssetDecimals": 6,
"priceDecimals": 9,
"version": 769,
"contractId": "0x7d1da52a221897ebc88dc6a5d4623e704f7d64022d498b0438827dd79b6e5457"
"version": 1281,
"contractId": "0x10860c51de3a37c47ebff2e08a810d9e2963ef161ee3a88274520938c85914e8"
},
{
"marketName": "BTCUSDC",
"owner": "0xd1ebb551a2d58f024875bcc6798e4e2f8c8feec9da718a9f29d362f14531a3ef",
"owner": "0xf47e0ef744ac8c993550e03d17f1c4844494553a12cac11ab8c568c8999fdbbf",
"baseAssetId": "0x38e4ca985b22625fff93205e997bfc5cc8453a953da638ad297ca60a9f2600bc",
"baseAssetDecimals": 8,
"quoteAssetId": "0x336b7c06352a4b736ff6f688ba6885788b3df16e136e95310ade51aa32dc6f05",
"quoteAssetDecimals": 6,
"priceDecimals": 9,
"version": 769,
"contractId": "0x416ccdaf69881ae345537b1844d1511b4103379fca43b8c2190aae8b42f08173"
"version": 1281,
"contractId": "0xbc69e42348c9a992100970e8469247b58a517c2f7dd373741c6707cda35ccfc6"
}
],
"indexers": {
"0x416ccdaf69881ae345537b1844d1511b4103379fca43b8c2190aae8b42f08173": {
"httpUrl": "https://indexer.bigdevenergy.link/4cba550/v1/graphql",
"wsUrl": "wss://indexer.bigdevenergy.link/4cba550/v1/graphql"
"0xbc69e42348c9a992100970e8469247b58a517c2f7dd373741c6707cda35ccfc6": {
"httpUrl": "https://indexer.bigdevenergy.link/67b693c/v1/graphql",
"wsUrl": "wss://indexer.bigdevenergy.link/67b693c/v1/graphql"
},
"0x7d1da52a221897ebc88dc6a5d4623e704f7d64022d498b0438827dd79b6e5457": {
"httpUrl": "https://indexer.bigdevenergy.link/4991bb0/v1/graphql",
"wsUrl": "wss://indexer.bigdevenergy.link/4991bb0/v1/graphql"
"0x10860c51de3a37c47ebff2e08a810d9e2963ef161ee3a88274520938c85914e8": {
"httpUrl": "https://indexer.bigdevenergy.link/67b693c/v1/graphql",
"wsUrl": "wss://indexer.bigdevenergy.link/67b693c/v1/graphql"
}
},
"contracts": {
"orderbook": "0x8f7935292f3da69aec797926029c864d7ec6d03c72f7347b4fd517ba4a7b78fb",
"registry": "0xfc3439e66c15c0b8e8e02e0fe4951eecd6001639a6aa8a650885af62ea92540f",
"multiAsset": "0xdc527289bdef8ec452f350c9b2d36d464a9ebed88eb389615e512a78e26e3509"
},
"networkUrl": "https://testnet.fuel.network/v1/graphql",
Expand Down
2 changes: 2 additions & 0 deletions src/screens/SpotScreen/BottomTables/SpotTable/SpotTableVM.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class SpotTableVM {
this.subscriptionToOpenOrders = bcNetwork
.subscribeSpotOrders({
...this.tableFilters,
market: tradeStore.market!.contractAddress,
asset: tradeStore.market!.baseToken.assetId,
user: accountStore.address!,
status: ["Active"],
Expand Down Expand Up @@ -187,6 +188,7 @@ class SpotTableVM {
this.subscriptionToHistoryOrders = bcNetwork
.subscribeSpotOrders({
...this.tableFilters,
market: tradeStore.market!.contractAddress,
asset: tradeStore.market!.baseToken.assetId,
user: accountStore.address!,
status: ["Closed", "Canceled"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React, { PropsWithChildren, useMemo } from "react";
import { makeAutoObservable, reaction } from "mobx";
import { Nullable } from "tsdef";

import useVM from "@hooks/useVM";
import { RootStore, useStores } from "@stores";

import { FuelNetwork } from "@blockchain";
import { SpotMarketTrade } from "@entity";

import { Subscription } from "@src/typings/utils";

const ctx = React.createContext<SpotTradesVM | null>(null);

export const SpotTradesVMProvider: React.FC<PropsWithChildren> = ({ children }) => {
Expand All @@ -18,8 +21,9 @@ export const SpotTradesVMProvider: React.FC<PropsWithChildren> = ({ children })
export const useSpotTradesVM = () => useVM(ctx);

class SpotTradesVM {
public trades: SpotMarketTrade[] = [];
private subscriptionToTradeOrderEvents: Nullable<Subscription> = null;

trades: SpotMarketTrade[] = [];
isInitialLoadComplete = false;

constructor(private rootStore: RootStore) {
Expand All @@ -42,9 +46,14 @@ class SpotTradesVM {

const bcNetwork = FuelNetwork.getInstance();

bcNetwork
if (this.subscriptionToTradeOrderEvents) {
this.subscriptionToTradeOrderEvents.unsubscribe();
}

this.subscriptionToTradeOrderEvents = bcNetwork
.subscribeSpotTradeOrderEvents({
limit: 50,
market: market!.contractAddress,
})
.subscribe({
next: ({ data }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ class CreateOrderVM {

const params: GetOrdersParams = {
limit: 50,
market: market.contractAddress,
asset: market.baseToken.assetId ?? "",
status: ["Active"],
};
Expand All @@ -412,18 +413,14 @@ class CreateOrderVM {
? orderList[orderList.length - 1].price.toString()
: this.inputPrice.toString();

deposit = {
...deposit,
};

const order: FulfillOrderManyWithDepositParams = {
...deposit,
amount: this.inputAmount.toString(),
orderType: type,
limitType: settingsStore.timeInForce,
price,
orders: orderList.map((el) => el.id),
slippage: "10000",
...deposit,
};
const data = await bcNetwork.fulfillOrderManyWithDeposit(order, marketContracts);
return data.transactionId;
Expand Down
19 changes: 1 addition & 18 deletions src/stores/BalanceStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ export class BalanceStore {

if (!accountStore.address || !wallet) return;

const [balances] = await Promise.all([this.fetchBalances(), this.fetchUserMarketBalance()]);
await this.fetchUserMarketBalanceByContracts();
const [balances] = await Promise.all([this.fetchBalances(), this.fetchUserMarketBalanceByContracts()]);

try {
for (const [tokenAddress, balance] of Object.entries(balances)) {
Expand Down Expand Up @@ -307,22 +306,6 @@ export class BalanceStore {
return bcNetwork.getBalances();
};

private fetchUserMarketBalance = async () => {
const { accountStore } = this.rootStore;
const bcNetwork = FuelNetwork.getInstance();

if (!accountStore.address) return;

try {
// TODO: After type fix in sdk
const address = Address.fromB256(accountStore.address);
const balanceData = await bcNetwork.fetchSpotUserMarketBalance(address.bech32Address);
this.setMyMarketBalance(balanceData);
} catch (error) {
console.error(error);
}
};

private fetchUserMarketBalanceByContracts = async () => {
const { accountStore } = this.rootStore;
const bcNetwork = FuelNetwork.getInstance();
Expand Down
1 change: 1 addition & 0 deletions src/stores/SpotOrderBookStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class SpotOrderBookStore {

const params: Omit<GetActiveOrdersParams, "orderType"> = {
limit: 100,
market: market.contractAddress,
asset: market.baseToken.assetId,
};

Expand Down
1 change: 1 addition & 0 deletions src/stores/SwapStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class SwapStore {
const bcNetwork = FuelNetwork.getInstance();
const params: GetOrdersParams = {
limit: 50, // or more if needed
market: tradeStore.market!.contractAddress,
asset: baseToken?.assetId,
status: ["Active"],
};
Expand Down
18 changes: 11 additions & 7 deletions src/stores/TradeStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ class TradeStore {
}

get initialized() {
const isMarketInfoReady = !(
this.spotMarketInfo.high.isZero() ||
this.spotMarketInfo.low.isZero() ||
this.spotMarketInfo.volume.isZero()
);
return Boolean(this.spotMarkets.length && isMarketInfoReady);
// const isMarketInfoReady = !(
// this.spotMarketInfo.high.isZero() ||
// this.spotMarketInfo.low.isZero() ||
// this.spotMarketInfo.volume.isZero()
// );
// return Boolean(this.spotMarkets.length && isMarketInfoReady);
return true;
}

setMarketSymbol = (v: string) => (this.marketSymbol = v);
Expand Down Expand Up @@ -124,7 +125,10 @@ class TradeStore {

if (!this.market) return;

const info = await FuelNetwork.getInstance().fetchSpotVolume();
const info = await FuelNetwork.getInstance().fetchSpotVolume({
limit: 1000,
market: this.market.contractAddress,
});
const baseTokenAmount = BN.formatUnits(info.volume, this.market.baseToken.decimals);
const price = BN.formatUnits(oracleStore.getTokenIndexPrice(this.market.baseToken.priceFeed), DEFAULT_DECIMALS);
const volume = baseTokenAmount.multipliedBy(price);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Token } from "@entity";

import configJSON from "@src/config.json";

const CURRENT_CONFIG_VER = "1.2.0";
const CURRENT_CONFIG_VER = "1.3.0";

function createConfig() {
assert(configJSON.version === CURRENT_CONFIG_VER, "Version mismatch");
Expand Down

0 comments on commit 97c8a0a

Please sign in to comment.