Skip to content
This repository has been archived by the owner on May 28, 2021. It is now read-only.

Use target if provided #1424

Merged
merged 4 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions modules/node/src/channel/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class ChannelService {
multisigAddress: string,
assetId: string = AddressZero,
rebalanceType: RebalanceType,
requestedTarget: BigNumber = Zero,
requestedTarget?: BigNumber,
): Promise<
| {
completed?: () => Promise<FreeBalanceResponse>;
Expand Down Expand Up @@ -184,12 +184,12 @@ export class ChannelService {
);
}

const targetToUse = maxBN([profileTarget, requestedTarget]);
const thresholdToUse = maxBN([collateralizeThreshold, requestedTarget]);
const targetToUse = requestedTarget ? requestedTarget : profileTarget;
const thresholdToUse = requestedTarget ? requestedTarget : collateralizeThreshold;

if (nodeFreeBalance.lt(thresholdToUse)) {
this.log.info(
`nodeFreeBalance ${nodeFreeBalance.toString()} < thresholdToUse ${thresholdToUse.toString()}, depositing to target ${requestedTarget.toString()}`,
`nodeFreeBalance ${nodeFreeBalance.toString()} < thresholdToUse ${thresholdToUse.toString()}, depositing to target ${targetToUse.toString()}`,
);
const amount = targetToUse.sub(nodeFreeBalance);
rebalanceRes = (await this.depositService.deposit(channel, amount, normalizedAssetId))!;
Expand Down
13 changes: 13 additions & 0 deletions modules/test-runner/src/collateral/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ describe(name, () => {
expect(freeBalance[nodeSignerAddress]).to.be.least(requestedTarget);
});

it("should collateralize tokens with a target lower than profile", async () => {
const requestedTarget = utils.parseEther("10"); // requested < 20
const response = (await client.requestCollateral(tokenAddress, requestedTarget))!;
expect(response).to.be.ok;
expect(response.completed).to.be.ok;
expect(response.transaction).to.be.ok;
expect(response.transaction.hash).to.be.ok;
expect(response.depositAppIdentityHash).to.be.ok;
const { freeBalance } = await response.completed();
expect(freeBalance[client.signerAddress]).to.be.eq(Zero);
expect(freeBalance[nodeSignerAddress]).to.be.eq(requestedTarget);
});

it("should properly handle concurrent collateral requests", async () => {
const appDef = client.config.contractAddresses[client.chainId].DepositApp;
let depositAppCount = 0;
Expand Down