Browse Source

Test

etomic
jl777 8 years ago
parent
commit
ef795f18a0
  1. 4
      basilisk/basilisk.h
  2. 147
      basilisk/jumblr.c
  3. 336
      basilisk/smartaddress.c
  4. 9
      iguana/main.c
  5. 2
      includes/iguana_funcs.h
  6. 4
      includes/iguana_structs.h

4
basilisk/basilisk.h

@ -42,6 +42,10 @@
#define INSTANTDEX_BTC "1KRhTPvoxyJmVALwHFXZdeeWFbcJSbkFPu"
#define INSTANTDEX_BTCD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf"
#define JUMBLR_INCR 99.65
#define JUMBLR_FEE 0.001
#define JUMBLR_TXFEE 0.01
struct basilisk_swap;
struct basilisk_rawtxinfo

147
basilisk/jumblr.c

@ -27,11 +27,8 @@
z_sendmany "fromaddress" [{"address":... ,"amount":..., "memo":"<hex>"},...] ( minconf ) ( fee )
*/
#define JUMBLR_INCR 99.65
#define JUMBLR_TXFEE 0.01
#define JUMBLR_ADDR "RGhxXpXSSBTBm9EvNsXnTQczthMCxHX91t"
#define JUMBLR_BTCADDR "18RmTJe9qMech8siuhYfMtHo8RtcN1obC6"
#define JUMBLR_FEE 0.001
int32_t jumblr_addresstype(struct supernet_info *myinfo,struct iguana_info *coin,char *addr)
{
@ -642,150 +639,6 @@ void jumblr_utxoupdate(struct supernet_info *myinfo,char *dest,struct iguana_inf
}
}
void jumblr_DEXupdate(struct supernet_info *myinfo,struct iguana_info *coin,char *symbol,char *CMCname,double BTC2KMD,double KMDavail)
{
double avebid,aveask,highbid,lowask,CMC_average,changes[3],estfee,estbtcfee; struct iguana_info *kmdcoin; struct DEXcoin_info *ptr = &coin->DEXinfo;
// wait for one confirmation to clear most in mempool (ha, ha)
// deal with changing addresses, ie all pendings?
estfee = 0.0001;
estbtcfee = 0.0015;
if ( coin != 0 && (kmdcoin= iguana_coinfind("KMD")) != 0 && time(NULL) > ptr->lasttime+60 )
{
ptr->coin = coin;
if ( strcmp(symbol,ptr->symbol) != 0 )
{
safecopy(ptr->symbol,symbol,sizeof(ptr->symbol));
safecopy(ptr->CMCname,CMCname,sizeof(ptr->CMCname));
}
//if ( ptr->depositaddr[0] == 0 )
{
if ( strcmp("KMD",symbol) == 0 )
ptr->deposit_privkey = jumblr_privkey(myinfo,ptr->depositaddr,0,ptr->KMDdepositaddr,JUMBLR_DEPOSITPREFIX);
else ptr->deposit_privkey = jumblr_privkey(myinfo,ptr->depositaddr,ptr->coin->chain->pubtype,ptr->KMDdepositaddr,JUMBLR_DEPOSITPREFIX);
}
//if ( ptr->jumblraddr[0] == 0 )
{
if ( strcmp("KMD",symbol) == 0 )
ptr->jumblr_privkey = jumblr_privkey(myinfo,ptr->jumblraddr,0,ptr->KMDjumblraddr,"");
else ptr->jumblr_privkey = jumblr_privkey(myinfo,ptr->jumblraddr,ptr->coin->chain->pubtype,ptr->KMDjumblraddr,"");
}
ptr->avail = dstr(jumblr_balance(myinfo,ptr->coin,ptr->depositaddr));
ptr->btcprice = get_theoretical(&avebid,&aveask,&highbid,&lowask,&CMC_average,changes,CMCname,symbol,"BTC",&ptr->USD_average);
KMDavail = dstr(jumblr_balance(myinfo,ptr->coin,ptr->KMDjumblraddr));
if ( strcmp("KMD",symbol) == 0 )
{
ptr->BTC2KMD = ptr->btcprice;
ptr->kmdprice = 1.;
ptr->KMDavail = KMDavail;
}
else if ( (ptr->BTC2KMD= BTC2KMD) > SMALLVAL )
{
ptr->kmdprice = ptr->btcprice / BTC2KMD;
ptr->KMDavail = KMDavail;
}
ptr->lasttime = (uint32_t)time(NULL);
printf("%s avail %.8f KMDavail %.8f btcprice %.8f deposit.(%s %s) -> jumblr.(%s %s)\n",symbol,ptr->avail,KMDavail,ptr->btcprice,ptr->depositaddr,ptr->KMDdepositaddr,ptr->jumblraddr,ptr->KMDjumblraddr);
} // else printf("skip\n");
}
void jumblr_CMCname(char *CMCname,char *symbol)
{
if ( strcmp(symbol,"KMD") == 0 )
strcpy(CMCname,"komodo");
}
void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coin,int32_t toKMD)
{
double vol,avail; int32_t enabled = 0; struct iguana_info *kmdcoin,*coinbtc = 0;
//printf("jumblr_DEXcheck numswaps.%d notary.%d IAMLP.%d %p %p %f\n",myinfo->numswaps,myinfo->IAMNOTARY,myinfo->IAMLP,kmdcoin,coinbtc,kmdcoin->DEXinfo.btcprice);
if ( myinfo->IAMNOTARY != 0 || myinfo->IAMLP != 0 || myinfo->secret[0] == 0 )
return;
kmdcoin = iguana_coinfind("KMD");
coinbtc = iguana_coinfind("BTC");
if ( kmdcoin == 0 || coinbtc == 0 )
return;
jumblr_DEXupdate(myinfo,kmdcoin,"KMD","komodo",0.,0.);
if ( strcmp(coin->symbol,"KMD") != 0 && strcmp(coin->symbol,"BTC") != 0 && kmdcoin->DEXinfo.btcprice > 0. )
{
if ( coin->CMCname[0] == 0 )
jumblr_CMCname(coin->CMCname,coin->symbol);
if ( coin->CMCname[0] != 0 )
jumblr_DEXupdate(myinfo,coin,coin->symbol,coin->CMCname,kmdcoin->DEXinfo.btcprice,kmdcoin->DEXinfo.avail);
}
if ( myinfo->numswaps == 0 || (kmdcoin->FULLNODE < 0 && coinbtc->FULLNODE < 0) )
enabled = 1;
if ( enabled != 0 && myinfo->IAMLP == 0 && kmdcoin->DEXinfo.btcprice > SMALLVAL )
{
double minbtc,minkmd,btcavail; char *retstr; cJSON *vals; bits256 hash;
minbtc = (kmdcoin->DEXinfo.btcprice * 1.2) * (JUMBLR_INCR + 3*(JUMBLR_INCR * JUMBLR_FEE + JUMBLR_TXFEE));
btcavail = dstr(jumblr_balance(myinfo,coinbtc,kmdcoin->DEXinfo.depositaddr));
avail = (btcavail - coinbtc->DEXinfo.DEXpending);
printf("BTC.%d deposits %.8f, min %.8f avail %.8f pending %.8f\n",toKMD,btcavail,minbtc,avail,coinbtc->DEXinfo.DEXpending);
if ( toKMD == 0 && coinbtc != 0 && btcavail > (minbtc + coinbtc->DEXinfo.DEXpending) )
{
/*if ( avail >= (100. * minbtc) )
vol = (100. * minbtc);
else if ( avail >= (10. * minbtc) )
vol = (10. * minbtc);
else*/
if ( avail >= minbtc )
vol = minbtc;
else vol = 0.;
if ( vol > 0. )
{
vals = cJSON_CreateObject();
jaddstr(vals,"source","BTC");
jaddstr(vals,"dest","KMD");
jaddnum(vals,"amount",vol);
jaddnum(vals,"minprice",0.985/kmdcoin->DEXinfo.btcprice);
jaddnum(vals,"usejumblr",1);
jaddnum(vals,"DEXselector",1);
memset(hash.bytes,0,sizeof(hash));
coinbtc->DEXinfo.DEXpending += vol;
if ( (retstr= InstantDEX_request(myinfo,coinbtc,0,0,hash,vals,"")) != 0 )
{
printf("request.(%s) -> (%s)\n",jprint(vals,0),retstr);
free(retstr);
}
free_json(vals);
// curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"request\",\"vals\":{\"source\":\"KMD\",\"amount\":20,\"dest\":\"USD\",\"minprice\":0.08}}"
}
} //else printf("btcavail %.8f pending %.8f\n",btcavail,pending);
minkmd = 100.;
avail = (kmdcoin->DEXinfo.KMDavail - kmdcoin->DEXinfo.DEXpending);
printf("KMD.%d deposits %.8f, min %.8f, avail %.8f pending %.8f\n",toKMD,kmdcoin->DEXinfo.KMDavail,minkmd,avail,kmdcoin->DEXinfo.DEXpending);
if ( toKMD != 0 && coinbtc != 0 && kmdcoin->DEXinfo.KMDavail > (minkmd + kmdcoin->DEXinfo.DEXpending) )
{
/*if ( avail > 100.*JUMBLR_INCR )
vol = 100.*JUMBLR_INCR;
else if ( avail > 10.*JUMBLR_INCR )
vol = 10.*JUMBLR_INCR;
else*/ if ( avail >= JUMBLR_INCR )
vol = JUMBLR_INCR;
else vol = 0.;
if ( vol > 0. )
{
vals = cJSON_CreateObject();
jaddstr(vals,"source","KMD");
jaddstr(vals,"dest","BTC");
jaddnum(vals,"amount",vol);
//jaddnum(vals,"destamount",JUMBLR_INCR*kmdcoin->DEXinfo.btcprice);
jaddnum(vals,"minprice",0.985 * kmdcoin->DEXinfo.btcprice);
jaddnum(vals,"usejumblr",2);
memset(hash.bytes,0,sizeof(hash));
kmdcoin->DEXinfo.DEXpending += vol;
jaddnum(vals,"DEXselector",2);
if ( (retstr= InstantDEX_request(myinfo,coinbtc,0,0,hash,vals,"")) != 0 )
{
printf("request.(%s) -> (%s)\n",jprint(vals,0),retstr);
free(retstr);
}
free_json(vals);
}
} else printf("kmdavail %.8f pending %.8f\n",kmdcoin->DEXinfo.KMDavail,kmdcoin->DEXinfo.DEXpending);
} else printf("notlp.%d kmdprice %.8f\n",myinfo->IAMLP,kmdcoin->DEXinfo.btcprice);
}
void jumblr_iteration(struct supernet_info *myinfo,struct iguana_info *coin,int32_t selector,int32_t modval)
{
//static uint32_t lasttime;

336
basilisk/smartaddress.c

@ -24,15 +24,16 @@
int32_t smartaddress_type(char *typestr)
{
char upper[64];
if ( strcmp(typestr,"deposit") != 0 && strcmp(typestr,"jumblr") != 0 )
if ( strcmp(typestr,"deposit") != 0 && strcmp(typestr,"jumblr") != 0 && strcmp(typestr,"dividend") != 0 && strcmp(typestr,"pangea") != 0 )
{
upper[sizeof(upper)-1] = 0;
strncpy(upper,typestr,sizeof(upper)-1);
touppercase(upper);
if ( iguana_coinfind(upper) != 0 )
return(0);
else return(-1);
}
return(-1);
return(1);
}
bits256 jumblr_privkey(struct supernet_info *myinfo,char *coinaddr,uint8_t pubtype,char *KMDaddr,char *prefix)
@ -49,6 +50,16 @@ bits256 jumblr_privkey(struct supernet_info *myinfo,char *coinaddr,uint8_t pubty
return(privkey);
}
cJSON *smartaddress_extrajson(struct smartaddress *ap)
{
cJSON *retjson = cJSON_CreateObject();
if ( strcmp(ap->typestr,"dividend") == 0 )
{
}
return(retjson);
}
cJSON *smartaddress_json(struct smartaddress *ap)
{
char coinaddr[64]; int32_t j,n; struct iguana_info *coin; cJSON *array,*item,*retjson;
@ -67,6 +78,7 @@ cJSON *smartaddress_json(struct smartaddress *ap)
jaddstr(item,"address",coinaddr);
jaddnum(item,"maxbid",ap->symbols[j].maxbid);
jaddnum(item,"minask",ap->symbols[j].minask);
jadd(item,"extra",smartaddress_extrajson(ap));
jaddi(array,item);
}
}
@ -91,6 +103,29 @@ void smartaddress_symboladd(struct smartaddress *ap,char *symbol,double maxbid,d
}
}
void smartaddress_minmaxupdate(struct supernet_info *myinfo,char *_type,char *_symbol,double maxbid,double minask)
{
char type[64],symbol[64]; int32_t i,j,n; struct smartaddress *ap;
strcpy(type,_type), tolowercase(type);
strcpy(symbol,_symbol), touppercase(symbol);
for (i=0; i<myinfo->numsmartaddrs; i++)
{
ap = &myinfo->smartaddrs[i];
if ( strcmp(type,ap->typestr) == 0 )
{
n = ap->numsymbols;
for (j=0; j<n; j++)
{
if ( strcmp(ap->symbols[j].symbol,symbol) == 0 )
{
dxblend(&ap->symbols[j].maxbid,maxbid,0.5);
dxblend(&ap->symbols[j].minask,minask,0.5);
}
}
}
}
}
int32_t _smartaddress_add(struct supernet_info *myinfo,bits256 privkey,char *type,char *symbol,double maxbid,double minask)
{
char coinaddr[64]; uint8_t addrtype,rmd160[20]; struct smartaddress *ap; int32_t i,j,n;
@ -108,6 +143,8 @@ int32_t _smartaddress_add(struct supernet_info *myinfo,bits256 privkey,char *typ
{
ap->symbols[j].maxbid = maxbid;
ap->symbols[j].minask = minask;
if ( maxbid > SMALLVAL && minask > SMALLVAL && smartaddress_type(type) == 0 )
smartaddress_minmaxupdate(myinfo,symbol,type,1./minask,1./maxbid);
return(0);
}
}
@ -230,6 +267,301 @@ int32_t smartaddress_pubkey33(struct supernet_info *myinfo,char *typestr,double
return(retval);
}
void smartaddress_CMCname(char *CMCname,char *symbol)
{
if ( strcmp(symbol,"KMD") == 0 )
strcpy(CMCname,"komodo");
else if ( strcmp(symbol,"BTC") == 0 )
strcpy(CMCname,"bitcoin");
}
void smartaddress_coinupdate(struct supernet_info *myinfo,char *symbol,double BTC2KMD,double KMDavail,double KMD2USD)
{
int32_t r; double avebid,aveask,highbid,lowask,CMC_average,changes[3]; struct iguana_info *coin; struct DEXcoin_info *ptr;
if ( (coin= iguana_coinfind(symbol)) != 0 )
{
ptr = &coin->DEXinfo;
ptr->coin = coin;
if ( coin->CMCname[0] == 0 )
smartaddress_CMCname(coin->CMCname,symbol);
r = (((symbol[0]^symbol[1]^symbol[2])&0x7f) % 15) - 7; // 53 to 67 seconds
if ( time(NULL) > (ptr->lasttime + 60 + r) )
{
if ( strcmp(symbol,ptr->symbol) != 0 )
{
safecopy(ptr->symbol,symbol,sizeof(ptr->symbol));
safecopy(ptr->CMCname,coin->CMCname,sizeof(ptr->CMCname));
}
ptr->deposit_privkey = jumblr_privkey(myinfo,ptr->depositaddr,coin->chain->pubtype,ptr->KMDdepositaddr,JUMBLR_DEPOSITPREFIX);
ptr->jumblr_privkey = jumblr_privkey(myinfo,ptr->jumblraddr,coin->chain->pubtype,ptr->KMDjumblraddr,"");
ptr->avail = dstr(jumblr_balance(myinfo,coin,ptr->depositaddr));
ptr->jumblravail = dstr(jumblr_balance(myinfo,ptr->coin,ptr->jumblraddr));
if ( strcmp(symbol,"USD") == 0 )
{
if ( KMD2USD > SMALLVAL )
{
ptr->kmdprice = 1./ KMD2USD;
if ( (ptr->BTC2KMD= BTC2KMD) > SMALLVAL )
ptr->btcprice = ptr->kmdprice * BTC2KMD;
}
printf("USD btcprice %.8f kmdprice %.8f\n",ptr->btcprice,ptr->kmdprice);
}
else
{
if ( strcmp(symbol,"BTC") == 0 )
ptr->btcprice = 1.;
else if ( coin->CMCname[0] != 0 && (ptr->btcprice == 0. || (ptr->counter++ % 10) == 0) )
ptr->btcprice = get_theoretical(&avebid,&aveask,&highbid,&lowask,&CMC_average,changes,coin->CMCname,symbol,"BTC",&ptr->USD_average);
if ( strcmp("KMD",symbol) == 0 )
ptr->kmdprice = 1.;
else if ( (ptr->BTC2KMD= BTC2KMD) > SMALLVAL )
ptr->kmdprice = ptr->btcprice / BTC2KMD;
}
ptr->lasttime = (uint32_t)time(NULL);
printf("%s avail %.8f KMDavail %.8f btcprice %.8f deposit.(%s %s) -> jumblr.(%s %s)\n",symbol,ptr->avail,KMDavail,ptr->btcprice,ptr->depositaddr,ptr->KMDdepositaddr,ptr->jumblraddr,ptr->KMDjumblraddr);
}
} // else printf("skip\n");
}
void smartaddress_dex(struct supernet_info *myinfo,int32_t selector,struct iguana_info *basecoin,char *coinaddr,double maxavail,struct iguana_info *relcoin,double maxbid,double minask,cJSON *extraobj,double maxvol)
{
double minamount,minbtc,price,avail,vol,btc2kmd,basebtc,relbtc,baseusd,relusd; char *retstr; cJSON *vals; bits256 hash;
basebtc = basecoin->DEXinfo.btcprice;
relbtc = relcoin->DEXinfo.btcprice;
baseusd = basecoin->DEXinfo.USD_average;
relusd = relcoin->DEXinfo.USD_average;
if ( (btc2kmd= basecoin->DEXinfo.BTC2KMD) < SMALLVAL && (btc2kmd= relcoin->DEXinfo.BTC2KMD) < SMALLVAL )
return;
minamount = price = 0.;
if ( basebtc < SMALLVAL && relbtc < SMALLVAL )
return;
if ( basebtc < SMALLVAL || relbtc < SMALLVAL )
{
if ( (price= maxbid) > SMALLVAL )
{
if ( basebtc < SMALLVAL )
basebtc = price * relbtc, printf("calculated basebtc %.8f from (%.8f * %.8f)\n",basebtc,price,relbtc);
else if ( relbtc < SMALLVAL )
relbtc = basebtc / price, printf("calculated relbtc %.8f from (%.8f / %.8f)\n",relbtc,basebtc,price); // price * relbtc == basebtc
}
} else price = 0.985 * (basebtc / relbtc);
minbtc = btc2kmd * (JUMBLR_INCR + 3*(JUMBLR_INCR * JUMBLR_FEE + JUMBLR_TXFEE));
if ( minamount == 0. && basebtc > SMALLVAL )
minamount = (minbtc / basebtc);
printf("%s/%s minbtc %.8f btcprice %.8f -> minamount %.8f price %.8f vs maxbid %.8f\n",basecoin->symbol,relcoin->symbol,minbtc,basecoin->DEXinfo.btcprice,minamount,price,maxbid);
if ( minamount > SMALLVAL && maxavail > minamount + basecoin->DEXinfo.DEXpending && (maxbid == 0. || price <= maxbid) )
{
avail = (maxavail - (minamount + basecoin->DEXinfo.DEXpending));
if ( avail >= (100. * minamount) )
vol = (100. * minamount);
else if ( avail >= (10. * minamount) )
vol = (10. * minamount);
else if ( avail >= minamount )
vol = minamount;
else vol = 0.;
if ( vol > 0. )
{
vals = cJSON_CreateObject();
jaddstr(vals,"source",basecoin->symbol);
jaddstr(vals,"dest",relcoin->symbol);
jaddnum(vals,"amount",vol);
jaddnum(vals,"minprice",price);
if ( selector != 0 )
{
jaddnum(vals,"usejumblr",selector);
jaddnum(vals,"DEXselector",selector);
}
memset(hash.bytes,0,sizeof(hash));
basecoin->DEXinfo.DEXpending += vol;
if ( (retstr= InstantDEX_request(myinfo,basecoin,0,0,hash,vals,"")) != 0 )
{
printf("request.(%s) -> (%s)\n",jprint(vals,0),retstr);
free(retstr);
}
free_json(vals);
}
}
/*
minbtc = (basecoin->DEXinfo.btcprice * 1.2) * (JUMBLR_INCR + 3*(JUMBLR_INCR * JUMBLR_FEE + JUMBLR_TXFEE));
btcavail = dstr(jumblr_balance(myinfo,coinbtc,kmdcoin->DEXinfo.depositaddr));
avail = (btcavail - coinbtc->DEXinfo.DEXpending);
printf("BTC.%d deposits %.8f, min %.8f avail %.8f pending %.8f\n",toKMD,btcavail,minbtc,avail,coinbtc->DEXinfo.DEXpending);
if ( toKMD == 0 && coinbtc != 0 && btcavail > (minbtc + coinbtc->DEXinfo.DEXpending) )
{
if ( vol > 0. )
{
vals = cJSON_CreateObject();
jaddstr(vals,"source","BTC");
jaddstr(vals,"dest","KMD");
jaddnum(vals,"amount",vol);
jaddnum(vals,"minprice",0.985/kmdcoin->DEXinfo.btcprice);
jaddnum(vals,"usejumblr",1);
jaddnum(vals,"DEXselector",1);
memset(hash.bytes,0,sizeof(hash));
coinbtc->DEXinfo.DEXpending += vol;
if ( (retstr= InstantDEX_request(myinfo,coinbtc,0,0,hash,vals,"")) != 0 )
{
printf("request.(%s) -> (%s)\n",jprint(vals,0),retstr);
free(retstr);
}
free_json(vals);
// curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"request\",\"vals\":{\"source\":\"KMD\",\"amount\":20,\"dest\":\"USD\",\"minprice\":0.08}}"
}
} //else printf("btcavail %.8f pending %.8f\n",btcavail,pending);
minkmd = 100.;
avail = (kmdcoin->DEXinfo.KMDavail - kmdcoin->DEXinfo.DEXpending);
printf("KMD.%d deposits %.8f, min %.8f, avail %.8f pending %.8f\n",toKMD,kmdcoin->DEXinfo.KMDavail,minkmd,avail,kmdcoin->DEXinfo.DEXpending);
if ( toKMD != 0 && coinbtc != 0 && kmdcoin->DEXinfo.KMDavail > (minkmd + kmdcoin->DEXinfo.DEXpending) )
{
if ( avail > 100.*JUMBLR_INCR )
vol = 100.*JUMBLR_INCR;
else if ( avail > 10.*JUMBLR_INCR )
vol = 10.*JUMBLR_INCR;
else if ( avail >= JUMBLR_INCR )
vol = JUMBLR_INCR;
else vol = 0.;
if ( vol > 0. )
{
vals = cJSON_CreateObject();
jaddstr(vals,"source","KMD");
jaddstr(vals,"dest","BTC");
jaddnum(vals,"amount",vol);
//jaddnum(vals,"destamount",JUMBLR_INCR*kmdcoin->DEXinfo.btcprice);
jaddnum(vals,"minprice",0.985 * kmdcoin->DEXinfo.btcprice);
jaddnum(vals,"usejumblr",2);
memset(hash.bytes,0,sizeof(hash));
kmdcoin->DEXinfo.DEXpending += vol;
jaddnum(vals,"DEXselector",2);
if ( (retstr= InstantDEX_request(myinfo,coinbtc,0,0,hash,vals,"")) != 0 )
{
printf("request.(%s) -> (%s)\n",jprint(vals,0),retstr);
free(retstr);
}
free_json(vals);
}
} else printf("kmdavail %.8f pending %.8f\n",kmdcoin->DEXinfo.avail,kmdcoin->DEXinfo.DEXpending);*/
}
void smartaddress_depositjumblr(struct supernet_info *myinfo,char *symbol,char *coinaddr,double maxbid,double minask,cJSON *extraobj)
{
struct iguana_info *basecoin,*relcoin;
if ( (basecoin= iguana_coinfind(symbol)) != 0 && (relcoin= iguana_coinfind("KMD")) != 0 )
{
if ( strcmp(coinaddr,basecoin->DEXinfo.depositaddr) == 0 )
smartaddress_dex(myinfo,1,basecoin,coinaddr,basecoin->DEXinfo.avail,relcoin,maxbid,minask,extraobj,0.);
else printf("smartaddress_jumblr: mismatch deposit address (%s) vs (%s)\n",coinaddr,basecoin->DEXinfo.depositaddr);
}
}
double smartaddress_jumblrcredit(struct supernet_info *myinfo,char *symbol)
{
return(0.); // default to BTC conversion for now
}
void smartaddress_jumblr(struct supernet_info *myinfo,char *symbol,char *coinaddr,double maxbid,double minask,cJSON *extraobj)
{
struct iguana_info *basecoin,*relcoin; double credits = 0.;
if ( strcmp("BTC",symbol) != 0 )
{
if ( (credits= smartaddress_jumblrcredit(myinfo,symbol)) <= 0. )
return;
}
if ( (basecoin= iguana_coinfind("KMD")) != 0 && (relcoin= iguana_coinfind(symbol)) != 0 )
{
if ( strcmp(coinaddr,basecoin->DEXinfo.jumblraddr) == 0 )
smartaddress_dex(myinfo,2,basecoin,coinaddr,basecoin->DEXinfo.jumblravail,relcoin,maxbid,minask,extraobj,credits);
else printf("smartaddress_jumblr: mismatch jumblr address (%s) vs (%s)\n",coinaddr,basecoin->DEXinfo.jumblraddr);
}
}
void smartaddress_dividend(struct supernet_info *myinfo,char *symbol,char *coinaddr,double maxbid,double minask,cJSON *extraobj)
{
// support list of weighted addresses, including snapshots
}
void smartaddress_pangea(struct supernet_info *myinfo,char *symbol,char *coinaddr,double maxbid,double minask,cJSON *extraobj)
{
// table deposit
}
void smartaddress_action(struct supernet_info *myinfo,int32_t selector,char *typestr,char *symbol,char *coinaddr,double maxbid,double minask,cJSON *extraobj)
{
char rel[64]; struct iguana_info *basecoin,*relcoin; double avail;
if ( strcmp(typestr,"deposit") == 0 && selector == 0 )
smartaddress_depositjumblr(myinfo,symbol,coinaddr,maxbid,minask,extraobj);
else if ( strcmp(typestr,"jumblr") == 0 && selector == 0 )
smartaddress_jumblr(myinfo,symbol,coinaddr,maxbid,minask,extraobj);
else if ( strcmp(typestr,"dividend") == 0 && selector == 0 )
smartaddress_dividend(myinfo,symbol,coinaddr,maxbid,minask,extraobj);
else if ( strcmp(typestr,"pangea") == 0 && selector == 0 )
smartaddress_pangea(myinfo,symbol,coinaddr,maxbid,minask,extraobj);
else
{
safecopy(rel,typestr,sizeof(rel));
touppercase(rel);
if ( (relcoin= iguana_coinfind(rel)) != 0 && (basecoin= iguana_coinfind(symbol)) != 0 )
{
if ( myinfo->numswaps == 0 || (basecoin->FULLNODE < 0 && relcoin->FULLNODE < 0) )
{
if ( (avail= dstr(jumblr_balance(myinfo,basecoin,coinaddr))) > SMALLVAL )
smartaddress_dex(myinfo,0,basecoin,coinaddr,avail,relcoin,maxbid,minask,extraobj,0.);
}
}
}
}
void smartaddress_update(struct supernet_info *myinfo,int32_t selector)
{
double maxbid,minask; char *smartstr,*typestr,*symbol,*address; cJSON *smartarray,*extraobj,*item,*array,*coinitem; int32_t iter,i,n,j,m; struct iguana_info *kmdcoin,*coinbtc = 0;
//printf("smartaddress_update numswaps.%d notary.%d IAMLP.%d %p %p %f\n",myinfo->numswaps,myinfo->IAMNOTARY,myinfo->IAMLP,kmdcoin,coinbtc,kmdcoin->DEXinfo.btcprice);
if ( myinfo->IAMNOTARY != 0 || myinfo->IAMLP != 0 || myinfo->secret[0] == 0 )
return;
kmdcoin = iguana_coinfind("KMD");
coinbtc = iguana_coinfind("BTC");
if ( kmdcoin == 0 || coinbtc == 0 )
return;
smartaddress_coinupdate(myinfo,"KMD",0.,0.,0.); // must be first
if ( kmdcoin->DEXinfo.btcprice > SMALLVAL )
{
if ( (smartstr= InstantDEX_smartaddresses(myinfo,0,0,0)) != 0 )
{
if ( (smartarray= cJSON_Parse(smartstr)) != 0 )
{
if ( (n= cJSON_GetArraySize(smartarray)) > 0 )
{
for (iter=0; iter<2; iter++)
{
for (i=0; i<n; i++)
{
item = jitem(smartarray,i);
if ( (typestr= jstr(item,"type")) != 0 && (array= jarray(&m,item,"coins")) != 0 )
{
for (j=0; j<m; j++)
{
coinitem = jitem(array,j);
symbol = jstr(coinitem,"coin");
if ( iter == 0 )
smartaddress_coinupdate(myinfo,symbol,kmdcoin->DEXinfo.btcprice,kmdcoin->DEXinfo.avail,kmdcoin->DEXinfo.USD_average);
else
{
address = jstr(coinitem,"address");
maxbid = jdouble(coinitem,"maxbid");
minask = jdouble(coinitem,"minask");
extraobj = jobj(coinitem,"extra");
smartaddress_action(myinfo,selector,typestr,symbol,address,maxbid,minask,extraobj);
}
}
}
}
}
}
free_json(smartarray);
}
free(smartstr);
}
}
}
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"

9
iguana/main.c

@ -753,18 +753,13 @@ void jumblr_loop(void *ptr)
printf("JUMBLR loop\n");
while ( myinfo->IAMNOTARY == 0 )
{
if ( (coin= iguana_coinfind("KMD")) != 0 && iguana_coinfind("BTC") != 0 )
if ( (coin= iguana_coinfind("KMD")) != 0 )
{
//#ifdef __APPLE__
//if ( (n++ % 10) == 0 )
n++;
jumblr_DEXcheck(myinfo,coin,n & 1);//!((n/10)&1));
//#endif
smartaddress_update(myinfo,n & 1);
if ( myinfo->jumblr_passphrase[0] != 0 && coin->FULLNODE < 0 )
{
// if BTC has arrived in destination address, invoke DEX -> BTC
//if ( (n++ % 10) == 0 )
// jumblr_DEXcheck(myinfo,coin,!((n/10)&1));
t = (uint32_t)time(NULL);
if ( (t % (120 * mult)) < 60 )
{

2
includes/iguana_funcs.h

@ -629,7 +629,7 @@ int32_t iguana_staker_sort(struct iguana_info *coin,bits256 *hash2p,uint8_t *ref
bits256 mpz_div64(bits256 hash,uint64_t divval);
void iguana_walletinitcheck(struct supernet_info *myinfo,struct iguana_info *coin);
void jumblr_iteration(struct supernet_info *myinfo,struct iguana_info *coin,int32_t selector,int32_t modval);
void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coin,int32_t toKMD);
void smartaddress_update(struct supernet_info *myinfo,int32_t selector);
bits256 jumblr_privkey(struct supernet_info *myinfo,char *BTCaddr,uint8_t pubtype,char *KMDaddr,char *prefix);
char *jumblr_importprivkey(struct supernet_info *myinfo,struct iguana_info *coin,char *wifstr);
int64_t iguana_esttxfee(struct supernet_info *myinfo,struct iguana_info *coin,char *rawtx,char *signedtx,int32_t numvins);

4
includes/iguana_structs.h

@ -472,8 +472,8 @@ struct DEXcoin_info
{
bits256 deposit_privkey,jumblr_privkey;
struct iguana_info *coin;
double btcprice,BTC2KMD,kmdprice,USD_average,DEXpending,KMDpending,maxbid,minask,avail,KMDavail;
uint32_t lasttime; int32_t numpending;
double btcprice,BTC2KMD,kmdprice,USD_average,DEXpending,maxbid,minask,avail,jumblravail;
uint32_t lasttime,counter; int32_t numpending;
char CMCname[32],symbol[16],depositaddr[64],KMDdepositaddr[64],KMDjumblraddr[64],jumblraddr[64];
struct jumblr_pending *pending;
};

Loading…
Cancel
Save