Commit aaf246e1 authored by Allan Juma's avatar Allan Juma

update

parent 33f5c0c5
......@@ -173,7 +173,10 @@ when(
}
var accountInfo = await Algorand.getAccount(store.settings.chains.algo.chain, store.settings.chains.algo.account.address);
console.log('algo account! '+accountInfo);
//var poolStats = await grpc.initPyface(['/data/lightning-bits/src/chains/algo/pools.py', 'bootstrap', 70232824, 0, '289:BITS', 'ALGO', 'TTNTINGI6AKN6JBHCAOXVFZN72BAMDNBTHZ3ZRQC3ILAMWONKN7XRRQ6GM' ]);
......
......@@ -143,8 +143,8 @@ class PoolAddAction {
//check if contract has enough balance first
console.log(parseFloat(this._store.settings.chains.algo.account.balance)*100, (amount*1.01));
if(parseFloat(this._store.settings.chains.algo.account.balance)*100 > (amount*1.01)){
console.log(parseFloat(this._store.settings.chains.algo.account.balance)*1000000, (amount*1.01));
if(parseFloat(this._store.settings.chains.algo.account.balance)*1000000 > (amount*1.01)){
console.log('INFO! contract has sufficient balance');
}else{
......@@ -190,6 +190,7 @@ class PoolAddAction {
var amount = toSatoshis(this._store.payment.amount, settings);
if(parseFloat(this._store.settings.chains.algo.account.balance)*1000000 > (amount*1.01)){
console.log('INFO! sufficient BTC in contract. skipping lightning swap...');
this._store.payment.address = '';
} else if (!this._store.payment.address) {
return this._notification.display({ msg: 'Enter an invoice or address' });
}
......
......@@ -18,25 +18,25 @@ const Algorand = {
getClient: network => {
let token = {
"X-Algo-API-Token": store.chains.algo.rpc[network].key
"X-Algo-API-Token": store.settings.chains.algo.rpc[store.settings.chains.algo.chain].key
};
if (store.chains.algo.rpc[network].server.search("purestake") >= 0) {
if (store.settings.chains.algo.rpc[store.settings.chains.algo.chain].server.search("purestake") >= 0) {
token = {
"X-API-Key": store.chains.algo.rpc[network].key
"X-API-Key": store.settings.chains.algo.rpc[store.settings.chains.algo.chain].key
};
}
return new algosdk.Algod(
token,
store.chains.algo.rpc[network].server,
store.chains.algo.rpc[network].port
store.settings.chains.algo.rpc[store.settings.chains.algo.chain].server,
store.settings.chains.algo.rpc[store.settings.chains.algo.chain].port
);
},
getClientForTx: network => {
let token = {
"X-API-Key": store.chains.algo.rpc[network].key,
"X-API-Key": store.settings.chains.algo.rpc[network].key,
"Content-Type": "application/x-binary"
};
......
......@@ -67,12 +67,29 @@ def swap(client,action,aID1,aID2,account,mne,amount):
txid = client.algod.send_transactions(transaction_group.signed_transactions)
wait_for_confirmation(txid)
# Fetch our two assets of interest
ASA = Asset(id=aID1, name='ASA', unit_name='ASA', decimals=0)
BTC = Asset(id=aID2, name='BTC satoshis', unit_name='BTC', decimals=6)
ASA = client.fetch_asset(aID1)
BTC = client.fetch_asset(aID2)
# Create the pool we will work with and fetch its on-chain state
pool = Pool(client, asset_a=ASA, asset_b=BTC, fetch=True)
#pool = Pool(client, asset_a=ASA, asset_b=BTC, fetch=True)
pool = client.fetch_pool(ASA, BTC)
r = pool.info()
if(not client.asset_is_opted_in(aID1)):
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) and aID2 > 0):
print('Account not opted into asset {aID2}, opting in now..')
transaction_group = client.prepare_asset_optin_transactions(aID2, 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)
#amount = 10_000_000
# Get a quote for a swap of 1 ALGO to TINYUSDC with 1% slippage tolerance
......@@ -231,25 +248,6 @@ if action == "pooling":
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
ASA = client.fetch_asset(aID1)
BTC = client.fetch_asset(aID2)
......
......@@ -36,7 +36,7 @@ ChartJS.register(ArcElement, Tooltip, Legend);
const { settings } = store;
var amount = toSatoshis(store.payment.amount, settings);
if(parseFloat(store.settings.chains.algo.account.balance)*100 > (amount*1.01)){
if(parseFloat(store.settings.chains.algo.account.balance)*1000000 > (amount*1.01)){
console.log('INFO! sufficient BTC in contract. skipping lightning swap...');
var poolStats = await grpc.initPyface(['/data/lightning-bits/src/chains/algo/pools.py', 'swap', store.selectedPool.assetID , 0, amount, store.settings.chains.algo.account.address, store.settings.chains.algo.account.mnemonic, 'add' ]);
......
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