Skip to content

Commit

Permalink
Adding support for BitShares Liquidity Pools (Poolmart) (#3378)
Browse files Browse the repository at this point in the history
feat: add liquidity pools
  • Loading branch information
AmmarYousefM authored Jun 20, 2022
1 parent b2ff2da commit 9e4d1d8
Show file tree
Hide file tree
Showing 41 changed files with 4,917 additions and 36 deletions.
9 changes: 9 additions & 0 deletions app/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ const QuickTrade = Loadable({
loading: LoadingIndicator
});

const PoolmartPage = Loadable({
loader: () =>
import(
/* webpackChunkName: "poolmart" */ "./components/Poolmart/PoolmartPage"
),
loading: LoadingIndicator
});

import LoginSelector from "./components/LoginSelector";
import Login from "./components/Login/Login";
import RegistrationSelector from "./components/Registration/RegistrationSelector";
Expand Down Expand Up @@ -638,6 +646,7 @@ class App extends React.Component {
path="/instant-trade/:marketID"
component={QuickTrade}
/>
<Route path="/pools" component={PoolmartPage} />
<Route path="*" component={Page404} />
</Switch>
</div>
Expand Down
1 change: 0 additions & 1 deletion app/actions/AccountActions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import alt from "alt-instance";
import accountUtils from "common/account_utils";
import AccountApi from "api/accountApi";

import WalletApi from "api/WalletApi";
import ApplicationApi from "api/ApplicationApi";
import WalletDb from "stores/WalletDb";
Expand Down
62 changes: 56 additions & 6 deletions app/actions/AssetActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,16 @@ class AssetActions {
);
let tr = WalletApi.new_transaction();
let precision = utils.get_asset_precision(createObject.precision);

big.config({DECIMAL_PLACES: createObject.precision});
let max_supply = new big(createObject.max_supply)
.times(precision)
.toString();
let max_market_fee = new big(createObject.max_market_fee || 0)
.times(precision)
.toString();

let corePrecision = utils.get_asset_precision(
ChainStore.getAsset(cer.base.asset_id).get("precision")
);

let operationJSON = {
fee: {
amount: 0,
Expand Down Expand Up @@ -309,11 +306,9 @@ class AssetActions {
is_prediction_market: is_prediction_market,
extensions: null
};

if (isBitAsset) {
operationJSON.bitasset_opts = bitasset_opts;
}

tr.add_type_operation("asset_create", operationJSON);
return dispatch => {
return WalletDb.process_transaction(tr, null, true)
Expand Down Expand Up @@ -590,9 +585,64 @@ class AssetActions {
};
}

getAssetsByIssuer(issuer, count, start, includeGateways = false){
let id = issuer + "_" + count;
console.log("getAssetsByIssuer id = ", id);
return dispatch => {
if (!inProgress[id]) {
let assets;
inProgress[id] = true;
dispatch({loading: true});

assets = Apis.instance()
.db_api()
.exec("get_assets_by_issuer", [issuer, start, count])
.then(assets => {
let bitAssetIDS = [];
let dynamicIDS = [];

assets.forEach(asset => {
ChainStore._updateObject(asset, false);
dynamicIDS.push(asset.dynamic_asset_data_id);
});
let dynamicPromise = Apis.instance()
.db_api()
.exec("get_objects", [dynamicIDS]);
Promise.all([dynamicPromise]).then(
results => {
delete inProgress[id];
dispatch({
assets: assets,
dynamic: results[0],
loading: false
});
return assets && assets.length;
}
);
})
.catch(error => {
console.log(
"Error in AssetActions.getAssetList: ",
error
);
dispatch({loading: false});
delete inProgress[id];
});

// Fetch next 10 assets for each gateAsset on request
if (includeGateways) {
gatewayPrefixes.forEach(a => {
this.getAssetList(a + "." + start, 10);
});
}

return assets;
}
};
}

lookupAsset(symbol, searchID) {
let asset = ChainStore.getAsset(symbol);

if (asset) {
return {
assets: [asset],
Expand Down
114 changes: 114 additions & 0 deletions app/actions/PoolActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import alt from "alt-instance";
import {Apis} from "bitsharesjs-ws";
import utils from "common/utils";
import WalletApi from "api/WalletApi";
import WalletDb from "stores/WalletDb";
import {ChainStore} from "bitsharesjs";
import big from "bignumber.js";
import {gatewayPrefixes} from "common/gateways";
import {price} from "bitsharesjs/es/serializer/src/operations";
let inProgress = {};

class PoolActions {
createPool(
account_id,
createObject,
flags,
permissions,
cer,
isBitAsset,
is_prediction_market,
bitasset_opts,
description
) {
// Create pool action here...
console.log(
"create pool:",
createObject,
"flags:",
flags,
"isBitAsset:",
isBitAsset,
"bitasset_opts:",
bitasset_opts
);
let tr = WalletApi.new_transaction();
let precision = utils.get_asset_precision(createObject.precision);
big.config({DECIMAL_PLACES: createObject.precision});
let max_supply = new big(createObject.max_supply)
.times(precision)
.toString();
let max_market_fee = new big(createObject.max_market_fee || 0)
.times(precision)
.toString();
let corePrecision = utils.get_asset_precision(
ChainStore.getAsset(cer.base.asset_id).get("precision")
);
let operationJSON = {
fee: {
amount: 0,
asset_id: 0
},
issuer: account_id,
symbol: createObject.symbol,
precision: parseInt(createObject.precision, 10),
common_options: {
max_supply: max_supply,
market_fee_percent: createObject.market_fee_percent * 100 || 0,
max_market_fee: max_market_fee,
issuer_permissions: permissions,
flags: flags,
core_exchange_rate: {
base: {
amount: cer.base.amount * corePrecision,
asset_id: cer.base.asset_id
},
quote: {
amount: cer.quote.amount * precision,
asset_id: "1.3.1"
}
},
whitelist_authorities: [],
blacklist_authorities: [],
whitelist_markets: [],
blacklist_markets: [],
description: description,
extensions: {
reward_percent: createObject.reward_percent * 100 || 0,
whitelist_market_fee_sharing: []
}
},
is_prediction_market: is_prediction_market,
extensions: null
};
if (isBitAsset) {
operationJSON.bitasset_opts = bitasset_opts;
}
tr.add_type_operation("asset_create", operationJSON);
return dispatch => {
return WalletDb.process_transaction(tr, null, true)
.then(result => {
// console.log("pool create result:", result);
dispatch(true);
})
.catch(error => {
console.log("----- createAsset error ----->", error);
dispatch(false);
});
};
}

create_liquidity_pool(
my_username,
asset_a,
asset_b,
share_asset,
taker_fee_percent,
withdrawal_fee_percent
){


}
}

export default alt.createActions(PoolActions);
Loading

0 comments on commit 9e4d1d8

Please sign in to comment.