Skip to content

Commit

Permalink
sdk: rename Udc to UDC and address PR comments
Browse files Browse the repository at this point in the history
- Raiden.udcWithdraw -> Raiden.withdrawFromUDC
- Raiden.planUdcWithdraw -> Raiden.planUDCWithdraw
- config.autoUdcWithdraw -> config.autoUDCWithdraw
- 100 -> constants.UDC_WITHDRAW_TIMEOUT
  • Loading branch information
andrevmatos committed Mar 25, 2021
1 parent 33a87cf commit 9b6f0a6
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion raiden-dapp/src/components/dialogs/UdcWithdrawalDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default class UdcWithdrawalDialog extends Vue {
async planWithdraw() {
this.inProgress = true;
try {
await this.$raiden.planUdcWithdraw(this.withdrawAmount);
await this.$raiden.planUDCWithdraw(this.withdrawAmount);
this.done();
} catch (e) {
this.error = e;
Expand Down
4 changes: 2 additions & 2 deletions raiden-dapp/src/services/raiden-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,8 @@ export default class RaidenService {
}

/* istanbul ignore next */
async planUdcWithdraw(amount: BigNumber): Promise<string> {
return this.raiden.planUdcWithdraw(amount);
async planUDCWithdraw(amount: BigNumber): Promise<string> {
return this.raiden.planUDCWithdraw(amount);
}

/* istanbul ignore next */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('UdcWithdrawalDialog.vue', function () {
expect.assertions(1);
await (wrapper.vm as any).planWithdraw();
await flushPromises();
expect($raiden.planUdcWithdraw).toBeCalledTimes(1);
expect($raiden.planUDCWithdraw).toBeCalledTimes(1);
});

test('invalid withdraw amount is zero', async () => {
Expand Down
5 changes: 4 additions & 1 deletion raiden-ts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
### Added
- [#1342] Flat (fixed) mediation fees for mediator nodes
- [#2581] `config.pfsSafetyMargin` now also accepts a `[f, a]` pair, which will add `f*fee + a*amount` on top of PFS's estimated fee, if one wants finer-grain control on safety margin which is added on the transfer to be initiated.
- [#2629] `config.autoUdcWithdraw` (default=true) to allow disabling automatically completing a planned UDC withdraw, and new `Raiden.getUdcWithdrawPlan` and `Raiden.udcWithdraw` to check and perform UDC withdraw when not in auto mode.
- [#2629] `config.autoUDCWithdraw` (default=true) to allow disabling automatically completing a planned UDC withdraw, and new `Raiden.getUDCWithdrawPlan` and `Raiden.withdrawFromUDC` to check and perform UDC withdraw when not in auto mode.

### Changed
- [#2536] Wait for global messages before resolving deposits and channel open request
- [#2566] Optimize initial sync and resume previous sync filters scans
- [#2570] Support multiple custom services in config.pfs
- [#2635] **BREAKING** Renamed `Raiden.planUdcWithdraw` to `Raiden.planUDCWithdraw` for consistency

### Removed
- [#2550] **BREAKING** Remove migration of legacy state at localStorage during creation
Expand All @@ -28,6 +29,8 @@
[#2581]: https://github.com/raiden-network/light-client/pull/2581
[#2596]: https://github.com/raiden-network/light-client/issues/2596
[#2600]: https://github.com/raiden-network/light-client/issues/2600
[#2629]: https://github.com/raiden-network/light-client/issues/2629
[#2635]: https://github.com/raiden-network/light-client/pull/2635

## [0.15.0] - 2021-01-26
### Added
Expand Down
6 changes: 3 additions & 3 deletions raiden-ts/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const RTCIceServer = t.type({ urls: t.union([t.string, t.array(t.string)]) });
* approving tokens should be needed only once, trusting TokenNetwork's & UDC contracts;
* Set to Zero to fallback to approving the strictly needed deposit amounts
* - autoSettle - Whether to channelSettle.request settleable channels automatically
* - autoUdcWithdraw - Whether to udcWithdraw.request planned withdraws automatically
* - autoUDCWithdraw - Whether to udcWithdraw.request planned withdraws automatically
* - mediationFees - deps.mediationFeeCalculator config. It's typed as unknown because it'll be
* validated and decoded by [[FeeModel.decodeConfig]].
* - matrixServer? - Specify a matrix server to use.
Expand Down Expand Up @@ -98,7 +98,7 @@ export const RaidenConfig = t.readonly(
pollingInterval: t.number,
minimumAllowance: UInt(32),
autoSettle: t.boolean,
autoUdcWithdraw: t.boolean,
autoUDCWithdraw: t.boolean,
mediationFees: t.unknown,
}),
t.partial({
Expand Down Expand Up @@ -168,7 +168,7 @@ export function makeDefaultConfig(
pollingInterval: 5000,
minimumAllowance: MaxUint256 as UInt<32>,
autoSettle: false,
autoUdcWithdraw: true,
autoUDCWithdraw: true,
mediationFees: {},
...overwrites,
caps, // merged caps overwrites 'overwrites.caps'
Expand Down
1 change: 1 addition & 0 deletions raiden-ts/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ export const CapsFallback = {

export const RAIDEN_DEVICE_ID = 'RAIDEN';
export const DEFAULT_CONFIRMATIONS = 5;
export const UDC_WITHDRAW_TIMEOUT = 100;
4 changes: 2 additions & 2 deletions raiden-ts/src/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@
"UDC_PLAN_WITHDRAW_EXCEEDS_AVAILABLE" : "The planned withdraw amount exceeds the total amount available for withdrawing.",
"UDC_WITHDRAW_NO_BALANCE" : "There is no balances left to withdraw from UDC.",
"UDC_WITHDRAW_FAILED" : "An error occurred while withdrawing from the UDC.",
"UDC_WITHDRAW_AUTO_ENABLED": "Interactive udcWithdraw disabled when config.autoUdcWithdraw is enabled; request will be made automatically",
"UDC_WITHDRAW_NO_PLAN": "No plan currently registered; you must call Raiden.planUdcWithdraw first",
"UDC_WITHDRAW_AUTO_ENABLED": "Interactive UDC withdraw disabled when config.autoUDCWithdraw is enabled; request will be made automatically",
"UDC_WITHDRAW_NO_PLAN": "No plan currently registered; you must call Raiden.planUDCWithdraw first",
"UDC_WITHDRAW_TOO_EARLY": "The current UDC withdraw plan is not yet ready to be withdrawn",
"UDC_WITHDRAW_TOO_LARGE": "Your current plan is not enough to withdraw the requested amount"
}
Expand Down
22 changes: 10 additions & 12 deletions raiden-ts/src/raiden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1393,9 +1393,9 @@ export class Raiden {
*
* @returns Promise to object containing maximum 'amount' planned for withdraw and 'block' at
* which withdraw will become available, and 'ready' after it can be withdrawn with
* [[udcWithdraw]]; resolves to undefined if there's no current plan
* [[withdrawFromUDC]]; resolves to undefined if there's no current plan
*/
public async getUdcWithdrawPlan(): Promise<
public async getUDCWithdrawPlan(): Promise<
{ amount: UInt<32>; block: number; ready: boolean } | undefined
> {
const plan = await this.deps.userDepositContract.withdraw_plans(this.address);
Expand All @@ -1410,15 +1410,14 @@ export class Raiden {
/**
* Records a UDC withdraw plan for our UDC deposit
*
* The plan will be ready for withdraw after 100 blocks.
* Maximum 'value' which can be planned is current [[getUDCCapacity]] plus current
* [[getUdcWithdrawPlan]].amount, since new plan overwrites previous.
* [[getUDCWithdrawPlan]].amount, since new plan overwrites previous.
*
* @param value - Maximum value which we may try to withdraw. An error will be thrown if this
* value is larger than [[getUDCCapacity]]+[[getUdcWithdrawPlan]].amount
* value is larger than [[getUDCCapacity]]+[[getUDCWithdrawPlan]].amount
* @returns Promise to hash of plan transaction, if it succeeds.
*/
public async planUdcWithdraw(value: BigNumberish): Promise<Hash> {
public async planUDCWithdraw(value: BigNumberish): Promise<Hash> {
const meta = {
amount: decode(UInt(32), value, ErrorCodes.DTA_INVALID_AMOUNT, this.log.error),
};
Expand All @@ -1433,16 +1432,15 @@ export class Raiden {
* Complete a planned UDC withdraw and get the deposit to account.
*
* Maximum 'value' is the one from current plan, attempting to withdraw a larger value will throw
* an error, but a smaller value is valid. This method may only be called after plan is 'ready',
* i.e. at least 100 blocks have passed after it was planned.
* an error, but a smaller value is valid. This method may only be called after plan is 'ready'
*
* @param value - Maximum value which we may try to withdraw. An error will be thrown if this
* value is larger than [[getUDCCapacity]]+[[getUdcWithdrawPlan]].amount
* value is larger than [[getUDCCapacity]]+[[getUDCWithdrawPlan]].amount
* @returns Promise to hash of plan transaction, if it succeeds.
*/
public async udcWithdraw(value?: BigNumberish): Promise<Hash> {
assert(!this.config.autoUdcWithdraw, ErrorCodes.UDC_WITHDRAW_AUTO_ENABLED, this.log.warn);
const plan = await this.getUdcWithdrawPlan();
public async withdrawFromUDC(value?: BigNumberish): Promise<Hash> {
assert(!this.config.autoUDCWithdraw, ErrorCodes.UDC_WITHDRAW_AUTO_ENABLED, this.log.warn);
const plan = await this.getUDCWithdrawPlan();
assert(plan, ErrorCodes.UDC_WITHDRAW_NO_PLAN, this.log.warn);
assert(plan.ready, ErrorCodes.UDC_WITHDRAW_TOO_EARLY, this.log.warn);
if (!value) {
Expand Down
16 changes: 6 additions & 10 deletions raiden-ts/src/services/epics/udc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { RaidenAction } from '../../actions';
import { newBlock } from '../../channels/actions';
import { approveIfNeeded$, assertTx } from '../../channels/utils';
import { intervalFromConfig } from '../../config';
import { UDC_WITHDRAW_TIMEOUT } from '../../constants';
import type { HumanStandardToken, UserDeposit } from '../../contracts';
import { chooseOnchainAccount, getContractWithSigner } from '../../helpers';
import type { RaidenState } from '../../state';
Expand Down Expand Up @@ -272,7 +273,7 @@ export function udcWithdrawPlanRequestEpic(
}

/**
* If config.autoUdcWithdraw is enabled, monitors planned withdraws and udcWithdraw.request when
* If config.autoUDCWithdraw is enabled, monitors planned withdraws and udcWithdraw.request when
* ready
*
* @param action$ - Observable of RaidenActions
Expand All @@ -289,7 +290,6 @@ export function udcAutoWithdrawEpic(
{}: Observable<RaidenState>,
{ userDepositContract, address, config$, log }: RaidenEpicDeps,
): Observable<udcWithdraw.request> {
const WITHDRAW_TIMEOUT = 100;
let nextCheckBlock = 0;
return action$.pipe(
filter(newBlock.is),
Expand All @@ -300,7 +300,7 @@ export function udcAutoWithdrawEpic(
filter(({ withdraw_block: withdrawBlock }) => {
const currentBlock = action.payload.blockNumber;
if (withdrawBlock.isZero()) {
nextCheckBlock = currentBlock + WITHDRAW_TIMEOUT;
nextCheckBlock = currentBlock + UDC_WITHDRAW_TIMEOUT;
return false;
} else if (withdrawBlock.gt(currentBlock)) {
nextCheckBlock = withdrawBlock.toNumber();
Expand All @@ -318,7 +318,7 @@ export function udcAutoWithdrawEpic(
}),
),
),
takeIf(config$.pipe(pluck('autoUdcWithdraw'))),
takeIf(config$.pipe(pluck('autoUDCWithdraw'))),
);
}

Expand Down Expand Up @@ -346,11 +346,7 @@ export function udcWithdrawEpic(
concatMap((action) => {
const contract = getContractWithSigner(userDepositContract, signer);
let balance: UInt<32>;
return retryAsync$(
async () => userDepositContract.callStatic.balances(address),
intervalFromConfig(config$),
{ onErrors: networkErrors, log: log.info },
).pipe(
return defer(async () => userDepositContract.callStatic.balances(address)).pipe(
mergeMap(async (balance_) => {
assert(balance_.gt(Zero), [
ErrorCodes.UDC_WITHDRAW_NO_BALANCE,
Expand All @@ -360,7 +356,7 @@ export function udcWithdrawEpic(
return contract.withdraw(action.meta.amount);
}),
assertTx('withdraw', ErrorCodes.UDC_WITHDRAW_FAILED, { log, provider }),
retryWhile(intervalFromConfig(config$), { onErrors: commonTxErrors, log: log.debug }),
retryWhile(intervalFromConfig(config$), { onErrors: commonTxErrors, log: log.info }),
mergeMap(([, { transactionHash, blockNumber }]) =>
action$.pipe(
filter(newBlock.is),
Expand Down
4 changes: 2 additions & 2 deletions raiden-ts/tests/unit/epics/udc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ describe('udcWithdraw', () => {
const withdrawTx = makeTransaction(1);
const raiden = await makeRaiden(undefined, false);

raiden.store.dispatch(raidenConfigUpdate({ autoUdcWithdraw: false }));
raiden.store.dispatch(raidenConfigUpdate({ autoUDCWithdraw: false }));
raiden.deps.userDepositContract.withdraw.mockResolvedValue(withdrawTx);
raiden.deps.userDepositContract.balances
.mockClear()
Expand Down Expand Up @@ -336,7 +336,7 @@ describe('udcWithdraw', () => {
const withdrawTx = makeTransaction(0); // failed tx
const raiden = await makeRaiden(undefined, false);

raiden.store.dispatch(raidenConfigUpdate({ autoUdcWithdraw: false }));
raiden.store.dispatch(raidenConfigUpdate({ autoUDCWithdraw: false }));
raiden.deps.userDepositContract.withdraw.mockResolvedValue(withdrawTx);
raiden.deps.userDepositContract.balances
.mockClear()
Expand Down

0 comments on commit 9b6f0a6

Please sign in to comment.