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

Commit

Permalink
Merge pull request #1424 from connext/1423-use-provided-collateral-ta…
Browse files Browse the repository at this point in the history
…rget

Use target if provided
  • Loading branch information
rhlsthrm authored Sep 19, 2020
2 parents c5b7b78 + 7ed99be commit e3f03ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
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

0 comments on commit e3f03ed

Please sign in to comment.