Skip to content

Commit 3f5dfc1

Browse files
feat: add estimated volume to estimateMatchOrders (#479)
1 parent 1026f45 commit 3f5dfc1

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

docs/classes/IExecOrderModule.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ ___
334334

335335
### estimateMatchOrders
336336

337-
**estimateMatchOrders**(`orders`, `options?`): `Promise`<{ `sponsored`: [`BN`](utils.BN.md) ; `total`: [`BN`](utils.BN.md) }\>
337+
**estimateMatchOrders**(`orders`, `options?`): `Promise`<{ `sponsored`: [`BN`](utils.BN.md) ; `total`: [`BN`](utils.BN.md) ; `volume`: [`BN`](utils.BN.md) }\>
338338

339339
estimates the cost of matching the provided orders
340340

@@ -347,6 +347,7 @@ const orders = {
347347
requestorder,
348348
};
349349
const result = await estimateMatchOrders(orders, {useVoucher: true});
350+
console.log(`executable volume: ${result.volume} tasks`);
350351
console.log(`total cost for matching orders: ${result.total} nRLC`);
351352
console.log(`sponsored cost covered by voucher: ${result.sponsored} nRLC`);
352353
```
@@ -366,7 +367,7 @@ console.log(`sponsored cost covered by voucher: ${result.sponsored} nRLC`);
366367

367368
#### Returns
368369

369-
`Promise`<{ `sponsored`: [`BN`](utils.BN.md) ; `total`: [`BN`](utils.BN.md) }\>
370+
`Promise`<{ `sponsored`: [`BN`](utils.BN.md) ; `total`: [`BN`](utils.BN.md) ; `volume`: [`BN`](utils.BN.md) }\>
370371

371372
___
372373

src/common/market/order.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,11 @@ export const estimateMatchOrders = async ({
893893
);
894894
}
895895

896-
return { total: totalCost, sponsored: sponsoredCost };
896+
return {
897+
volume: matchableVolume,
898+
total: totalCost,
899+
sponsored: sponsoredCost,
900+
};
897901
};
898902

899903
export const matchOrders = async ({

src/lib/IExecOrderModule.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,7 @@ export default class IExecOrderModule extends IExecModule {
10521052
* requestorder,
10531053
* };
10541054
* const result = await estimateMatchOrders(orders, {useVoucher: true});
1055+
* console.log(`executable volume: ${result.volume} tasks`);
10551056
* console.log(`total cost for matching orders: ${result.total} nRLC`);
10561057
* console.log(`sponsored cost covered by voucher: ${result.sponsored} nRLC`);
10571058
* ```
@@ -1075,7 +1076,7 @@ export default class IExecOrderModule extends IExecModule {
10751076
*/
10761077
voucherAddress?: Addressish;
10771078
},
1078-
): Promise<{ total: BN; sponsored: BN }>;
1079+
): Promise<{ volume: BN; total: BN; sponsored: BN }>;
10791080
/**
10801081
* Create an IExecOrderModule instance using an IExecConfig instance
10811082
*/

test/lib/e2e/IExecOrderModule.test.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ describe('unpublish...order()', () => {
14201420
});
14211421

14221422
describe('estimateMatchOrders()', () => {
1423-
test('estimates the total cost', async () => {
1423+
test('estimates the total cost and volume', async () => {
14241424
const noVoucherTestChain = TEST_CHAINS['custom-token-chain'];
14251425
const options = {
14261426
resultProxyURL: 'https://result-proxy.iex.ec',
@@ -1467,6 +1467,8 @@ describe('estimateMatchOrders()', () => {
14671467
expect(res.sponsored).toEqual(new BN(0));
14681468
expect(res.total).toBeInstanceOf(BN);
14691469
expect(res.total).toEqual(new BN(35));
1470+
expect(res.volume).toBeInstanceOf(BN);
1471+
expect(res.volume).toEqual(new BN(5));
14701472
});
14711473

14721474
describe('with useVoucher', () => {
@@ -1475,6 +1477,7 @@ describe('estimateMatchOrders()', () => {
14751477
let datasetorderTemplate;
14761478
let workerpoolorderTemplate;
14771479
let voucherTypeId;
1480+
let matchableVolume;
14781481
let expectedTotal;
14791482

14801483
beforeAll(async () => {
@@ -1493,7 +1496,7 @@ describe('estimateMatchOrders()', () => {
14931496
{ volume: 5, workerpoolprice: 1 },
14941497
);
14951498

1496-
const matchableVolume = new BN(5); // min volume among orders
1499+
matchableVolume = new BN(5); // min volume among orders
14971500
expectedTotal = new BN(5 + 1 + 1).mul(matchableVolume); // volume * orders unit prices
14981501

14991502
voucherTypeId = await createVoucherType(iexecTestChain)({
@@ -1581,6 +1584,8 @@ describe('estimateMatchOrders()', () => {
15811584
expect(res.sponsored).toEqual(new BN(0));
15821585
expect(res.total).toBeInstanceOf(BN);
15831586
expect(res.total).toEqual(new BN(35));
1587+
expect(res.volume).toBeInstanceOf(BN);
1588+
expect(res.volume).toEqual(new BN(5));
15841589
});
15851590

15861591
test('should have sponsored amount as 0 when useVoucher is false', async () => {
@@ -1613,6 +1618,8 @@ describe('estimateMatchOrders()', () => {
16131618
expect(res.sponsored).toEqual(new BN(0));
16141619
expect(res.total).toBeInstanceOf(BN);
16151620
expect(res.total).toEqual(expectedTotal);
1621+
expect(res.volume).toBeInstanceOf(BN);
1622+
expect(res.volume).toEqual(matchableVolume);
16161623
});
16171624

16181625
test('should return total cost and sponsored amount when using voucher', async () => {
@@ -1647,6 +1654,8 @@ describe('estimateMatchOrders()', () => {
16471654
expect(res.sponsored).toEqual(expectedTotal);
16481655
expect(res.total).toBeInstanceOf(BN);
16491656
expect(res.total).toEqual(expectedTotal);
1657+
expect(res.volume).toBeInstanceOf(BN);
1658+
expect(res.volume).toEqual(matchableVolume);
16501659
});
16511660

16521661
test('should return sponsored amount equal to voucher balance when voucher value is less than total cost', async () => {
@@ -1684,6 +1693,8 @@ describe('estimateMatchOrders()', () => {
16841693
expect(res.sponsored).toEqual(new BN(voucherInfo.balance));
16851694
expect(res.total).toBeInstanceOf(BN);
16861695
expect(res.total).toEqual(expectedTotal);
1696+
expect(res.volume).toBeInstanceOf(BN);
1697+
expect(res.volume).toEqual(matchableVolume);
16871698
});
16881699

16891700
test('should have sponsored amount as 0 when voucher expired', async () => {
@@ -1718,6 +1729,8 @@ describe('estimateMatchOrders()', () => {
17181729
expect(res.sponsored).toEqual(new BN(0));
17191730
expect(res.total).toBeInstanceOf(BN);
17201731
expect(res.total).toEqual(expectedTotal);
1732+
expect(res.volume).toBeInstanceOf(BN);
1733+
expect(res.volume).toEqual(matchableVolume);
17211734
});
17221735

17231736
describe('with custom voucherAddress option', () => {
@@ -1763,6 +1776,8 @@ describe('estimateMatchOrders()', () => {
17631776
expect(res.sponsored).toEqual(expectedTotal);
17641777
expect(res.total).toBeInstanceOf(BN);
17651778
expect(res.total).toEqual(expectedTotal);
1779+
expect(res.volume).toBeInstanceOf(BN);
1780+
expect(res.volume).toEqual(matchableVolume);
17661781
});
17671782

17681783
test('should throw if specified voucherAddress is not a voucher', async () => {

0 commit comments

Comments
 (0)