Skip to content

Commit

Permalink
shakedex: update version to v0.0.18
Browse files Browse the repository at this point in the history
And old version deprecation
  • Loading branch information
rithvikvibhu committed Jul 6, 2022
1 parent c0618ad commit d6de9cd
Show file tree
Hide file tree
Showing 18 changed files with 2,112 additions and 532 deletions.
1 change: 1 addition & 0 deletions app/background/node/client.js
Expand Up @@ -18,6 +18,7 @@ export const clientStub = ipcRendererInjector => makeClient(ipcRendererInjector,
'sendRawAirdrop',
'getFees',
'getAverageBlockTime',
'getMTP',
'getCoin',
'verifyMessageWithName',
'setNodeDir',
Expand Down
6 changes: 6 additions & 0 deletions app/background/node/service.js
Expand Up @@ -517,6 +517,11 @@ export class NodeService extends EventEmitter {
return Math.floor((sum / count) * 1000);
}

async getMTP() {
const info = await this._execRPC('getblockchaininfo');
return info.mediantime;
};

async getCoin(hash, index) {
if (await this.getSpvMode()) {
return hapiGet(`/coin/${hash}/${index}`);
Expand Down Expand Up @@ -627,6 +632,7 @@ const methods = {
sendRawAirdrop: (data) => service.sendRawAirdrop(data),
getFees: () => service.getFees(),
getAverageBlockTime: () => service.getAverageBlockTime(),
getMTP: () => service.getMTP(),
getCoin: (hash, index) => service.getCoin(hash, index),
setNodeDir: data => service.setNodeDir(data),
setAPIKey: data => service.setAPIKey(data),
Expand Down
1 change: 1 addition & 0 deletions app/background/shakedex/client.js
Expand Up @@ -16,4 +16,5 @@ export const clientStub = ipcRendererInjector => makeClient(ipcRendererInjector,
'getExchangeAuctions',
'listAuction',
'getFeeInfo',
'getBestBid',
]);
45 changes: 32 additions & 13 deletions app/background/shakedex/service.js
Expand Up @@ -84,11 +84,19 @@ export async function iteratePrefix(prefix, cb) {
}

export async function getExchangeAuctions(currentPage = 1) {
return await client.get(`api/v1/auctions?page=${currentPage}&per_page=20`);
const res = await client.get(`api/v2/auctions?page=${currentPage}&per_page=20`);
const auctions = res.auctions.map(auction => {
auction.bids.sort((a,b) => b.price - a.price);
return auction;
})
return {
total: +res.total,
auctions
}
}

export async function listAuction(auction) {
const resp = await fetch(`https://api.shakedex.com/api/v1/auctions`, {
const resp = await fetch(`https://api.shakedex.com/api/v2/auctions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
Expand All @@ -110,7 +118,7 @@ export async function fulfillSwap(auction, bid, passphrase) {
paymentAddr: auction.paymentAddr,
price: bid.price,
fee: bid.fee,
lockTime: Math.floor(bid.lockTime / 1000),
lockTime: bid.lockTime,
signature: bid.signature,
});

Expand Down Expand Up @@ -332,24 +340,24 @@ export async function launchAuction(nameLock, passphrase, paramsOverride, persis
const key = `${listingPrefix()}/${nameLock.name}/${nameLock.transferTxHash}`;
const listing = await get(key);

const {startPrice, endPrice, durationDays, feeRate, feeAddr} = paramsOverride || listing.params;
const {startPrice, endPrice, durationDays, feeRate, feeAddr, lowestDeprecatedPrice} = paramsOverride || listing.params;

if (paramsOverride) {
listing.params = paramsOverride;
}

let reductionTimeMS;
let reductionTime;
switch (durationDays) {
case 1:
reductionTimeMS = 60 * 60 * 1000;
reductionTime = 60 * 60;
break;
case 3:
reductionTimeMS = 3 * 60 * 60 * 1000;
reductionTime = 3 * 60 * 60;
break;
case 5:
case 7:
case 14:
reductionTimeMS = 24 * 60 * 60 * 1000;
reductionTime = 24 * 60 * 60;
break;
}

Expand All @@ -364,13 +372,15 @@ export async function launchAuction(nameLock, passphrase, paramsOverride, persis

if (!finalizeCoin) throw new Error('cannot find finalize coin');

const mtp = await nodeService.getMTP();

const auctionFactory = new AuctionFactory({
name: listing.nameLock.name,
startTime: Date.now(),
endTime: Date.now() + durationDays * 24 * 60 * 60 * 1000,
startTime: mtp >>> 0,
endTime: (mtp + durationDays * 24 * 60 * 60) >>> 0,
startPrice: startPrice,
endPrice: endPrice,
reductionTimeMS,
reductionTime,
reductionStrategy: linearReductionStrategy,
feeRate: feeRate || 0,
feeAddr,
Expand All @@ -388,6 +398,9 @@ export async function launchAuction(nameLock, passphrase, paramsOverride, persis
const auctionJSON = auction.toJSON(context);
if (persist) {
listing.auction = auctionJSON;
if (lowestDeprecatedPrice) {
listing.lowestDeprecatedPrice = lowestDeprecatedPrice;
}
await put(
key,
listing,
Expand All @@ -397,7 +410,7 @@ export async function launchAuction(nameLock, passphrase, paramsOverride, persis
}

export async function getFeeInfo() {
const resp = await fetch(`https://api.shakedex.com/api/v1/fee_info`);
const resp = await fetch(`https://api.shakedex.com/api/v2/fee_info`);
if (resp.status === 404) {
return {
rate: 0,
Expand All @@ -407,13 +420,18 @@ export async function getFeeInfo() {
return resp.json();
}

export async function getBestBid(auction) {
const context = getContext();
return (new Auction({...auction, data: auction.bids})).bestBidAt(context);
}

async function downloadProofs(auctionJSON) {
const context = getContext();
const proofs = [];
for (const bid of auctionJSON.bids) {
proofs.push(new SwapProof({
price: bid.price,
lockTime: bid.lockTime / 1000,
lockTime: bid.lockTime,
signature: bid.signature,
}));
}
Expand Down Expand Up @@ -472,6 +490,7 @@ const methods = {
getExchangeAuctions,
listAuction,
getFeeInfo,
getBestBid,
};

export async function start(server) {
Expand Down

0 comments on commit d6de9cd

Please sign in to comment.