Commit 86d3a150 authored by allan juma's avatar allan juma

update

parent aaf246e1
......@@ -66,10 +66,13 @@ class PoolRemoveLiqAction {
*/
async confirmRem() {
var amount = this._store.invoice.amount/this._store.selectedPool.quote;
var poolStats = await this._grpc.initPyface(['/data/lightning-bits/src/chains/algo/pools.py', 'swap', this._store.selectedPool.assetID , 0, parseInt(amount), this._store.settings.chains.algo.account.address, this._store.settings.chains.algo.account.mnemonic, 'remove' ]);
console.log(poolStats);
var amount = this._store.invoice.amount/this._store.selectedPool.quote *1000000;
var res = await this._grpc.initPyface(['/data/lightning-bits/src/chains/algo/pools.py', 'swap', this._store.selectedPool.assetID , 0, parseInt(amount), this._store.settings.chains.algo.account.address, this._store.settings.chains.algo.account.mnemonic, 'remove' ]);
console.log(res);
this._nav.goPayPoolDone();
return res;
}
async generateUri() {
......
......@@ -61,19 +61,20 @@ class PoolAction {
var grpc = hii._grpc;
var store = hii._store;
console.log(pool);
var pDat = await addAsaQuote(grpc,store,pool.poolID.id, 0);
var ret = {
id: pool.id,
cat: 'micro',
type: 'algorand',
icon: pool.bannerPath,
//quote: await addAsaQuote(grpc,store,75685483, 0),
quote: await addAsaQuote(grpc,store,pool.poolID.id, 0),
quote: pDat.q,
assetID: pool.poolID.id,
banner: pool.bannerPath,
url: 'https://demo1.bitsoko.org',
title: pool.name,
desc: pool.description,
amount: 0,
amount: pDat.b,
fee: 0,
confirmations: 5,
status: pool.active ? 'open' : 'closed',
......@@ -91,9 +92,9 @@ var ret = {
async getPools() {
try {
const uri = 'https://dooca.bitsoko.org/getEnterprise/?servEntID=1';
//const uri = 'https://dooca.bitsoko.org/getEnterprise/?servEntID=1';
//const uri = 'https://gateway.bitsoko.org/getEnterpriseRoute';
const uri = 'http://10.0.255.253:1814/getEnterprise/?servEntID=1';
const response = checkHttpStatus(await fetch(uri));
const svs = await response.json();
var pools = svs.services;
......
......@@ -17,46 +17,6 @@ import re
def add_liquidity(account, amount, aID1, aID2):
client = TinymanTestnetClient(user_address=account['address'])
# By default all subsequent operations are on behalf of user_address
# Fetch our two assets of interest
ASA = client.fetch_asset(aID1)
BTC = client.fetch_asset(aID2)
# Fetch the pool we will work with
pool = client.fetch_pool(ASA, BTC)
# Get a quote for supplying 1000.0 TinyUSDC
quote = pool.fetch_mint_quote(ASA(1_000_000), BTC(1_000_000), slippage=0.01)
print(quote)
# Check if we are happy with the quote..
if quote.amounts_in[BTC] < 5_000_000:
# Prepare the mint transactions from the quote and sign them
transaction_group = pool.prepare_mint_transactions_from_quote(quote)
transaction_group.sign_with_private_key(account['address'], account['private_key'])
result = client.submit(transaction_group, wait=True)
# Check if any excess liquidity asset remaining after the mint
excess = pool.fetch_excess_amounts()
if pool.liquidity_asset in excess:
amount = excess[pool.liquidity_asset]
print(f'Excess: {amount}')
if amount > 1_000_000:
transaction_group = pool.prepare_redeem_transactions(amount)
transaction_group.sign_with_private_key(account['address'], account['private_key'])
result = client.submit(transaction_group, wait=True)
info = pool.fetch_pool_position()
share = info['share'] * 100
print(f'Pool Tokens: {info[pool.liquidity_asset]}')
print(f'Assets: {info[TINYUSDC]}, {info[ALGO]}')
print(f'Share of pool: {share:.3f}%')
def swap(client,action,aID1,aID2,account,mne,amount):
if(not client.is_opted_in(account['address'])):
print('Account not opted into app, opting in now..')
......@@ -142,23 +102,70 @@ def swap(client,action,aID1,aID2,account,mne,amount):
action = sys.argv[1]
#
if action == "bootstrap":
pooler_address = sys.argv[6]
aID1 = sys.argv[2]
aID2 = sys.argv[3]
aName1 = sys.argv[4]
aName2 = sys.argv[5]
Pool.__init__(AlgodTestnetClient, '', aID1, aID2, pooler_address)
print(Pool.prep_bootstrap_transactions(AlgodTestnetClient, '', pooler_address, aID1, aID2, aName1, aName2))
if action == "poolState":
if action == "bootstrap":
pooler_address = sys.argv[4]
aID1 = int(sys.argv[2])
aID2 = int(sys.argv[3])
#Pool.fetch_state(AlgodTestnetClient, pooler_address)
#Pool.__init__(AlgodTestnetClient, '', aID1, aID2, pooler_address)
print(get_pool_info(AlgodTestnetClient, Pool.fetch_state(AlgodTestnetClient, pooler_address), aID1, aID2 ))
#Pool.fetch_pool_position(AlgodTestnetClient, pooler_address)
aID2 = int(sys.argv[3])
mne = sys.argv[5]
priv_key = mnemonic.to_private_key(mne)
account = {
'address': pooler_address,
'private_key': priv_key,
}
client = TinymanTestnetClient(user_address=account['address'])
if(not client.is_opted_in(account['address'])):
print('Account not opted into app, opting in now..')
transaction_group = client.prepare_app_optin_transactions(account['address'])
for i, txn in enumerate(transaction_group.transactions):
if txn.sender == account['address']:
transaction_group.signed_transactions[i] = txn.sign(account['private_key'])
txid = client.algod.send_transactions(transaction_group.signed_transactions)
#wait_for_confirmation(txid)
if(not client.asset_is_opted_in(aID1, account['address'])):
print('Account not opted into asset {aID1}, opting in now..')
transaction_group = client.prepare_asset_optin_transactions(aID1, account['address'])
for i, txn in enumerate(transaction_group.transactions):
if txn.sender == account['address']:
transaction_group.signed_transactions[i] = txn.sign(account['private_key'])
txid = client.algod.send_transactions(transaction_group.signed_transactions)
#wait_for_confirmation(txid)
'''
if(not client.asset_is_opted_in(aID2)):
print('Account not opted into asset {aID2}, opting in now..')
transaction_group = client.prepare_asset_optin_transactions(aID1, account['address'])
for i, txn in enumerate(transaction_group.transactions):
if txn.sender == account['address']:
transaction_group.signed_transactions[i] = txn.sign(account['private_key'])
txid = client.algod.send_transactions(transaction_group.signed_transactions)
#wait_for_confirmation(txid)
'''
# Fetch our two assets of interest
TINYUSDC = client.fetch_asset(aID1)
ALGO = client.fetch_asset(aID2)
# Fetch the pool we will work with
pool = client.fetch_pool(TINYUSDC, ALGO)
transaction_group = pool.prepare_bootstrap_transactions(pooler_address=account['address'])
transaction_group.sign_with_private_key(account['address'], account['private_key'])
result = client.submit(transaction_group, wait=True)
pool = client.fetch_pool(TINYUSDC, ALGO)
pool.refresh()
r = pool.info()
'''
if(not client.asset_is_opted_in(r['liquidity_asset_id'], account['address'])):
print(f"Account not opted into asset {r['liquidity_asset_id']}, opting in now..")
transaction_group = client.prepare_asset_optin_transactions(r['liquidity_asset_id'], account['address'])
transaction_group.sign_with_private_key(account['address'], account['private_key'])
client.submit(transaction_group, wait=True)
#wait_for_confirmation(txid)
'''
print(r)
if action == "accState":
pooler_address = sys.argv[2]
Pool.prep_acc_state(AlgodTestnetClient, pooler_address)
......@@ -180,27 +187,6 @@ if action == "swap":
swap(client,action,aID1,aID2,account,mne,amount)
if action == "quote":
......@@ -210,21 +196,35 @@ if action == "quote":
aID1 = int(sys.argv[2])
aID2 = int(sys.argv[3])
pooler_address = sys.argv[4]
# Fetch our two assets of interest
ASA = client.fetch_asset(aID1)
BTC = client.fetch_asset(aID2)
print(ASA,BTC,aID1,aID2)
# Fetch the pool we will work with
pool = client.fetch_pool(ASA, BTC)
r = pool.info()
# Get a quote for a swap of 1 ASA with 1% slippage tolerance
quote = pool.fetch_fixed_input_swap_quote(ASA(1), slippage=0.01)
quote = pool.fetch_fixed_input_swap_quote(ASA(1000000), slippage=0.01)
reg = re.search("('([^/,]*)')",str(quote.amount_out))
result = reg.group(1)
#print(r)
print(result)
account_info = client.algod.account_info(pooler_address)
amount = 0
assets = {a['asset-id']: a for a in account_info['assets']}
print(assets[aID1]['amount'])
#for i, ast in enumerate(assets):
#print(ast)
#if int(ast) == aID1:
#amount = ast['amount']
#print(amount)
if action == "pooling":
pooler_address = sys.argv[4]
mne = sys.argv[5]
......@@ -265,42 +265,4 @@ if action == "pooling":
#print(f'Pool Tokens: {info[pool.liquidity_asset]}')
#print(f'Assets: {info[ASA]}, {info[BTC]}')
#print(f'Share of pool: {share:.3f}%')
if action == "addLiq":
#aID1 = int(sys.argv[2])
aID1 = int(sys.argv[2])
aID2 = int(sys.argv[3])
pooler_address = sys.argv[4]
mne = sys.argv[5]
amount = int(sys.argv[6])
priv_key = mnemonic.to_private_key(mne)
account = {
'address': pooler_address,
'private_key': priv_key,
}
client = TinymanTestnetClient(user_address=account['address'])
# Fetch our two assets of interest
TINYUSDC = client.fetch_asset(aID1)
ALGO = client.fetch_asset(aID2)
# Fetch the pool we will work with
pool = client.fetch_pool(TINYUSDC, ALGO)
#quote = pool.fetch_fixed_input_swap_quote(ALGO(1_000_000), slippage=0.01)
#transaction_group = pool.prepare_redeem_transactions(amount)
# Check if the account is opted into Tinyman and optin if necessary
if(not client.is_opted_in()):
print('Account not opted into app, opting in now..')
transaction_group = client.prepare_app_optin_transactions()
transaction_group.sign_with_private_key(account['address'], account['private_key'])
result = client.submit(transaction_group, wait=True)
# Get a quote for a swap of 1 ALGO to TINYUSDC with 1% slippage tolerance
#transaction_group = pool.prepare_bootstrap_transactions()
#transaction_group.sign_with_private_key(account['address'], account['private_key'])
#result = client.submit(transaction_group, wait=True)
#print(result)
add_liquidity(account, amount, aID1, aID2)
......@@ -13,9 +13,12 @@ const ComputedPool = store => {
const t = pools ? pools.slice() : [];
//const p = payments ? payments.slice() : [];
//const i = invoices ? invoices.slice() : [];
store.poolBalance = 0;
const all = [].concat(t);
all.sort((a, b) => b.date.getTime() - a.date.getTime());
//all.sort((a, b) => b.date.getTime() - a.date.getTime());
all.sort((a, b) => b.amount - a.amount);
all.forEach((t, i) => {
store.poolBalance = store.poolBalance + (parseInt(t.quote*t.amount));
t.key = String(i);
//t.idName = t.type === 'algorand' ? '209:BITS:dooca-net' : 'Ethereum';
t.idName = t.id+':BITS:MSM-1:POOL | '+t.title;
......@@ -26,8 +29,8 @@ const ComputedPool = store => {
//t.quote = addQuote(t.aID, 0);
t.dateLabel = t.date.toLocaleDateString();
t.dateTimeLabel = t.date.toLocaleString();
t.amountLabel = JSON.stringify(t.quote);
t.share = toAmountLabel(t.amount, settings);
t.amountLabel = toAmountLabel(parseInt(parseFloat(t.quote)*Math.pow(10,6)), settings);
t.share = t.amount/Math.pow(10,6);
t.raised = toAmountLabel(0, settings);
if (Number.isInteger(t.confirmations)) {
t.confirmationsLabel = t.confirmations.toString();
......@@ -55,6 +58,10 @@ const ComputedPool = store => {
.map(c => c.localBalance + c.commitFee)
.reduce((a, b) => a + b, 0);
},
get poolBalanceLabel() {
const { poolBalance, settings } = store;
return toAmountLabel(poolBalance, settings);
},
get poolBalanceOpenLabel() {
const { channelBalanceOpenSatoshis, settings } = store;
return toAmountLabel(channelBalanceOpenSatoshis, settings);
......
......@@ -144,15 +144,39 @@ export const toAmountLabel = (satoshis, settings) => {
export const addAsaQuote = async (grpc, store, aID1, aID2) => {
var quote = await grpc.initPyface(['/data/lightning-bits/src/chains/algo/pools.py', 'quote', aID1, aID2 ]);
// var quote = await grpc.initPyface(['/data/lightning-bits/src/chains/algo/pools.py', 'addLiq', aID1, aID2 , store.settings.chains.algo.account.address, store.settings.chains.algo.account.mnemonic, 1]);
//var poolStats = await grpc.initPyface(['/data/lightning-bits/src/chains/algo/pools.py', 'bootstrap', aID1, aID2, store.settings.chains.algo.account.address, store.settings.chains.algo.account.mnemonic ]);
//poolStats = poolStats.replace(/'/g, '"').replace(/"{/g, "{").slice(0, -3);
//console.log(poolStats);
// var quote = await grpc.initPyface(['/data/lightning-bits/src/chains/algo/pools.py', 'swap', aID1, aID2, 10, store.settings.chains.algo.account.address, store.settings.chains.algo.account.mnemonic, 'remove' ]);
var quote = await grpc.initPyface(['/data/lightning-bits/src/chains/algo/pools.py', 'quote', aID1, aID2, store.settings.chains.algo.account.address ]);
console.log(quote);
try{
var q = quote.split("'")[1].split("'")[0];
var amt = parseInt(parseFloat(q)*1000000);
//console.log(amt);
if(!Number.isInteger(amt)) amt = 0;
var ql = toAmount(amt,store.settings);
return ql;
}catch(er){console.error(er)}
var q = parseFloat(quote.split("'")[1].split("'")[0]);
var b = parseInt(quote.split("'")[2].replace(/\D/g,''));
if(b >= 0){
//balance is int ok
}else{
b=0;
}
console.log(q,b);
var amt = parseInt(q);
if(Number.isInteger(amt)){
//var ql = toAmount(amt,store.settings);
return {q:q, b:b};
}else if(!Number.isInteger(amt)){
var ql = toAmount(0,store.settings);
return {q:ql, b:b};
}
}catch(er){
console.error(er);
}
}
/**
......
......@@ -210,7 +210,7 @@ var poolStats = await grpc.initPyface(['/data/lightning-bits/src/chains/algo/poo
// doSwap(store.settings.chains.algo.account.mnemonic);
var poolStats = await grpc.initPyface(['/data/lightning-bits/src/chains/algo/pools.py', 'pooling', 75685483 , 0, store.settings.chains.algo.account.address, store.settings.chains.algo.account.mnemonic ]);
var poolStats = await grpc.initPyface(['/data/lightning-bits/src/chains/algo/pools.py', 'pooling', store.selectedPool.assetID , 0, store.settings.chains.algo.account.address, store.settings.chains.algo.account.mnemonic ]);
console.log(poolStats);
}
......@@ -237,7 +237,7 @@ const PoolDetailView = ({ store, grpc, nav, pooladdliq, poolremoveliq}) => (
{store.selectedPool.desc}
</DetailField>
<DetailField name="Performance">
VALUATION: {store.selectedPool.quote*1000} | PRICE: {store.selectedPool.quote} | ROI: 0%
VALUATION: {parseInt(store.selectedPool.quote*1000*Math.pow(10,6))+store.settings.fiat} | PRICE: {parseInt(store.selectedPool.quote*Math.pow(10,6))+store.settings.fiat} | SHARE: {parseInt(store.selectedPool.amount*store.selectedPool.quote)+store.settings.fiat}
</DetailField>
{store.selectedPool.memo ? (
<DetailField name="Note">
......@@ -248,7 +248,7 @@ const PoolDetailView = ({ store, grpc, nav, pooladdliq, poolremoveliq}) => (
CAP: 0{store.unitLabel} | FUNDED: 0% | INVESTORS: 1 | ID: {store.selectedPool.id}:BITS:dooca.net
</DetailField>
<DetailField name="Asset Supply">
TOTAL: 1,000 | CIRCULATING: 0 | ID: 234569876
TOTAL: 1,000 | OWNED: {store.selectedPool.amount/Math.pow(10,6)} | CIRCULATING: 30% | ID: {store.selectedPool.assetID}
</DetailField>
{store.selectedPool.confirmationsLabel ? (
<DetailField name="Contract">
......
......@@ -97,6 +97,7 @@ const PoolSummary = ({
);
const PoolBalances = ({
poolBalanceLabel,
balanceLabel,
unitLabel,
}) => (
......@@ -107,7 +108,7 @@ const PoolBalances = ({
</View>
<Text style={summaryStyles.txt}>Balance</Text>
<Text style={[summaryStyles.txt, summaryStyles.total]}>
0.00 {unitLabel}
{poolBalanceLabel}
</Text>
</View>
</View>
......@@ -120,6 +121,7 @@ PoolSummary.propTypes = {
};
PoolBalances.propTypes = {
poolBalanceLabel: PropTypes.string.isRequired,
balanceLabel: PropTypes.string.isRequired,
unitLabel: PropTypes.string,
};
......@@ -172,6 +174,7 @@ const poolStyles = StyleSheet.create({
});
const PoolView = ({ store, nav, pool, grpc, goPoolAdd }) => {
const { computedPools: pools,
poolBalanceLabel,
poolBalanceOpenLabel,
poolBalanceClosingLabel,
balanceLabel,
......@@ -191,6 +194,7 @@ const PoolView = ({ store, nav, pool, grpc, goPoolAdd }) => {
/>
<PoolBalances style={poolStyles.btnWrapper}
poolBalanceLabel={poolBalanceLabel}
balanceLabel={balanceLabel}
unitLabel={unitLabel}
/>
......@@ -338,8 +342,8 @@ const hStyles = StyleSheet.create({
const PoolListHeader = () => (
<ListHeader style={[iStyles.item, hStyles.header]}>
<View style={iStyles.i} />
<Text style={[iStyles.m, hStyles.txt]}>CONTRACT</Text>
<Text style={[iStyles.m, hStyles.txt]}>STATUS</Text>
<Text style={[iStyles.m, hStyles.txt]}>CAP</Text>
<Text style={[iStyles.l, hStyles.txt]}>MERCHANT</Text>
<Text style={[iStyles.l, hStyles.txt]}>SHARE</Text>
<Text style={[iStyles.m, hStyles.txt]}>PRICE</Text>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment