From 8b77a35d6ea1aaaae2d8a8920c006ceff65be437 Mon Sep 17 00:00:00 2001 From: golobitch Date: Sun, 3 Nov 2024 23:03:45 +0100 Subject: [PATCH 1/8] feat(backend)!: add liquidity threshold high for asset and peer --- .../generated/graphql.ts | 30 +++++-- ...3204430_assets_peer_liquidity_threshold.js | 25 ++++++ packages/backend/src/asset/model.ts | 53 +++++++----- packages/backend/src/asset/service.ts | 15 ++-- .../src/graphql/generated/graphql.schema.json | 84 +++++++++++++++++-- .../backend/src/graphql/generated/graphql.ts | 30 +++++-- .../backend/src/graphql/resolvers/asset.ts | 6 +- .../backend/src/graphql/resolvers/peer.ts | 3 +- packages/backend/src/graphql/schema.graphql | 24 ++++-- .../src/payment-method/ilp/peer/model.ts | 53 +++++++----- .../src/payment-method/ilp/peer/service.ts | 6 +- packages/backend/src/tests/peer.ts | 4 +- packages/frontend/app/generated/graphql.ts | 30 +++++-- .../src/generated/graphql.ts | 30 +++++-- test/integration/lib/generated/graphql.ts | 30 +++++-- 15 files changed, 319 insertions(+), 104 deletions(-) create mode 100644 packages/backend/migrations/20241103204430_assets_peer_liquidity_threshold.js diff --git a/localenv/mock-account-servicing-entity/generated/graphql.ts b/localenv/mock-account-servicing-entity/generated/graphql.ts index 131de7eb44..6d720b6e38 100644 --- a/localenv/mock-account-servicing-entity/generated/graphql.ts +++ b/localenv/mock-account-servicing-entity/generated/graphql.ts @@ -112,8 +112,10 @@ export type Asset = Model & { id: Scalars['ID']['output']; /** Available liquidity */ liquidity?: Maybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this value. */ + liquidityThresholdHigh?: Maybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this value. */ - liquidityThreshold?: Maybe; + liquidityThresholdLow?: Maybe; /** The receiving fee structure for the asset. */ receivingFee?: Maybe; /** Difference in order of magnitude between the standard unit of an asset and its corresponding fractional unit. */ @@ -191,8 +193,10 @@ export type CreateAssetInput = { code: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** Difference in order of magnitude between the standard unit of an asset and its corresponding fractional unit. */ scale: Scalars['UInt8']['input']; /** Minimum amount of liquidity that can be withdrawn from the asset. */ @@ -299,8 +303,10 @@ export type CreatePeerInput = { idempotencyKey?: InputMaybe; /** Initial amount of liquidity to deposit for the peer. */ initialLiquidity?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if peer liqudity is higher than this value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if peer liquidity falls below this value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** Maximum packet amount that the peer accepts. */ maxPacketAmount?: InputMaybe; /** Internal name of the peer. */ @@ -1085,8 +1091,10 @@ export type Peer = Model & { id: Scalars['ID']['output']; /** Current amount of peer liquidity available. */ liquidity?: Maybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this value. */ + liquidityThresholdHigh?: Maybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this value. */ - liquidityThreshold?: Maybe; + liquidityThresholdLow?: Maybe; /** Maximum packet amount that the peer accepts. */ maxPacketAmount?: Maybe; /** Public name for the peer. */ @@ -1376,8 +1384,10 @@ export type UpdateAssetInput = { id: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this new value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this new value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** New minimum amount of liquidity that can be withdrawn from the asset. */ withdrawalThreshold?: InputMaybe; }; @@ -1396,8 +1406,10 @@ export type UpdatePeerInput = { id: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if peer liquidity is higher than this new value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if peer liquidity falls below this new value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** New maximum packet amount that the peer accepts. */ maxPacketAmount?: InputMaybe; /** New public name for the peer. */ @@ -1980,7 +1992,8 @@ export type AssetResolvers, ParentType, ContextType, Partial>; id?: Resolver; liquidity?: Resolver, ParentType, ContextType>; - liquidityThreshold?: Resolver, ParentType, ContextType>; + liquidityThresholdHigh?: Resolver, ParentType, ContextType>; + liquidityThresholdLow?: Resolver, ParentType, ContextType>; receivingFee?: Resolver, ParentType, ContextType>; scale?: Resolver; sendingFee?: Resolver, ParentType, ContextType>; @@ -2253,7 +2266,8 @@ export type PeerResolvers; id?: Resolver; liquidity?: Resolver, ParentType, ContextType>; - liquidityThreshold?: Resolver, ParentType, ContextType>; + liquidityThresholdHigh?: Resolver, ParentType, ContextType>; + liquidityThresholdLow?: Resolver, ParentType, ContextType>; maxPacketAmount?: Resolver, ParentType, ContextType>; name?: Resolver, ParentType, ContextType>; staticIlpAddress?: Resolver; diff --git a/packages/backend/migrations/20241103204430_assets_peer_liquidity_threshold.js b/packages/backend/migrations/20241103204430_assets_peer_liquidity_threshold.js new file mode 100644 index 0000000000..7716649f3c --- /dev/null +++ b/packages/backend/migrations/20241103204430_assets_peer_liquidity_threshold.js @@ -0,0 +1,25 @@ +exports.up = function(knex) { + return Promise.all([ + knex.schema.table('assets', (table) => { + table.renameColumn('liquidityThreshold', 'liquidityThresholdLow') + table.bigInteger('liquidityThresholdHigh').nullable() + }), + knex.schema.table('peers', (table) => { + table.renameColumn('liquidityThreshold', 'liquidityThresholdLow') + table.bigInteger('liquidityThresholdHigh').nullable() + }) + ]) +} + +exports.down = function(knex) { + return Promise.all([ + knex.schema.table('assets', (table) => { + table.renameColumn('liquidityThresholdLow', 'liquidityThreshold') + table.dropColumn('liquidityThresholdHigh') + }), + knex.schema.table('peers', (table) => { + table.renameColumn('liquidityThresholdLow', 'liquidityThreshold') + table.dropColumn('liquidityThresholdHigh') + }) + ]) +} diff --git a/packages/backend/src/asset/model.ts b/packages/backend/src/asset/model.ts index 62237fcd20..279163c11a 100644 --- a/packages/backend/src/asset/model.ts +++ b/packages/backend/src/asset/model.ts @@ -16,7 +16,9 @@ export class Asset extends BaseModel implements LiquidityAccount { public readonly withdrawalThreshold!: bigint | null - public readonly liquidityThreshold!: bigint | null + public readonly liquidityThresholdLow!: bigint | null + + public readonly liquidityThresholdHigh!: bigint | null public readonly deletedAt: string | null | undefined @@ -28,31 +30,44 @@ export class Asset extends BaseModel implements LiquidityAccount { } } - public async onDebit({ balance }: OnDebitOptions): Promise { - if (this.liquidityThreshold !== null) { - if (balance <= this.liquidityThreshold) { - await AssetEvent.query().insert({ - assetId: this.id, - type: AssetEventType.LiquidityLow, - data: { + private async checkAndInsertEvent(balance: bigint, threshold: bigint | null, eventType: AssetEventType) { + if (threshold === null) { + return + } + + const isThresholdCrossed = (eventType === AssetEventType.LiquidityLow && balance <= threshold) || (eventType === AssetEventType.LiquidityHigh && balance >= threshold) + + if (isThresholdCrossed) { + await AssetEvent.query().insert({ + assetId: this.id, + type: eventType, + data: { + id: this.id, + asset: { id: this.id, - asset: { - id: this.id, - code: this.code, - scale: this.scale - }, - liquidityThreshold: this.liquidityThreshold, - balance - } - }) - } + code: this.code, + scale: this.scale + }, + liquidityThreshold: threshold, + balance + } + }) } + } + + public async onDebit({ balance }: OnDebitOptions): Promise { + await Promise.all([ + this.checkAndInsertEvent(balance, this.liquidityThresholdLow, AssetEventType.LiquidityLow), + this.checkAndInsertEvent(balance, this.liquidityThresholdHigh, AssetEventType.LiquidityHigh) + ]) + return this } } export enum AssetEventType { - LiquidityLow = 'asset.liquidity_low' + LiquidityLow = 'asset.liquidity_low', + LiquidityHigh = 'asset.liquidity_high' } export type AssetEventData = { diff --git a/packages/backend/src/asset/service.ts b/packages/backend/src/asset/service.ts index 139006e926..82c22fca8b 100644 --- a/packages/backend/src/asset/service.ts +++ b/packages/backend/src/asset/service.ts @@ -15,13 +15,15 @@ export interface AssetOptions { export interface CreateOptions extends AssetOptions { withdrawalThreshold?: bigint - liquidityThreshold?: bigint + liquidityThresholdLow?: bigint + liquidityThresholdHigh?: bigint | null } export interface UpdateOptions { id: string withdrawalThreshold: bigint | null - liquidityThreshold: bigint | null + liquidityThresholdLow: bigint | null + liquidityThresholdHigh?: bigint | null } export interface DeleteOptions { id: string @@ -67,7 +69,7 @@ export async function createAssetService({ async function createAsset( deps: ServiceDependencies, - { code, scale, withdrawalThreshold, liquidityThreshold }: CreateOptions + { code, scale, withdrawalThreshold, liquidityThresholdLow, liquidityThresholdHigh }: CreateOptions ): Promise { try { // check if exists but deleted | by code-scale @@ -95,7 +97,8 @@ async function createAsset( code, scale, withdrawalThreshold, - liquidityThreshold + liquidityThresholdLow, + liquidityThresholdHigh, }) await deps.accountingService.createLiquidityAndLinkedSettlementAccount( asset, @@ -114,14 +117,14 @@ async function createAsset( async function updateAsset( deps: ServiceDependencies, - { id, withdrawalThreshold, liquidityThreshold }: UpdateOptions + { id, withdrawalThreshold, liquidityThresholdLow, liquidityThresholdHigh }: UpdateOptions ): Promise { if (!deps.knex) { throw new Error('Knex undefined') } try { return await Asset.query(deps.knex) - .patchAndFetchById(id, { withdrawalThreshold, liquidityThreshold }) + .patchAndFetchById(id, { withdrawalThreshold, liquidityThresholdLow, liquidityThresholdHigh }) .throwIfNotFound() } catch (err) { if (err instanceof NotFoundError) { diff --git a/packages/backend/src/graphql/generated/graphql.schema.json b/packages/backend/src/graphql/generated/graphql.schema.json index 3f5f20485e..227908acd2 100644 --- a/packages/backend/src/graphql/generated/graphql.schema.json +++ b/packages/backend/src/graphql/generated/graphql.schema.json @@ -638,7 +638,19 @@ "deprecationReason": null }, { - "name": "liquidityThreshold", + "name": "liquidityThresholdHigh", + "description": "A webhook event will notify the Account Servicing Entity if liquidity is higher than this value.", + "args": [], + "type": { + "kind": "SCALAR", + "name": "UInt64", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "liquidityThresholdLow", "description": "A webhook event will notify the Account Servicing Entity if liquidity falls below this value.", "args": [], "type": { @@ -1063,7 +1075,19 @@ "deprecationReason": null }, { - "name": "liquidityThreshold", + "name": "liquidityThresholdHigh", + "description": "A webhook event will notify the Account Servicing Entity if liquidity is higher than this value.", + "type": { + "kind": "SCALAR", + "name": "UInt64", + "ofType": null + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "liquidityThresholdLow", "description": "A webhook event will notify the Account Servicing Entity if liquidity falls below this value.", "type": { "kind": "SCALAR", @@ -1730,7 +1754,19 @@ "deprecationReason": null }, { - "name": "liquidityThreshold", + "name": "liquidityThresholdHigh", + "description": "A webhook event will notify the Account Servicing Entity if peer liqudity is higher than this value.", + "type": { + "kind": "SCALAR", + "name": "UInt64", + "ofType": null + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "liquidityThresholdLow", "description": "A webhook event will notify the Account Servicing Entity if peer liquidity falls below this value.", "type": { "kind": "SCALAR", @@ -5936,7 +5972,19 @@ "deprecationReason": null }, { - "name": "liquidityThreshold", + "name": "liquidityThresholdHigh", + "description": "A webhook event will notify the Account Servicing Entity if liquidity is higher than this value.", + "args": [], + "type": { + "kind": "SCALAR", + "name": "UInt64", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "liquidityThresholdLow", "description": "A webhook event will notify the Account Servicing Entity if liquidity falls below this value.", "args": [], "type": { @@ -7623,7 +7671,19 @@ "deprecationReason": null }, { - "name": "liquidityThreshold", + "name": "liquidityThresholdHigh", + "description": "A webhook event will notify the Account Servicing Entity if liquidity is higher than this new value.", + "type": { + "kind": "SCALAR", + "name": "UInt64", + "ofType": null + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "liquidityThresholdLow", "description": "A webhook event will notify the Account Servicing Entity if liquidity falls below this new value.", "type": { "kind": "SCALAR", @@ -7741,7 +7801,19 @@ "deprecationReason": null }, { - "name": "liquidityThreshold", + "name": "liquidityThresholdHigh", + "description": "A webhook event will notify the Account Servicing Entity if peer liquidity is higher than this new value.", + "type": { + "kind": "SCALAR", + "name": "UInt64", + "ofType": null + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "liquidityThresholdLow", "description": "A webhook event will notify the Account Servicing Entity if peer liquidity falls below this new value.", "type": { "kind": "SCALAR", diff --git a/packages/backend/src/graphql/generated/graphql.ts b/packages/backend/src/graphql/generated/graphql.ts index 131de7eb44..6d720b6e38 100644 --- a/packages/backend/src/graphql/generated/graphql.ts +++ b/packages/backend/src/graphql/generated/graphql.ts @@ -112,8 +112,10 @@ export type Asset = Model & { id: Scalars['ID']['output']; /** Available liquidity */ liquidity?: Maybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this value. */ + liquidityThresholdHigh?: Maybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this value. */ - liquidityThreshold?: Maybe; + liquidityThresholdLow?: Maybe; /** The receiving fee structure for the asset. */ receivingFee?: Maybe; /** Difference in order of magnitude between the standard unit of an asset and its corresponding fractional unit. */ @@ -191,8 +193,10 @@ export type CreateAssetInput = { code: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** Difference in order of magnitude between the standard unit of an asset and its corresponding fractional unit. */ scale: Scalars['UInt8']['input']; /** Minimum amount of liquidity that can be withdrawn from the asset. */ @@ -299,8 +303,10 @@ export type CreatePeerInput = { idempotencyKey?: InputMaybe; /** Initial amount of liquidity to deposit for the peer. */ initialLiquidity?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if peer liqudity is higher than this value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if peer liquidity falls below this value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** Maximum packet amount that the peer accepts. */ maxPacketAmount?: InputMaybe; /** Internal name of the peer. */ @@ -1085,8 +1091,10 @@ export type Peer = Model & { id: Scalars['ID']['output']; /** Current amount of peer liquidity available. */ liquidity?: Maybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this value. */ + liquidityThresholdHigh?: Maybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this value. */ - liquidityThreshold?: Maybe; + liquidityThresholdLow?: Maybe; /** Maximum packet amount that the peer accepts. */ maxPacketAmount?: Maybe; /** Public name for the peer. */ @@ -1376,8 +1384,10 @@ export type UpdateAssetInput = { id: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this new value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this new value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** New minimum amount of liquidity that can be withdrawn from the asset. */ withdrawalThreshold?: InputMaybe; }; @@ -1396,8 +1406,10 @@ export type UpdatePeerInput = { id: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if peer liquidity is higher than this new value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if peer liquidity falls below this new value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** New maximum packet amount that the peer accepts. */ maxPacketAmount?: InputMaybe; /** New public name for the peer. */ @@ -1980,7 +1992,8 @@ export type AssetResolvers, ParentType, ContextType, Partial>; id?: Resolver; liquidity?: Resolver, ParentType, ContextType>; - liquidityThreshold?: Resolver, ParentType, ContextType>; + liquidityThresholdHigh?: Resolver, ParentType, ContextType>; + liquidityThresholdLow?: Resolver, ParentType, ContextType>; receivingFee?: Resolver, ParentType, ContextType>; scale?: Resolver; sendingFee?: Resolver, ParentType, ContextType>; @@ -2253,7 +2266,8 @@ export type PeerResolvers; id?: Resolver; liquidity?: Resolver, ParentType, ContextType>; - liquidityThreshold?: Resolver, ParentType, ContextType>; + liquidityThresholdHigh?: Resolver, ParentType, ContextType>; + liquidityThresholdLow?: Resolver, ParentType, ContextType>; maxPacketAmount?: Resolver, ParentType, ContextType>; name?: Resolver, ParentType, ContextType>; staticIlpAddress?: Resolver; diff --git a/packages/backend/src/graphql/resolvers/asset.ts b/packages/backend/src/graphql/resolvers/asset.ts index 52a18a2b30..74a104e25e 100644 --- a/packages/backend/src/graphql/resolvers/asset.ts +++ b/packages/backend/src/graphql/resolvers/asset.ts @@ -86,7 +86,8 @@ export const updateAsset: MutationResolvers['updateAsset'] = const assetOrError = await assetService.update({ id: args.input.id, withdrawalThreshold: args.input.withdrawalThreshold ?? null, - liquidityThreshold: args.input.liquidityThreshold ?? null + liquidityThresholdLow: args.input.liquidityThresholdLow ?? null, + liquidityThresholdHigh: args.input.liquidityThresholdHigh ?? null, }) if (isAssetError(assetOrError)) { throw new GraphQLError(errorToMessage[assetOrError], { @@ -181,6 +182,7 @@ export const assetToGraphql = (asset: Asset): SchemaAsset => ({ code: asset.code, scale: asset.scale, withdrawalThreshold: asset.withdrawalThreshold, - liquidityThreshold: asset.liquidityThreshold, + liquidityThresholdLow: asset.liquidityThresholdLow, + liquidityThresholdHigh: asset.liquidityThresholdHigh, createdAt: new Date(+asset.createdAt).toISOString() }) diff --git a/packages/backend/src/graphql/resolvers/peer.ts b/packages/backend/src/graphql/resolvers/peer.ts index b2296b7a89..c0965554fe 100644 --- a/packages/backend/src/graphql/resolvers/peer.ts +++ b/packages/backend/src/graphql/resolvers/peer.ts @@ -125,6 +125,7 @@ export const peerToGraphql = (peer: Peer): SchemaPeer => ({ asset: assetToGraphql(peer.asset), staticIlpAddress: peer.staticIlpAddress, name: peer.name, - liquidityThreshold: peer.liquidityThreshold, + liquidityThresholdLow: peer.liquidityThresholdLow, + liquidityThresholdHigh: peer.liquidityThresholdHigh, createdAt: new Date(+peer.createdAt).toISOString() }) diff --git a/packages/backend/src/graphql/schema.graphql b/packages/backend/src/graphql/schema.graphql index b6a57d5523..377119a48a 100644 --- a/packages/backend/src/graphql/schema.graphql +++ b/packages/backend/src/graphql/schema.graphql @@ -332,7 +332,9 @@ input CreateAssetInput { "Minimum amount of liquidity that can be withdrawn from the asset." withdrawalThreshold: UInt64 "A webhook event will notify the Account Servicing Entity if liquidity falls below this value." - liquidityThreshold: UInt64 + liquidityThresholdLow: UInt64 + "A webhook event will notify the Account Servicing Entity if liquidity is higher than this value." + liquidityThresholdHigh: UInt64 "Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency)." idempotencyKey: String } @@ -343,7 +345,9 @@ input UpdateAssetInput { "New minimum amount of liquidity that can be withdrawn from the asset." withdrawalThreshold: UInt64 "A webhook event will notify the Account Servicing Entity if liquidity falls below this new value." - liquidityThreshold: UInt64 + liquidityThresholdLow: UInt64 + "A webhook event will notify the Account Servicing Entity if liquidity is higher than this new value." + liquidityThresholdHigh: UInt64 "Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency)." idempotencyKey: String } @@ -381,7 +385,9 @@ input CreatePeerInput { "Internal name of the peer." name: String "A webhook event will notify the Account Servicing Entity if peer liquidity falls below this value." - liquidityThreshold: UInt64 + liquidityThresholdLow: UInt64 + "A webhook event will notify the Account Servicing Entity if peer liqudity is higher than this value." + liquidityThresholdHigh: UInt64 "Initial amount of liquidity to deposit for the peer." initialLiquidity: UInt64 "Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency)." @@ -417,7 +423,9 @@ input UpdatePeerInput { "New public name for the peer." name: String "A webhook event will notify the Account Servicing Entity if peer liquidity falls below this new value." - liquidityThreshold: UInt64 + liquidityThresholdLow: UInt64 + "A webhook event will notify the Account Servicing Entity if peer liquidity is higher than this new value." + liquidityThresholdHigh: UInt64 "Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency)." idempotencyKey: String } @@ -594,7 +602,9 @@ type Asset implements Model { "Minimum amount of liquidity that can be withdrawn from the asset." withdrawalThreshold: UInt64 "A webhook event will notify the Account Servicing Entity if liquidity falls below this value." - liquidityThreshold: UInt64 + liquidityThresholdLow: UInt64 + "A webhook event will notify the Account Servicing Entity if liquidity is higher than this value." + liquidityThresholdHigh: UInt64 "The receiving fee structure for the asset." receivingFee: Fee "The sending fee structure for the asset." @@ -664,7 +674,9 @@ type Peer implements Model { "Public name for the peer." name: String "A webhook event will notify the Account Servicing Entity if liquidity falls below this value." - liquidityThreshold: UInt64 + liquidityThresholdLow: UInt64 + "A webhook event will notify the Account Servicing Entity if liquidity is higher than this value." + liquidityThresholdHigh: UInt64 "Current amount of peer liquidity available." liquidity: UInt64 "The date and time when the peer was created." diff --git a/packages/backend/src/payment-method/ilp/peer/model.ts b/packages/backend/src/payment-method/ilp/peer/model.ts index e22619e867..ceb524f87c 100644 --- a/packages/backend/src/payment-method/ilp/peer/model.ts +++ b/packages/backend/src/payment-method/ilp/peer/model.ts @@ -34,7 +34,8 @@ export class Peer } } - public readonly liquidityThreshold!: bigint | null + public readonly liquidityThresholdLow!: bigint | null + public readonly liquidityThresholdHigh!: bigint | null public assetId!: string public asset!: Asset @@ -53,25 +54,36 @@ export class Peer public name?: string - public async onDebit({ balance }: OnDebitOptions): Promise { - if (this.liquidityThreshold !== null) { - if (balance <= this.liquidityThreshold) { - await PeerEvent.query().insert({ - peerId: this.id, - type: PeerEventType.LiquidityLow, - data: { - id: this.id, - asset: { - id: this.asset.id, - code: this.asset.code, - scale: this.asset.scale - }, - liquidityThreshold: this.liquidityThreshold, - balance - } - }) - } + private async checkAndInsertEvent(balance: bigint, threshold: bigint | null, eventType: PeerEventType) { + if (threshold === null) { + return + } + + const isThresholdCrossed = (eventType === PeerEventType.LiquidityLow && balance <= threshold) || (eventType === PeerEventType.LiquidityHigh && balance >= threshold) + + if (isThresholdCrossed) { + await PeerEvent.query().insert({ + assetId: this.id, + type: eventType, + data: { + id: this.id, + asset: { + id: this.asset.id, + code: this.asset.code, + scale: this.asset.scale + }, + liquidityThreshold: threshold, + balance + } + }) } + } + + public async onDebit({ balance }: OnDebitOptions): Promise { + await Promise.all([ + this.checkAndInsertEvent(balance, this.liquidityThresholdLow, PeerEventType.LiquidityLow), + this.checkAndInsertEvent(balance, this.liquidityThresholdHigh, PeerEventType.LiquidityHigh) + ]) return this } @@ -101,7 +113,8 @@ export class Peer } export enum PeerEventType { - LiquidityLow = 'peer.liquidity_low' + LiquidityLow = 'peer.liquidity_low', + LiquidityHigh = 'peer.liquidity_high' } export type PeerEventData = { diff --git a/packages/backend/src/payment-method/ilp/peer/service.ts b/packages/backend/src/payment-method/ilp/peer/service.ts index be64dcc520..1d21b0deee 100644 --- a/packages/backend/src/payment-method/ilp/peer/service.ts +++ b/packages/backend/src/payment-method/ilp/peer/service.ts @@ -38,7 +38,8 @@ export type Options = { maxPacketAmount?: bigint staticIlpAddress: string name?: string - liquidityThreshold?: bigint + liquidityThresholdLow?: bigint + liquidityThresholdHigh?: bigint initialLiquidity?: bigint } @@ -138,7 +139,8 @@ async function createPeer( maxPacketAmount: options.maxPacketAmount, staticIlpAddress: options.staticIlpAddress, name: options.name, - liquidityThreshold: options.liquidityThreshold + liquidityThresholdLow: options.liquidityThresholdLow, + liquidityThresholdHigh: options.liquidityThresholdHigh, }) .withGraphFetched('asset') diff --git a/packages/backend/src/tests/peer.ts b/packages/backend/src/tests/peer.ts index 4e323af4cc..42d1735007 100644 --- a/packages/backend/src/tests/peer.ts +++ b/packages/backend/src/tests/peer.ts @@ -30,8 +30,8 @@ export async function createPeer( if (options.maxPacketAmount) { peerOptions.maxPacketAmount = options.maxPacketAmount } - if (options.liquidityThreshold) { - peerOptions.liquidityThreshold = options.liquidityThreshold + if (options.liquidityThresholdLow) { + peerOptions.liquidityThresholdLow = options.liquidityThresholdLow } const peerService = await deps.use('peerService') const peer = await peerService.create(peerOptions) diff --git a/packages/frontend/app/generated/graphql.ts b/packages/frontend/app/generated/graphql.ts index 2d35119c43..7c85b35f2b 100644 --- a/packages/frontend/app/generated/graphql.ts +++ b/packages/frontend/app/generated/graphql.ts @@ -112,8 +112,10 @@ export type Asset = Model & { id: Scalars['ID']['output']; /** Available liquidity */ liquidity?: Maybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this value. */ + liquidityThresholdHigh?: Maybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this value. */ - liquidityThreshold?: Maybe; + liquidityThresholdLow?: Maybe; /** The receiving fee structure for the asset. */ receivingFee?: Maybe; /** Difference in order of magnitude between the standard unit of an asset and its corresponding fractional unit. */ @@ -191,8 +193,10 @@ export type CreateAssetInput = { code: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** Difference in order of magnitude between the standard unit of an asset and its corresponding fractional unit. */ scale: Scalars['UInt8']['input']; /** Minimum amount of liquidity that can be withdrawn from the asset. */ @@ -299,8 +303,10 @@ export type CreatePeerInput = { idempotencyKey?: InputMaybe; /** Initial amount of liquidity to deposit for the peer. */ initialLiquidity?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if peer liqudity is higher than this value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if peer liquidity falls below this value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** Maximum packet amount that the peer accepts. */ maxPacketAmount?: InputMaybe; /** Internal name of the peer. */ @@ -1085,8 +1091,10 @@ export type Peer = Model & { id: Scalars['ID']['output']; /** Current amount of peer liquidity available. */ liquidity?: Maybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this value. */ + liquidityThresholdHigh?: Maybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this value. */ - liquidityThreshold?: Maybe; + liquidityThresholdLow?: Maybe; /** Maximum packet amount that the peer accepts. */ maxPacketAmount?: Maybe; /** Public name for the peer. */ @@ -1376,8 +1384,10 @@ export type UpdateAssetInput = { id: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this new value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this new value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** New minimum amount of liquidity that can be withdrawn from the asset. */ withdrawalThreshold?: InputMaybe; }; @@ -1396,8 +1406,10 @@ export type UpdatePeerInput = { id: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if peer liquidity is higher than this new value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if peer liquidity falls below this new value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** New maximum packet amount that the peer accepts. */ maxPacketAmount?: InputMaybe; /** New public name for the peer. */ @@ -1980,7 +1992,8 @@ export type AssetResolvers, ParentType, ContextType, Partial>; id?: Resolver; liquidity?: Resolver, ParentType, ContextType>; - liquidityThreshold?: Resolver, ParentType, ContextType>; + liquidityThresholdHigh?: Resolver, ParentType, ContextType>; + liquidityThresholdLow?: Resolver, ParentType, ContextType>; receivingFee?: Resolver, ParentType, ContextType>; scale?: Resolver; sendingFee?: Resolver, ParentType, ContextType>; @@ -2253,7 +2266,8 @@ export type PeerResolvers; id?: Resolver; liquidity?: Resolver, ParentType, ContextType>; - liquidityThreshold?: Resolver, ParentType, ContextType>; + liquidityThresholdHigh?: Resolver, ParentType, ContextType>; + liquidityThresholdLow?: Resolver, ParentType, ContextType>; maxPacketAmount?: Resolver, ParentType, ContextType>; name?: Resolver, ParentType, ContextType>; staticIlpAddress?: Resolver; diff --git a/packages/mock-account-service-lib/src/generated/graphql.ts b/packages/mock-account-service-lib/src/generated/graphql.ts index 131de7eb44..6d720b6e38 100644 --- a/packages/mock-account-service-lib/src/generated/graphql.ts +++ b/packages/mock-account-service-lib/src/generated/graphql.ts @@ -112,8 +112,10 @@ export type Asset = Model & { id: Scalars['ID']['output']; /** Available liquidity */ liquidity?: Maybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this value. */ + liquidityThresholdHigh?: Maybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this value. */ - liquidityThreshold?: Maybe; + liquidityThresholdLow?: Maybe; /** The receiving fee structure for the asset. */ receivingFee?: Maybe; /** Difference in order of magnitude between the standard unit of an asset and its corresponding fractional unit. */ @@ -191,8 +193,10 @@ export type CreateAssetInput = { code: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** Difference in order of magnitude between the standard unit of an asset and its corresponding fractional unit. */ scale: Scalars['UInt8']['input']; /** Minimum amount of liquidity that can be withdrawn from the asset. */ @@ -299,8 +303,10 @@ export type CreatePeerInput = { idempotencyKey?: InputMaybe; /** Initial amount of liquidity to deposit for the peer. */ initialLiquidity?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if peer liqudity is higher than this value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if peer liquidity falls below this value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** Maximum packet amount that the peer accepts. */ maxPacketAmount?: InputMaybe; /** Internal name of the peer. */ @@ -1085,8 +1091,10 @@ export type Peer = Model & { id: Scalars['ID']['output']; /** Current amount of peer liquidity available. */ liquidity?: Maybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this value. */ + liquidityThresholdHigh?: Maybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this value. */ - liquidityThreshold?: Maybe; + liquidityThresholdLow?: Maybe; /** Maximum packet amount that the peer accepts. */ maxPacketAmount?: Maybe; /** Public name for the peer. */ @@ -1376,8 +1384,10 @@ export type UpdateAssetInput = { id: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this new value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this new value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** New minimum amount of liquidity that can be withdrawn from the asset. */ withdrawalThreshold?: InputMaybe; }; @@ -1396,8 +1406,10 @@ export type UpdatePeerInput = { id: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if peer liquidity is higher than this new value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if peer liquidity falls below this new value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** New maximum packet amount that the peer accepts. */ maxPacketAmount?: InputMaybe; /** New public name for the peer. */ @@ -1980,7 +1992,8 @@ export type AssetResolvers, ParentType, ContextType, Partial>; id?: Resolver; liquidity?: Resolver, ParentType, ContextType>; - liquidityThreshold?: Resolver, ParentType, ContextType>; + liquidityThresholdHigh?: Resolver, ParentType, ContextType>; + liquidityThresholdLow?: Resolver, ParentType, ContextType>; receivingFee?: Resolver, ParentType, ContextType>; scale?: Resolver; sendingFee?: Resolver, ParentType, ContextType>; @@ -2253,7 +2266,8 @@ export type PeerResolvers; id?: Resolver; liquidity?: Resolver, ParentType, ContextType>; - liquidityThreshold?: Resolver, ParentType, ContextType>; + liquidityThresholdHigh?: Resolver, ParentType, ContextType>; + liquidityThresholdLow?: Resolver, ParentType, ContextType>; maxPacketAmount?: Resolver, ParentType, ContextType>; name?: Resolver, ParentType, ContextType>; staticIlpAddress?: Resolver; diff --git a/test/integration/lib/generated/graphql.ts b/test/integration/lib/generated/graphql.ts index 131de7eb44..6d720b6e38 100644 --- a/test/integration/lib/generated/graphql.ts +++ b/test/integration/lib/generated/graphql.ts @@ -112,8 +112,10 @@ export type Asset = Model & { id: Scalars['ID']['output']; /** Available liquidity */ liquidity?: Maybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this value. */ + liquidityThresholdHigh?: Maybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this value. */ - liquidityThreshold?: Maybe; + liquidityThresholdLow?: Maybe; /** The receiving fee structure for the asset. */ receivingFee?: Maybe; /** Difference in order of magnitude between the standard unit of an asset and its corresponding fractional unit. */ @@ -191,8 +193,10 @@ export type CreateAssetInput = { code: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** Difference in order of magnitude between the standard unit of an asset and its corresponding fractional unit. */ scale: Scalars['UInt8']['input']; /** Minimum amount of liquidity that can be withdrawn from the asset. */ @@ -299,8 +303,10 @@ export type CreatePeerInput = { idempotencyKey?: InputMaybe; /** Initial amount of liquidity to deposit for the peer. */ initialLiquidity?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if peer liqudity is higher than this value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if peer liquidity falls below this value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** Maximum packet amount that the peer accepts. */ maxPacketAmount?: InputMaybe; /** Internal name of the peer. */ @@ -1085,8 +1091,10 @@ export type Peer = Model & { id: Scalars['ID']['output']; /** Current amount of peer liquidity available. */ liquidity?: Maybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this value. */ + liquidityThresholdHigh?: Maybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this value. */ - liquidityThreshold?: Maybe; + liquidityThresholdLow?: Maybe; /** Maximum packet amount that the peer accepts. */ maxPacketAmount?: Maybe; /** Public name for the peer. */ @@ -1376,8 +1384,10 @@ export type UpdateAssetInput = { id: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if liquidity is higher than this new value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if liquidity falls below this new value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** New minimum amount of liquidity that can be withdrawn from the asset. */ withdrawalThreshold?: InputMaybe; }; @@ -1396,8 +1406,10 @@ export type UpdatePeerInput = { id: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if peer liquidity is higher than this new value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if peer liquidity falls below this new value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** New maximum packet amount that the peer accepts. */ maxPacketAmount?: InputMaybe; /** New public name for the peer. */ @@ -1980,7 +1992,8 @@ export type AssetResolvers, ParentType, ContextType, Partial>; id?: Resolver; liquidity?: Resolver, ParentType, ContextType>; - liquidityThreshold?: Resolver, ParentType, ContextType>; + liquidityThresholdHigh?: Resolver, ParentType, ContextType>; + liquidityThresholdLow?: Resolver, ParentType, ContextType>; receivingFee?: Resolver, ParentType, ContextType>; scale?: Resolver; sendingFee?: Resolver, ParentType, ContextType>; @@ -2253,7 +2266,8 @@ export type PeerResolvers; id?: Resolver; liquidity?: Resolver, ParentType, ContextType>; - liquidityThreshold?: Resolver, ParentType, ContextType>; + liquidityThresholdHigh?: Resolver, ParentType, ContextType>; + liquidityThresholdLow?: Resolver, ParentType, ContextType>; maxPacketAmount?: Resolver, ParentType, ContextType>; name?: Resolver, ParentType, ContextType>; staticIlpAddress?: Resolver; From 28b4df1c0286d5d733f848b73697d9613a58862a Mon Sep 17 00:00:00 2001 From: golobitch Date: Sun, 3 Nov 2024 23:05:16 +0100 Subject: [PATCH 2/8] test(resolvers): update asset and peer test resolvers to use low liquidity threshold --- .../src/graphql/resolvers/asset.test.ts | 74 +++++++++---------- .../src/graphql/resolvers/peer.test.ts | 25 ++++--- 2 files changed, 50 insertions(+), 49 deletions(-) diff --git a/packages/backend/src/graphql/resolvers/asset.test.ts b/packages/backend/src/graphql/resolvers/asset.test.ts index d174e32a2b..d79c1455ee 100644 --- a/packages/backend/src/graphql/resolvers/asset.test.ts +++ b/packages/backend/src/graphql/resolvers/asset.test.ts @@ -59,26 +59,26 @@ describe('Asset Resolvers', (): void => { describe('Create Asset', (): void => { test.each` - withdrawalThreshold | expectedWithdrawalThreshold | liquidityThreshold | expectedLiquidityThreshold - ${undefined} | ${null} | ${undefined} | ${null} - ${BigInt(0)} | ${'0'} | ${undefined} | ${null} - ${BigInt(5)} | ${'5'} | ${undefined} | ${null} - ${undefined} | ${null} | ${BigInt(0)} | ${'0'} - ${undefined} | ${null} | ${BigInt(5)} | ${'5'} - ${BigInt(0)} | ${'0'} | ${BigInt(0)} | ${'0'} - ${BigInt(5)} | ${'5'} | ${BigInt(5)} | ${'5'} + withdrawalThreshold | expectedWithdrawalThreshold | liquidityThresholdLow | expectedLiquidityThresholdLow + ${undefined} | ${null} | ${undefined} | ${null} + ${BigInt(0)} | ${'0'} | ${undefined} | ${null} + ${BigInt(5)} | ${'5'} | ${undefined} | ${null} + ${undefined} | ${null} | ${BigInt(0)} | ${'0'} + ${undefined} | ${null} | ${BigInt(5)} | ${'5'} + ${BigInt(0)} | ${'0'} | ${BigInt(0)} | ${'0'} + ${BigInt(5)} | ${'5'} | ${BigInt(5)} | ${'5'} `( - 'Can create an asset (withdrawalThreshold: $withdrawalThreshold, liquidityThreshold: $liquidityThreshold)', + 'Can create an asset (withdrawalThreshold: $withdrawalThreshold, liquidityThresholdLow: $liquidityThresholdLow)', async ({ withdrawalThreshold, expectedWithdrawalThreshold, - liquidityThreshold, - expectedLiquidityThreshold + liquidityThresholdLow, + expectedLiquidityThresholdLow }): Promise => { const input: CreateAssetInput = { ...randomAsset(), withdrawalThreshold, - liquidityThreshold + liquidityThresholdLow } const response = await appContainer.apolloClient @@ -92,7 +92,7 @@ describe('Asset Resolvers', (): void => { scale liquidity withdrawalThreshold - liquidityThreshold + liquidityThresholdLow } } } @@ -117,14 +117,14 @@ describe('Asset Resolvers', (): void => { scale: input.scale, liquidity: '0', withdrawalThreshold: expectedWithdrawalThreshold, - liquidityThreshold: expectedLiquidityThreshold + liquidityThresholdLow: expectedLiquidityThresholdLow }) await expect( assetService.get(response.asset.id) ).resolves.toMatchObject({ ...input, withdrawalThreshold: withdrawalThreshold ?? null, - liquidityThreshold: liquidityThreshold ?? null + liquidityThresholdLow: liquidityThresholdLow ?? null }) } ) @@ -219,7 +219,7 @@ describe('Asset Resolvers', (): void => { const asset = await assetService.create({ ...randomAsset(), withdrawalThreshold: BigInt(10), - liquidityThreshold: BigInt(100) + liquidityThresholdLow: BigInt(100) }) assert.ok(!isAssetError(asset)) assert.ok(asset.withdrawalThreshold) @@ -234,7 +234,7 @@ describe('Asset Resolvers', (): void => { scale liquidity withdrawalThreshold - liquidityThreshold + liquidityThresholdLow createdAt } } @@ -258,7 +258,7 @@ describe('Asset Resolvers', (): void => { scale: asset.scale, liquidity: '0', withdrawalThreshold: asset.withdrawalThreshold.toString(), - liquidityThreshold: asset.liquidityThreshold?.toString(), + liquidityThresholdLow: asset.liquidityThresholdLow?.toString(), createdAt: new Date(+asset.createdAt).toISOString() }) @@ -275,7 +275,7 @@ describe('Asset Resolvers', (): void => { scale: asset.scale, liquidity: '100', withdrawalThreshold: asset.withdrawalThreshold.toString(), - liquidityThreshold: asset.liquidityThreshold?.toString(), + liquidityThresholdLow: asset.liquidityThresholdLow?.toString(), createdAt: new Date(+asset.createdAt).toISOString() }) }) @@ -406,7 +406,7 @@ describe('Asset Resolvers', (): void => { assetService.create({ ...randomAsset(), withdrawalThreshold: BigInt(10), - liquidityThreshold: BigInt(100) + liquidityThresholdLow: BigInt(100) }) as Promise, pagedQuery: 'assets' }) @@ -417,7 +417,7 @@ describe('Asset Resolvers', (): void => { const asset = await assetService.create({ ...randomAsset(), withdrawalThreshold: BigInt(10), - liquidityThreshold: BigInt(100) + liquidityThresholdLow: BigInt(100) }) assert.ok(!isAssetError(asset)) assets.push(asset) @@ -434,7 +434,7 @@ describe('Asset Resolvers', (): void => { code scale withdrawalThreshold - liquidityThreshold + liquidityThresholdLow } cursor } @@ -453,7 +453,7 @@ describe('Asset Resolvers', (): void => { query.edges.forEach((edge, idx) => { const asset = assets[idx] assert.ok(asset.withdrawalThreshold) - assert.ok(asset.liquidityThreshold) + assert.ok(asset.liquidityThresholdLow) expect(edge.cursor).toEqual(asset.id) expect(edge.node).toEqual({ __typename: 'Asset', @@ -461,7 +461,7 @@ describe('Asset Resolvers', (): void => { code: asset.code, scale: asset.scale, withdrawalThreshold: asset.withdrawalThreshold.toString(), - liquidityThreshold: asset.liquidityThreshold.toString() + liquidityThresholdLow: asset.liquidityThresholdLow.toString() }) }) }) @@ -540,7 +540,7 @@ describe('Asset Resolvers', (): void => { describe('updateAsset', (): void => { describe.each` - withdrawalThreshold | liquidityThreshold + withdrawalThreshold | liquidityThresholdLow ${null} | ${null} ${BigInt(0)} | ${null} ${BigInt(5)} | ${null} @@ -549,21 +549,21 @@ describe('Asset Resolvers', (): void => { ${BigInt(0)} | ${BigInt(0)} ${BigInt(5)} | ${BigInt(5)} `( - 'from withdrawalThreshold: $withdrawalThreshold and liquidityThreshold: $liquidityThreshold', - ({ withdrawalThreshold, liquidityThreshold }): void => { + 'from withdrawalThreshold: $withdrawalThreshold and liquidityThresholdLow: $liquidityThresholdLow', + ({ withdrawalThreshold, liquidityThresholdLow }): void => { let asset: AssetModel beforeEach(async (): Promise => { asset = (await assetService.create({ ...randomAsset(), withdrawalThreshold, - liquidityThreshold + liquidityThresholdLow })) as AssetModel assert.ok(!isAssetError(asset)) }) test.each` - withdrawalThreshold | liquidityThreshold + withdrawalThreshold | liquidityThresholdLow ${null} | ${null} ${BigInt(0)} | ${null} ${BigInt(5)} | ${null} @@ -572,7 +572,7 @@ describe('Asset Resolvers', (): void => { ${BigInt(0)} | ${BigInt(0)} ${BigInt(5)} | ${BigInt(5)} `( - 'to withdrawalThreshold: $withdrawalThreshold and liquidityThreshold: $liquidityThreshold', + 'to withdrawalThreshold: $withdrawalThreshold and liquidityThresholdLow: $liquidityThresholdLow', async ({ withdrawalThreshold }): Promise => { const response = await appContainer.apolloClient .mutate({ @@ -584,7 +584,7 @@ describe('Asset Resolvers', (): void => { code scale withdrawalThreshold - liquidityThreshold + liquidityThresholdLow } } } @@ -593,7 +593,7 @@ describe('Asset Resolvers', (): void => { input: { id: asset.id, withdrawalThreshold, - liquidityThreshold + liquidityThresholdLow } } }) @@ -614,14 +614,14 @@ describe('Asset Resolvers', (): void => { withdrawalThreshold === null ? null : withdrawalThreshold.toString(), - liquidityThreshold: - liquidityThreshold === null + liquidityThresholdLow: + liquidityThresholdLow === null ? null - : liquidityThreshold.toString() + : liquidityThresholdLow.toString() }) await expect(assetService.get(asset.id)).resolves.toMatchObject({ withdrawalThreshold, - liquidityThreshold + liquidityThresholdLow }) } ) @@ -646,7 +646,7 @@ describe('Asset Resolvers', (): void => { input: { id: uuid(), withdrawalThreshold: BigInt(10), - liquidityThreshold: BigInt(100) + liquidityThresholdLow: BigInt(100) } } }) diff --git a/packages/backend/src/graphql/resolvers/peer.test.ts b/packages/backend/src/graphql/resolvers/peer.test.ts index 8fc24012d2..b564a6b1a6 100644 --- a/packages/backend/src/graphql/resolvers/peer.test.ts +++ b/packages/backend/src/graphql/resolvers/peer.test.ts @@ -52,7 +52,8 @@ describe('Peer Resolvers', (): void => { maxPacketAmount: BigInt(100), staticIlpAddress: 'test.' + uuid(), name: faker.person.fullName(), - liquidityThreshold: BigInt(100), + liquidityThresholdLow: BigInt(100), + liquidityThresholdHigh: BigInt(2000), initialLiquidity: BigInt(100) }) @@ -100,7 +101,7 @@ describe('Peer Resolvers', (): void => { staticIlpAddress liquidity name - liquidityThreshold + liquidityThresholdLow } } } @@ -137,7 +138,7 @@ describe('Peer Resolvers', (): void => { staticIlpAddress: peer.staticIlpAddress, liquidity: peer.initialLiquidity?.toString(), name: peer.name, - liquidityThreshold: peer.liquidityThreshold?.toString() + liquidityThresholdLow: peer.liquidityThresholdLow?.toString() }) delete peer.http.incoming await expect(peerService.get(response.peer.id)).resolves.toMatchObject({ @@ -267,7 +268,7 @@ describe('Peer Resolvers', (): void => { staticIlpAddress liquidity name - liquidityThreshold + liquidityThresholdLow } } `, @@ -302,7 +303,7 @@ describe('Peer Resolvers', (): void => { maxPacketAmount: peer.maxPacketAmount?.toString(), liquidity: '0', name: peer.name, - liquidityThreshold: '100' + liquidityThresholdLow: '100' }) await accountingService.createDeposit({ @@ -330,7 +331,7 @@ describe('Peer Resolvers', (): void => { maxPacketAmount: peer.maxPacketAmount?.toString(), liquidity: '100', name: peer.name, - liquidityThreshold: '100' + liquidityThresholdLow: '100' }) }) @@ -409,7 +410,7 @@ describe('Peer Resolvers', (): void => { } staticIlpAddress name - liquidityThreshold + liquidityThresholdLow } cursor } @@ -447,7 +448,7 @@ describe('Peer Resolvers', (): void => { staticIlpAddress: peer.staticIlpAddress, maxPacketAmount: peer.maxPacketAmount?.toString(), name: peer.name, - liquidityThreshold: '100' + liquidityThresholdLow: '100' }) }) }) @@ -475,7 +476,7 @@ describe('Peer Resolvers', (): void => { }, staticIlpAddress: 'g.rafiki.' + peer.id, name: faker.person.fullName(), - liquidityThreshold: BigInt(200) + liquidityThresholdLow: BigInt(200) } assert.ok(updateOptions.http) const response = await appContainer.apolloClient @@ -494,7 +495,7 @@ describe('Peer Resolvers', (): void => { } staticIlpAddress name - liquidityThreshold + liquidityThresholdLow } } } @@ -523,7 +524,7 @@ describe('Peer Resolvers', (): void => { }, staticIlpAddress: updateOptions.staticIlpAddress, name: updateOptions.name, - liquidityThreshold: '200' + liquidityThresholdLow: '200' }) await expect(peerService.get(peer.id)).resolves.toMatchObject({ asset: peer.asset, @@ -533,7 +534,7 @@ describe('Peer Resolvers', (): void => { maxPacketAmount: BigInt(updateOptions.maxPacketAmount), staticIlpAddress: updateOptions.staticIlpAddress, name: updateOptions.name, - liquidityThreshold: BigInt(200) + liquidityThresholdLow: BigInt(200) }) }) From b8fceedf6ad02d93558fbf02da452c603e1eb907 Mon Sep 17 00:00:00 2001 From: golobitch Date: Tue, 5 Nov 2024 23:19:20 +0100 Subject: [PATCH 3/8] feat(localenv): rename liquidityThreshold to liquidityThresholdLow --- localenv/cloud-nine-wallet/seed.yml | 10 +++++----- localenv/happy-life-bank/seed.yml | 10 +++++----- .../mock-account-servicing-entity/seed.example.yml | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/localenv/cloud-nine-wallet/seed.yml b/localenv/cloud-nine-wallet/seed.yml index eff7d687df..7335441e8c 100644 --- a/localenv/cloud-nine-wallet/seed.yml +++ b/localenv/cloud-nine-wallet/seed.yml @@ -2,25 +2,25 @@ assets: - code: USD scale: 2 liquidity: 100000000 - liquidityThreshold: 10000000 + liquidityThresholdLow: 10000000 - code: EUR scale: 2 liquidity: 100000000 - liquidityThreshold: 10000000 + liquidityThresholdLow: 10000000 - code: MXN scale: 2 liquidity: 100000000 - liquidityThreshold: 10000000 + liquidityThresholdLow: 10000000 - code: JPY scale: 0 liquidity: 1000000 - liquidityThreshold: 100000 + liquidityThresholdLow: 100000 peeringAsset: 'USD' peers: - initialLiquidity: '10000000' peerUrl: http://happy-life-bank-backend:3002 peerIlpAddress: test.happy-life-bank - liquidityThreshold: 1000000 + liquidityThresholdLow: 1000000 accounts: - name: 'Grace Franklin' path: accounts/gfranklin diff --git a/localenv/happy-life-bank/seed.yml b/localenv/happy-life-bank/seed.yml index 1a8e57cff7..cf8f91215d 100644 --- a/localenv/happy-life-bank/seed.yml +++ b/localenv/happy-life-bank/seed.yml @@ -2,25 +2,25 @@ assets: - code: USD scale: 2 liquidity: 10000000000 - liquidityThreshold: 100000000 + liquidityThresholdLow: 100000000 - code: EUR scale: 2 liquidity: 10000000000 - liquidityThreshold: 1000000 + liquidityThresholdLow: 1000000 - code: MXN scale: 2 liquidity: 10000000000 - liquidityThreshold: 10000000 + liquidityThresholdLow: 10000000 - code: JPY scale: 0 liquidity: 1000000000 - liquidityThreshold: 1000000 + liquidityThresholdLow: 1000000 peeringAsset: 'USD' peers: - initialLiquidity: '1000000000000' peerUrl: http://cloud-nine-wallet-backend:3002 peerIlpAddress: test.cloud-nine-wallet - liquidityThreshold: 1000000 + liquidityThresholdLow: 1000000 accounts: - name: 'Philip Fry' path: accounts/pfry diff --git a/localenv/mock-account-servicing-entity/seed.example.yml b/localenv/mock-account-servicing-entity/seed.example.yml index f2c56fc943..4536993eb8 100644 --- a/localenv/mock-account-servicing-entity/seed.example.yml +++ b/localenv/mock-account-servicing-entity/seed.example.yml @@ -2,17 +2,17 @@ assets: - code: USD scale: 2 liquidity: 1000000 - liquidityThreshold: 100000 + liquidityThresholdLow: 100000 - code: JPY scale: 2 liquidity: 10000 - liquidityThreshold: 1000 + liquidityThresholdLow: 1000 peeringAsset: 'USD' peers: - initialLiquidity: '100000' peerUrl: http://peer-backend:3002 peerIlpAddress: test.peer - liquidityThreshold: 10000 + liquidityThresholdLow: 10000 accounts: - name: 'Grace Franklin' path: accounts/gfranklin From a8677a8c0d08b03f5fbd378a84810b655d0f4e9a Mon Sep 17 00:00:00 2001 From: golobitch Date: Tue, 5 Nov 2024 23:19:57 +0100 Subject: [PATCH 4/8] test(liquidity): peers and asset low and high --- packages/backend/src/asset/model.test.ts | 53 +++++++++- packages/backend/src/asset/service.test.ts | 87 +++++++++------ .../src/graphql/resolvers/asset.test.ts | 100 +++++++++++------- .../src/graphql/resolvers/peer.test.ts | 25 +++-- .../ilp/auto-peering/service.ts | 6 +- packages/backend/src/tests/peer.ts | 4 + .../src/requesters.ts | 31 ++++-- packages/mock-account-service-lib/src/seed.ts | 7 +- .../mock-account-service-lib/src/types.ts | 6 +- .../testenv/cloud-nine-wallet/seed.yml | 15 ++- .../testenv/happy-life-bank/seed.yml | 15 ++- 11 files changed, 238 insertions(+), 111 deletions(-) diff --git a/packages/backend/src/asset/model.test.ts b/packages/backend/src/asset/model.test.ts index 461fb043e5..e86c59ffcd 100644 --- a/packages/backend/src/asset/model.test.ts +++ b/packages/backend/src/asset/model.test.ts @@ -38,20 +38,50 @@ describe('Models', (): void => { beforeEach(async (): Promise => { const options = { ...randomAsset(), - liquidityThreshold: BigInt(100) + liquidityThresholdLow: BigInt(100), + liquidityThresholdHigh: BigInt(500) } const assetOrError = await assetService.create(options) if (!isAssetError(assetOrError)) { asset = assetOrError } }) + + test.each` + balance + ${BigInt(500)} + ${BigInt(1000)} + `( + 'creates webhook event if balance=$balance >= liquidityThresholdHigh', + async ({ balance }): Promise => { + await asset.onDebit({ balance }) + const event = ( + await AssetEvent.query(knex).where('type', AssetEventType.LiquidityHigh) + )[0] + + expect(event).toMatchObject({ + type: AssetEventType.LiquidityHigh, + data: { + id: asset.id, + asset: { + id: asset.id, + code: asset.code, + scale: asset.scale + }, + liquidityThreshold: asset.liquidityThresholdHigh?.toString(), + balance: balance.toString() + } + }) + } + ) + test.each` balance ${BigInt(50)} ${BigInt(99)} ${BigInt(100)} `( - 'creates webhook event if balance=$balance <= liquidityThreshold', + 'creates webhook event if balance=$balance <= liquidityThresholdLow', async ({ balance }): Promise => { await asset.onDebit({ balance }) const event = ( @@ -69,18 +99,33 @@ describe('Models', (): void => { code: asset.code, scale: asset.scale }, - liquidityThreshold: asset.liquidityThreshold?.toString(), + liquidityThreshold: asset.liquidityThresholdLow?.toString(), balance: balance.toString() } }) } ) - test('does not create webhook event if balance > liquidityThreshold', async (): Promise => { + test('does not create webhook event if balance > liquidityThresholdLow', async (): Promise => { await asset.onDebit({ balance: BigInt(110) }) await expect( AssetEvent.query(knex).where('type', AssetEventType.LiquidityLow) ).resolves.toEqual([]) }) + + + test.each` + balance + ${BigInt(200)} + ${BigInt(499)} + `( + 'does not create webhook event if balance=$balance < liquidityThresholdLow', + async ({ balance }): Promise => { + await asset.onDebit({ balance }) + await expect( + AssetEvent.query(knex).where('type', AssetEventType.LiquidityHigh) + ).resolves.toEqual([]) + } + ) }) }) diff --git a/packages/backend/src/asset/service.test.ts b/packages/backend/src/asset/service.test.ts index ec30e34407..aedfa7b2bc 100644 --- a/packages/backend/src/asset/service.test.ts +++ b/packages/backend/src/asset/service.test.ts @@ -46,18 +46,23 @@ describe('Asset Service', (): void => { describe('create', (): void => { test.each` - withdrawalThreshold | liquidityThreshold - ${undefined} | ${undefined} - ${BigInt(5)} | ${undefined} - ${undefined} | ${BigInt(5)} - ${BigInt(5)} | ${BigInt(5)} + withdrawalThreshold | liquidityThresholdLow | liquidityThresholdHigh + ${undefined} | ${undefined} | ${undefined} + ${undefined} | ${undefined} | ${BigInt(500)} + ${undefined} | ${BigInt(5)} | ${undefined} + ${undefined} | ${BigInt(5)} | ${BigInt(500)} + ${BigInt(5)} | ${undefined} | ${undefined} + ${BigInt(5)} | ${undefined} | ${BigInt(500)} + ${BigInt(5)} | ${BigInt(5)} | ${undefined} + ${BigInt(5)} | ${BigInt(5)} | ${BigInt(500)} `( 'Asset can be created and fetched', - async ({ withdrawalThreshold, liquidityThreshold }): Promise => { + async ({ withdrawalThreshold, liquidityThresholdLow, liquidityThresholdHigh }): Promise => { const options = { ...randomAsset(), withdrawalThreshold, - liquidityThreshold + liquidityThresholdLow, + liquidityThresholdHigh, } const asset = await assetService.create(options) assert.ok(!isAssetError(asset)) @@ -66,7 +71,8 @@ describe('Asset Service', (): void => { id: asset.id, ledger: asset.ledger, withdrawalThreshold: withdrawalThreshold || null, - liquidityThreshold: liquidityThreshold || null + liquidityThresholdLow: liquidityThresholdLow || null, + liquidityThresholdHigh: liquidityThresholdHigh || null, }) await expect(assetService.get(asset.id)).resolves.toEqual(asset) } @@ -144,24 +150,30 @@ describe('Asset Service', (): void => { describe('update', (): void => { describe.each` - withdrawalThreshold | liquidityThreshold - ${null} | ${null} - ${BigInt(0)} | ${null} - ${BigInt(5)} | ${null} - ${null} | ${BigInt(0)} - ${null} | ${BigInt(5)} - ${BigInt(0)} | ${BigInt(0)} - ${BigInt(5)} | ${BigInt(5)} + withdrawalThreshold | liquidityThresholdLow | liquidityThresholdHigh + ${null} | ${null} | ${null} + ${null} | ${null} | ${BigInt(500)} + ${null} | ${BigInt(5)} | ${null} + ${null} | ${BigInt(5)} | ${BigInt(500)} + ${BigInt(0)} | ${null} | ${null} + ${BigInt(0)} | ${null} | ${BigInt(500)} + ${BigInt(0)} | ${BigInt(5)} | ${null} + ${BigInt(0)} | ${BigInt(5)} | ${BigInt(500)} + ${BigInt(5)} | ${null} | ${null} + ${BigInt(5)} | ${null} | ${BigInt(500)} + ${BigInt(5)} | ${BigInt(5)} | ${null} + ${BigInt(5)} | ${BigInt(5)} | ${BigInt(500)} `( - 'Asset threshold can be updated from withdrawalThreshold: $withdrawalThreshold, liquidityThreshold: $liquidityThreshold', - ({ withdrawalThreshold, liquidityThreshold }): void => { + 'Asset threshold can be updated from withdrawalThreshold: $withdrawalThreshold, liquidityThresholdLow: $liquidityThresholdLow, liquidityThresholdHigh: $liquidityThresholdHigh', + ({ withdrawalThreshold, liquidityThresholdLow, liquidityThresholdHigh }): void => { let assetId: string beforeEach(async (): Promise => { const asset = await assetService.create({ ...randomAsset(), withdrawalThreshold, - liquidityThreshold + liquidityThresholdLow, + liquidityThresholdHigh }) assert.ok(!isAssetError(asset)) expect(asset.withdrawalThreshold).toEqual(withdrawalThreshold) @@ -169,28 +181,36 @@ describe('Asset Service', (): void => { }) test.each` - withdrawalThreshold | liquidityThreshold - ${null} | ${null} - ${BigInt(0)} | ${null} - ${BigInt(5)} | ${null} - ${null} | ${BigInt(0)} - ${null} | ${BigInt(5)} - ${BigInt(0)} | ${BigInt(0)} - ${BigInt(5)} | ${BigInt(5)} + withdrawalThreshold | liquidityThresholdLow | liquidityThresholdHigh + ${null} | ${null} | ${null} + ${null} | ${null} | ${BigInt(500)} + ${null} | ${BigInt(5)} | ${null} + ${null} | ${BigInt(5)} | ${BigInt(500)} + ${BigInt(0)} | ${null} | ${null} + ${BigInt(0)} | ${null} | ${BigInt(500)} + ${BigInt(0)} | ${BigInt(5)} | ${null} + ${BigInt(0)} | ${BigInt(5)} | ${BigInt(500)} + ${BigInt(5)} | ${null} | ${null} + ${BigInt(5)} | ${null} | ${BigInt(500)} + ${BigInt(5)} | ${BigInt(5)} | ${null} + ${BigInt(5)} | ${BigInt(5)} | ${BigInt(500)} `( - 'to withdrawalThreshold: $withdrawalThreshold, liquidityThreshold: $liquidityThreshold', + 'to withdrawalThreshold: $withdrawalThreshold, liquidityThresholdLow: $liquidityThresholdLow, liquidityThresholdHigh: $liquidityThresholdHigh', async ({ withdrawalThreshold, - liquidityThreshold + liquidityThresholdLow, + liquidityThresholdHigh }): Promise => { const asset = await assetService.update({ id: assetId, withdrawalThreshold, - liquidityThreshold + liquidityThresholdLow, + liquidityThresholdHigh }) assert.ok(!isAssetError(asset)) expect(asset.withdrawalThreshold).toEqual(withdrawalThreshold) - expect(asset.liquidityThreshold).toEqual(liquidityThreshold) + expect(asset.liquidityThresholdLow).toEqual(liquidityThresholdLow) + expect(asset.liquidityThresholdHigh).toEqual(liquidityThresholdHigh) await expect(assetService.get(assetId)).resolves.toEqual(asset) } ) @@ -202,7 +222,7 @@ describe('Asset Service', (): void => { assetService.update({ id: uuid(), withdrawalThreshold: BigInt(10), - liquidityThreshold: null + liquidityThresholdLow: null }) ).resolves.toEqual(AssetError.UnknownAsset) }) @@ -303,7 +323,8 @@ describe('Asset Service', (): void => { maxPacketAmount: BigInt(100), staticIlpAddress: 'test.' + uuid(), name: faker.person.fullName(), - liquidityThreshold: BigInt(100) + liquidityThresholdLow: BigInt(100), + liquidityThresholdHigh: BigInt(1000) } const peer = await peerService.create(options) assert.ok(!isPeerError(peer)) diff --git a/packages/backend/src/graphql/resolvers/asset.test.ts b/packages/backend/src/graphql/resolvers/asset.test.ts index d79c1455ee..e0be25c20b 100644 --- a/packages/backend/src/graphql/resolvers/asset.test.ts +++ b/packages/backend/src/graphql/resolvers/asset.test.ts @@ -59,26 +59,29 @@ describe('Asset Resolvers', (): void => { describe('Create Asset', (): void => { test.each` - withdrawalThreshold | expectedWithdrawalThreshold | liquidityThresholdLow | expectedLiquidityThresholdLow - ${undefined} | ${null} | ${undefined} | ${null} - ${BigInt(0)} | ${'0'} | ${undefined} | ${null} - ${BigInt(5)} | ${'5'} | ${undefined} | ${null} - ${undefined} | ${null} | ${BigInt(0)} | ${'0'} - ${undefined} | ${null} | ${BigInt(5)} | ${'5'} - ${BigInt(0)} | ${'0'} | ${BigInt(0)} | ${'0'} - ${BigInt(5)} | ${'5'} | ${BigInt(5)} | ${'5'} + withdrawalThreshold | expectedWithdrawalThreshold | liquidityThresholdLow | expectedLiquidityThresholdLow | liquidityThresholdHigh | expectedLiquidityThresholdHigh + ${undefined} | ${null} | ${undefined} | ${null} | ${undefined} | ${null} + ${BigInt(0)} | ${'0'} | ${undefined} | ${null} | ${undefined} | ${null} + ${BigInt(5)} | ${'5'} | ${undefined} | ${null} | ${undefined} | ${null} + ${undefined} | ${null} | ${BigInt(0)} | ${'0'} | ${BigInt(100)} | ${'100'} + ${undefined} | ${null} | ${BigInt(5)} | ${'5'} | ${BigInt(5000)} | ${'5000'} + ${BigInt(0)} | ${'0'} | ${BigInt(0)} | ${'0'} | ${BigInt(100)} | ${'100'} + ${BigInt(5)} | ${'5'} | ${BigInt(5)} | ${'5'} | ${BigInt(5000)} | ${'5000'} `( - 'Can create an asset (withdrawalThreshold: $withdrawalThreshold, liquidityThresholdLow: $liquidityThresholdLow)', + 'Can create an asset (withdrawalThreshold: $withdrawalThreshold, liquidityThresholdLow: $liquidityThresholdLow, liquidityThresholdHigh: $liquidityThresholdHigh)', async ({ withdrawalThreshold, expectedWithdrawalThreshold, liquidityThresholdLow, - expectedLiquidityThresholdLow + expectedLiquidityThresholdLow, + liquidityThresholdHigh, + expectedLiquidityThresholdHigh }): Promise => { const input: CreateAssetInput = { ...randomAsset(), withdrawalThreshold, - liquidityThresholdLow + liquidityThresholdLow, + liquidityThresholdHigh } const response = await appContainer.apolloClient @@ -93,6 +96,7 @@ describe('Asset Resolvers', (): void => { liquidity withdrawalThreshold liquidityThresholdLow + liquidityThresholdHigh } } } @@ -117,14 +121,16 @@ describe('Asset Resolvers', (): void => { scale: input.scale, liquidity: '0', withdrawalThreshold: expectedWithdrawalThreshold, - liquidityThresholdLow: expectedLiquidityThresholdLow + liquidityThresholdLow: expectedLiquidityThresholdLow, + liquidityThresholdHigh: expectedLiquidityThresholdHigh }) await expect( assetService.get(response.asset.id) ).resolves.toMatchObject({ ...input, withdrawalThreshold: withdrawalThreshold ?? null, - liquidityThresholdLow: liquidityThresholdLow ?? null + liquidityThresholdLow: liquidityThresholdLow ?? null, + liquidityThresholdHigh: liquidityThresholdHigh ?? null }) } ) @@ -235,6 +241,7 @@ describe('Asset Resolvers', (): void => { liquidity withdrawalThreshold liquidityThresholdLow + liquidityThresholdHigh createdAt } } @@ -259,6 +266,7 @@ describe('Asset Resolvers', (): void => { liquidity: '0', withdrawalThreshold: asset.withdrawalThreshold.toString(), liquidityThresholdLow: asset.liquidityThresholdLow?.toString(), + liquidityThresholdHigh: asset.liquidityThresholdHigh?.toString(), createdAt: new Date(+asset.createdAt).toISOString() }) @@ -276,6 +284,7 @@ describe('Asset Resolvers', (): void => { liquidity: '100', withdrawalThreshold: asset.withdrawalThreshold.toString(), liquidityThresholdLow: asset.liquidityThresholdLow?.toString(), + liquidityThresholdHigh: asset.liquidityThresholdHigh?.toString(), createdAt: new Date(+asset.createdAt).toISOString() }) }) @@ -406,7 +415,8 @@ describe('Asset Resolvers', (): void => { assetService.create({ ...randomAsset(), withdrawalThreshold: BigInt(10), - liquidityThresholdLow: BigInt(100) + liquidityThresholdLow: BigInt(100), + liquidityThresholdHigh: BigInt(1000) }) as Promise, pagedQuery: 'assets' }) @@ -417,7 +427,8 @@ describe('Asset Resolvers', (): void => { const asset = await assetService.create({ ...randomAsset(), withdrawalThreshold: BigInt(10), - liquidityThresholdLow: BigInt(100) + liquidityThresholdLow: BigInt(100), + liquidityThresholdHigh: BigInt(1000) }) assert.ok(!isAssetError(asset)) assets.push(asset) @@ -435,6 +446,7 @@ describe('Asset Resolvers', (): void => { scale withdrawalThreshold liquidityThresholdLow + liquidityThresholdHigh } cursor } @@ -454,6 +466,7 @@ describe('Asset Resolvers', (): void => { const asset = assets[idx] assert.ok(asset.withdrawalThreshold) assert.ok(asset.liquidityThresholdLow) + assert.ok(asset.liquidityThresholdHigh) expect(edge.cursor).toEqual(asset.id) expect(edge.node).toEqual({ __typename: 'Asset', @@ -461,7 +474,8 @@ describe('Asset Resolvers', (): void => { code: asset.code, scale: asset.scale, withdrawalThreshold: asset.withdrawalThreshold.toString(), - liquidityThresholdLow: asset.liquidityThresholdLow.toString() + liquidityThresholdLow: asset.liquidityThresholdLow.toString(), + liquidityThresholdHigh: asset.liquidityThresholdHigh.toString() }) }) }) @@ -540,39 +554,40 @@ describe('Asset Resolvers', (): void => { describe('updateAsset', (): void => { describe.each` - withdrawalThreshold | liquidityThresholdLow - ${null} | ${null} - ${BigInt(0)} | ${null} - ${BigInt(5)} | ${null} - ${null} | ${BigInt(0)} - ${null} | ${BigInt(5)} - ${BigInt(0)} | ${BigInt(0)} - ${BigInt(5)} | ${BigInt(5)} + withdrawalThreshold | liquidityThresholdLow | liquidityThresholdHigh + ${null} | ${null} | ${null} + ${BigInt(0)} | ${null} | ${null} + ${BigInt(5)} | ${null} | ${null} + ${null} | ${BigInt(0)} | ${BigInt(1000)} + ${null} | ${BigInt(5)} | ${BigInt(5000)} + ${BigInt(0)} | ${BigInt(0)} | ${BigInt(1000)} + ${BigInt(5)} | ${BigInt(5)} | ${BigInt(5000)} `( - 'from withdrawalThreshold: $withdrawalThreshold and liquidityThresholdLow: $liquidityThresholdLow', - ({ withdrawalThreshold, liquidityThresholdLow }): void => { + 'from withdrawalThreshold: $withdrawalThreshold, liquidityThresholdLow: $liquidityThresholdLow and liquidityThresholdHigh: $liquidityThresholdHigh', + ({ withdrawalThreshold, liquidityThresholdLow, liquidityThresholdHigh }): void => { let asset: AssetModel beforeEach(async (): Promise => { asset = (await assetService.create({ ...randomAsset(), withdrawalThreshold, - liquidityThresholdLow + liquidityThresholdLow, + liquidityThresholdHigh })) as AssetModel assert.ok(!isAssetError(asset)) }) test.each` - withdrawalThreshold | liquidityThresholdLow - ${null} | ${null} - ${BigInt(0)} | ${null} - ${BigInt(5)} | ${null} - ${null} | ${BigInt(0)} - ${null} | ${BigInt(5)} - ${BigInt(0)} | ${BigInt(0)} - ${BigInt(5)} | ${BigInt(5)} + withdrawalThreshold | liquidityThresholdLow | liquidityThresholdHigh + ${null} | ${null} | ${null} + ${BigInt(0)} | ${null} | ${null} + ${BigInt(5)} | ${null} | ${null} + ${null} | ${BigInt(0)} | ${BigInt(1000)} + ${null} | ${BigInt(5)} | ${BigInt(5000)} + ${BigInt(0)} | ${BigInt(0)} | ${BigInt(1000)} + ${BigInt(5)} | ${BigInt(5)} | ${BigInt(5000)} `( - 'to withdrawalThreshold: $withdrawalThreshold and liquidityThresholdLow: $liquidityThresholdLow', + 'to withdrawalThreshold: $withdrawalThreshold, liquidityThresholdLow: $liquidityThresholdLow and liquidityThresholdHigh: $liquidityThresholdHigh', async ({ withdrawalThreshold }): Promise => { const response = await appContainer.apolloClient .mutate({ @@ -585,6 +600,7 @@ describe('Asset Resolvers', (): void => { scale withdrawalThreshold liquidityThresholdLow + liquidityThresholdHigh } } } @@ -593,7 +609,8 @@ describe('Asset Resolvers', (): void => { input: { id: asset.id, withdrawalThreshold, - liquidityThresholdLow + liquidityThresholdLow, + liquidityThresholdHigh } } }) @@ -617,11 +634,16 @@ describe('Asset Resolvers', (): void => { liquidityThresholdLow: liquidityThresholdLow === null ? null - : liquidityThresholdLow.toString() + : liquidityThresholdLow.toString(), + liquidityThresholdHigh: + liquidityThresholdHigh === null + ? null + : liquidityThresholdHigh.toString() }) await expect(assetService.get(asset.id)).resolves.toMatchObject({ withdrawalThreshold, - liquidityThresholdLow + liquidityThresholdLow, + liquidityThresholdHigh }) } ) diff --git a/packages/backend/src/graphql/resolvers/peer.test.ts b/packages/backend/src/graphql/resolvers/peer.test.ts index b564a6b1a6..c74bb4f667 100644 --- a/packages/backend/src/graphql/resolvers/peer.test.ts +++ b/packages/backend/src/graphql/resolvers/peer.test.ts @@ -102,6 +102,7 @@ describe('Peer Resolvers', (): void => { liquidity name liquidityThresholdLow + liquidityThresholdHigh } } } @@ -138,7 +139,8 @@ describe('Peer Resolvers', (): void => { staticIlpAddress: peer.staticIlpAddress, liquidity: peer.initialLiquidity?.toString(), name: peer.name, - liquidityThresholdLow: peer.liquidityThresholdLow?.toString() + liquidityThresholdLow: peer.liquidityThresholdLow?.toString(), + liquidityThresholdHigh: peer.liquidityThresholdHigh?.toString() }) delete peer.http.incoming await expect(peerService.get(response.peer.id)).resolves.toMatchObject({ @@ -269,6 +271,7 @@ describe('Peer Resolvers', (): void => { liquidity name liquidityThresholdLow + liquidityThresholdHigh } } `, @@ -303,7 +306,8 @@ describe('Peer Resolvers', (): void => { maxPacketAmount: peer.maxPacketAmount?.toString(), liquidity: '0', name: peer.name, - liquidityThresholdLow: '100' + liquidityThresholdLow: '100', + liquidityThresholdHigh: '2000' }) await accountingService.createDeposit({ @@ -331,7 +335,8 @@ describe('Peer Resolvers', (): void => { maxPacketAmount: peer.maxPacketAmount?.toString(), liquidity: '100', name: peer.name, - liquidityThresholdLow: '100' + liquidityThresholdLow: '100', + liquidityThresholdHigh: '2000' }) }) @@ -411,6 +416,7 @@ describe('Peer Resolvers', (): void => { staticIlpAddress name liquidityThresholdLow + liquidityThresholdHigh } cursor } @@ -448,7 +454,8 @@ describe('Peer Resolvers', (): void => { staticIlpAddress: peer.staticIlpAddress, maxPacketAmount: peer.maxPacketAmount?.toString(), name: peer.name, - liquidityThresholdLow: '100' + liquidityThresholdLow: '100', + liquidityThresholdHigh: '2000' }) }) }) @@ -476,7 +483,8 @@ describe('Peer Resolvers', (): void => { }, staticIlpAddress: 'g.rafiki.' + peer.id, name: faker.person.fullName(), - liquidityThresholdLow: BigInt(200) + liquidityThresholdLow: BigInt(200), + liquidityThresholdHigh: BigInt(3000) } assert.ok(updateOptions.http) const response = await appContainer.apolloClient @@ -496,6 +504,7 @@ describe('Peer Resolvers', (): void => { staticIlpAddress name liquidityThresholdLow + liquidityThresholdHigh } } } @@ -524,7 +533,8 @@ describe('Peer Resolvers', (): void => { }, staticIlpAddress: updateOptions.staticIlpAddress, name: updateOptions.name, - liquidityThresholdLow: '200' + liquidityThresholdLow: '200', + liquidityThresholdHigh: '3000' }) await expect(peerService.get(peer.id)).resolves.toMatchObject({ asset: peer.asset, @@ -534,7 +544,8 @@ describe('Peer Resolvers', (): void => { maxPacketAmount: BigInt(updateOptions.maxPacketAmount), staticIlpAddress: updateOptions.staticIlpAddress, name: updateOptions.name, - liquidityThresholdLow: BigInt(200) + liquidityThresholdLow: BigInt(200), + liquidityThresholdHigh: BigInt(3000) }) }) diff --git a/packages/backend/src/payment-method/ilp/auto-peering/service.ts b/packages/backend/src/payment-method/ilp/auto-peering/service.ts index 31d1e60ea9..73a2cdcfab 100644 --- a/packages/backend/src/payment-method/ilp/auto-peering/service.ts +++ b/packages/backend/src/payment-method/ilp/auto-peering/service.ts @@ -22,7 +22,8 @@ export interface InitiatePeeringRequestArgs { name?: string maxPacketAmount?: bigint liquidityToDeposit?: bigint - liquidityThreshold?: bigint + liquidityThresholdLow?: bigint + liquidityThresholdHigh?: bigint } export interface PeeringRequestArgs { @@ -112,7 +113,8 @@ async function initiatePeeringRequest( maxPacketAmount: args.maxPacketAmount, name: args.name ?? peeringDetailsOrError.name, assetId: asset.id, - liquidityThreshold: args.liquidityThreshold, + liquidityThresholdLow: args.liquidityThresholdLow, + liquidityThresholdHigh: args.liquidityThresholdHigh, staticIlpAddress: peeringDetailsOrError.staticIlpAddress, http: { incoming: { diff --git a/packages/backend/src/tests/peer.ts b/packages/backend/src/tests/peer.ts index 42d1735007..1c723dfcbb 100644 --- a/packages/backend/src/tests/peer.ts +++ b/packages/backend/src/tests/peer.ts @@ -33,6 +33,10 @@ export async function createPeer( if (options.liquidityThresholdLow) { peerOptions.liquidityThresholdLow = options.liquidityThresholdLow } + if (options.liquidityThresholdHigh) { + peerOptions.liquidityThresholdHigh = options.liquidityThresholdHigh + } + const peerService = await deps.use('peerService') const peer = await peerService.create(peerOptions) if (isPeerError(peer)) { diff --git a/packages/mock-account-service-lib/src/requesters.ts b/packages/mock-account-service-lib/src/requesters.ts index e6edd93bb9..2ae3d5d1f4 100644 --- a/packages/mock-account-service-lib/src/requesters.ts +++ b/packages/mock-account-service-lib/src/requesters.ts @@ -23,7 +23,8 @@ export function createRequesters( createAsset: ( code: string, scale: number, - liquidityThreshold: number + liquidityThresholdLow: number, + liquidityThresholdHigh: number ) => Promise createPeer: ( staticIlpAddress: string, @@ -31,7 +32,8 @@ export function createRequesters( assetId: string, assetCode: string, name: string, - liquidityThreshold: number + liquidityThresholdLow: number, + liquidityThresholdHigh: number ) => Promise createAutoPeer: ( peerUrl: string, @@ -67,15 +69,16 @@ export function createRequesters( ) => Promise } { return { - createAsset: (code, scale, liquidityThreshold) => - createAsset(apolloClient, code, scale, liquidityThreshold), + createAsset: (code, scale, liquidityThresholdLow, liquidityThresholdHigh) => + createAsset(apolloClient, code, scale, liquidityThresholdLow, liquidityThresholdHigh), createPeer: ( staticIlpAddress, outgoingEndpoint, assetId, assetCode, name, - liquidityThreshold + liquidityThresholdLow, + liquidityThresholdHigh ) => createPeer( apolloClient, @@ -85,7 +88,8 @@ export function createRequesters( assetId, assetCode, name, - liquidityThreshold + liquidityThresholdLow, + liquidityThresholdHigh ), createAutoPeer: (peerUrl, assetId) => createAutoPeer(apolloClient, logger, peerUrl, assetId), @@ -112,7 +116,8 @@ export async function createAsset( apolloClient: ApolloClient, code: string, scale: number, - liquidityThreshold: number + liquidityThresholdLow: number, + liquidityThresholdHigh: number ): Promise { const createAssetMutation = gql` mutation CreateAsset($input: CreateAssetInput!) { @@ -121,7 +126,8 @@ export async function createAsset( id code scale - liquidityThreshold + liquidityThresholdLow + liquidityThresholdHigh } } } @@ -130,7 +136,8 @@ export async function createAsset( input: { code, scale, - liquidityThreshold + liquidityThresholdLow, + liquidityThresholdHigh } } return apolloClient @@ -154,7 +161,8 @@ export async function createPeer( assetId: string, assetCode: string, name: string, - liquidityThreshold: number + liquidityThresholdLow: number, + liquidityThresholdHigh: number ): Promise { const createPeerMutation = gql` mutation CreatePeer($input: CreatePeerInput!) { @@ -174,7 +182,8 @@ export async function createPeer( }, assetId, name, - liquidityThreshold + liquidityThresholdLow, + liquidityThresholdHigh } } return apolloClient diff --git a/packages/mock-account-service-lib/src/seed.ts b/packages/mock-account-service-lib/src/seed.ts index eb1fc20515..42af927a3d 100644 --- a/packages/mock-account-service-lib/src/seed.ts +++ b/packages/mock-account-service-lib/src/seed.ts @@ -41,9 +41,9 @@ export async function setupFromSeed( } = createRequesters(apolloClient, logger) const assets: Record = {} - for (const { code, scale, liquidity, liquidityThreshold } of config.seed + for (const { code, scale, liquidity, liquidityThresholdLow, liquidityThresholdHigh } of config.seed .assets) { - const { asset } = await createAsset(code, scale, liquidityThreshold) + const { asset } = await createAsset(code, scale, liquidityThresholdLow, liquidityThresholdHigh) if (!asset) { throw new Error('asset not defined') } @@ -70,7 +70,8 @@ export async function setupFromSeed( assets[peeringAsset].id, assets[peeringAsset].code, peer.name, - peer.liquidityThreshold + peer.liquidityThresholdLow, + peer.liquidityThresholdHigh ).then((response) => response.peer) if (!peerResponse) { throw new Error('peer response not defined') diff --git a/packages/mock-account-service-lib/src/types.ts b/packages/mock-account-service-lib/src/types.ts index 76c90bfda8..6fdc9ee90f 100644 --- a/packages/mock-account-service-lib/src/types.ts +++ b/packages/mock-account-service-lib/src/types.ts @@ -4,11 +4,13 @@ interface Asset { code: string scale: number liquidity: number - liquidityThreshold: number + liquidityThresholdLow: number + liquidityThresholdHigh: number } export interface Peering { - liquidityThreshold: number + liquidityThresholdLow: number + liquidityThresholdHigh: number peerUrl: string peerIlpAddress: string initialLiquidity: string diff --git a/test/integration/testenv/cloud-nine-wallet/seed.yml b/test/integration/testenv/cloud-nine-wallet/seed.yml index cd55ae9b87..c8c521ca95 100644 --- a/test/integration/testenv/cloud-nine-wallet/seed.yml +++ b/test/integration/testenv/cloud-nine-wallet/seed.yml @@ -2,25 +2,30 @@ assets: - code: USD scale: 2 liquidity: 1000000 - liquidityThreshold: 100000 + liquidityThresholdLow: 100000 + liquidityThresholdHigh: 1000000 - code: EUR scale: 2 liquidity: 1000000 - liquidityThreshold: 100000 + liquidityThresholdLow: 100000 + liquidityThresholdHigh: 1000000 - code: MXN scale: 2 liquidity: 1000000 - liquidityThreshold: 100000 + liquidityThresholdLow: 100000 + liquidityThresholdHigh: 1000000 - code: JPY scale: 0 liquidity: 10000 - liquidityThreshold: 1000 + liquidityThresholdLow: 1000 + liquidityThreshoHighow: 10000 peeringAsset: 'USD' peers: - initialLiquidity: '100000' peerUrl: http://happy-life-bank-test-backend:4102 peerIlpAddress: test.happy-life-bank-test - liquidityThreshold: 10000 + liquidityThresholdLow: 10000 + liquidityThresholHighw: 100000 accounts: - name: 'Grace Franklin' path: accounts/gfranklin diff --git a/test/integration/testenv/happy-life-bank/seed.yml b/test/integration/testenv/happy-life-bank/seed.yml index cb763ce313..1f4b7efc45 100644 --- a/test/integration/testenv/happy-life-bank/seed.yml +++ b/test/integration/testenv/happy-life-bank/seed.yml @@ -2,25 +2,30 @@ assets: - code: USD scale: 2 liquidity: 1000000 - liquidityThreshold: 100000 + liquidityThresholdLow: 100000 + liquidityThresholdHigh: 1000000 - code: EUR scale: 2 liquidity: 1000000 - liquidityThreshold: 100000 + liquidityThresholdLow: 100000 + liquidityThresholdHigh: 1000000 - code: MXN scale: 2 liquidity: 1000000 - liquidityThreshold: 100000 + liquidityThresholdLow: 100000 + liquidityThresholdHigh: 1000000 - code: JPY scale: 0 liquidity: 10000 - liquidityThreshold: 1000 + liquidityThresholdLow: 1000 + liquidityThreshoHighow: 10000 peeringAsset: 'USD' peers: - initialLiquidity: '1000000000000' peerUrl: http://cloud-nine-wallet-test-backend:3102 peerIlpAddress: test.cloud-nine-wallet-test - liquidityThreshold: 100000 + liquidityThresholdLow: 100000 + liquidityThresholdHigh: 1000000 accounts: - name: 'Philip Fry' path: accounts/pfry From 9ceb81d58c9a8983cd7e682746388954e743ebf5 Mon Sep 17 00:00:00 2001 From: golobitch Date: Wed, 6 Nov 2024 22:08:23 +0100 Subject: [PATCH 5/8] chore(lint): everything --- ...3204430_assets_peer_liquidity_threshold.js | 44 +++++++++---------- packages/backend/src/asset/model.test.ts | 6 ++- packages/backend/src/asset/model.ts | 22 ++++++++-- packages/backend/src/asset/service.test.ts | 20 ++++++--- packages/backend/src/asset/service.ts | 23 ++++++++-- .../src/graphql/resolvers/asset.test.ts | 32 ++++++++------ .../backend/src/graphql/resolvers/asset.ts | 2 +- .../ilp/auto-peering/service.test.ts | 8 ++-- .../src/payment-method/ilp/peer/model.test.ts | 2 +- .../src/payment-method/ilp/peer/model.ts | 22 ++++++++-- .../payment-method/ilp/peer/service.test.ts | 13 +++--- .../src/payment-method/ilp/peer/service.ts | 2 +- packages/backend/src/tests/peer.ts | 2 +- .../src/requesters.ts | 8 +++- packages/mock-account-service-lib/src/seed.ts | 20 +++++++-- 15 files changed, 152 insertions(+), 74 deletions(-) diff --git a/packages/backend/migrations/20241103204430_assets_peer_liquidity_threshold.js b/packages/backend/migrations/20241103204430_assets_peer_liquidity_threshold.js index 7716649f3c..13d728323d 100644 --- a/packages/backend/migrations/20241103204430_assets_peer_liquidity_threshold.js +++ b/packages/backend/migrations/20241103204430_assets_peer_liquidity_threshold.js @@ -1,25 +1,25 @@ -exports.up = function(knex) { - return Promise.all([ - knex.schema.table('assets', (table) => { - table.renameColumn('liquidityThreshold', 'liquidityThresholdLow') - table.bigInteger('liquidityThresholdHigh').nullable() - }), - knex.schema.table('peers', (table) => { - table.renameColumn('liquidityThreshold', 'liquidityThresholdLow') - table.bigInteger('liquidityThresholdHigh').nullable() - }) - ]) +exports.up = function (knex) { + return Promise.all([ + knex.schema.table('assets', (table) => { + table.renameColumn('liquidityThreshold', 'liquidityThresholdLow') + table.bigInteger('liquidityThresholdHigh').nullable() + }), + knex.schema.table('peers', (table) => { + table.renameColumn('liquidityThreshold', 'liquidityThresholdLow') + table.bigInteger('liquidityThresholdHigh').nullable() + }) + ]) } -exports.down = function(knex) { - return Promise.all([ - knex.schema.table('assets', (table) => { - table.renameColumn('liquidityThresholdLow', 'liquidityThreshold') - table.dropColumn('liquidityThresholdHigh') - }), - knex.schema.table('peers', (table) => { - table.renameColumn('liquidityThresholdLow', 'liquidityThreshold') - table.dropColumn('liquidityThresholdHigh') - }) - ]) +exports.down = function (knex) { + return Promise.all([ + knex.schema.table('assets', (table) => { + table.renameColumn('liquidityThresholdLow', 'liquidityThreshold') + table.dropColumn('liquidityThresholdHigh') + }), + knex.schema.table('peers', (table) => { + table.renameColumn('liquidityThresholdLow', 'liquidityThreshold') + table.dropColumn('liquidityThresholdHigh') + }) + ]) } diff --git a/packages/backend/src/asset/model.test.ts b/packages/backend/src/asset/model.test.ts index e86c59ffcd..fbaf4c85f9 100644 --- a/packages/backend/src/asset/model.test.ts +++ b/packages/backend/src/asset/model.test.ts @@ -56,7 +56,10 @@ describe('Models', (): void => { async ({ balance }): Promise => { await asset.onDebit({ balance }) const event = ( - await AssetEvent.query(knex).where('type', AssetEventType.LiquidityHigh) + await AssetEvent.query(knex).where( + 'type', + AssetEventType.LiquidityHigh + ) )[0] expect(event).toMatchObject({ @@ -112,7 +115,6 @@ describe('Models', (): void => { ).resolves.toEqual([]) }) - test.each` balance ${BigInt(200)} diff --git a/packages/backend/src/asset/model.ts b/packages/backend/src/asset/model.ts index 279163c11a..c2523d9669 100644 --- a/packages/backend/src/asset/model.ts +++ b/packages/backend/src/asset/model.ts @@ -30,12 +30,18 @@ export class Asset extends BaseModel implements LiquidityAccount { } } - private async checkAndInsertEvent(balance: bigint, threshold: bigint | null, eventType: AssetEventType) { + private async checkAndInsertEvent( + balance: bigint, + threshold: bigint | null, + eventType: AssetEventType + ) { if (threshold === null) { return } - const isThresholdCrossed = (eventType === AssetEventType.LiquidityLow && balance <= threshold) || (eventType === AssetEventType.LiquidityHigh && balance >= threshold) + const isThresholdCrossed = + (eventType === AssetEventType.LiquidityLow && balance <= threshold) || + (eventType === AssetEventType.LiquidityHigh && balance >= threshold) if (isThresholdCrossed) { await AssetEvent.query().insert({ @@ -57,8 +63,16 @@ export class Asset extends BaseModel implements LiquidityAccount { public async onDebit({ balance }: OnDebitOptions): Promise { await Promise.all([ - this.checkAndInsertEvent(balance, this.liquidityThresholdLow, AssetEventType.LiquidityLow), - this.checkAndInsertEvent(balance, this.liquidityThresholdHigh, AssetEventType.LiquidityHigh) + this.checkAndInsertEvent( + balance, + this.liquidityThresholdLow, + AssetEventType.LiquidityLow + ), + this.checkAndInsertEvent( + balance, + this.liquidityThresholdHigh, + AssetEventType.LiquidityHigh + ) ]) return this diff --git a/packages/backend/src/asset/service.test.ts b/packages/backend/src/asset/service.test.ts index aedfa7b2bc..560fbb7e24 100644 --- a/packages/backend/src/asset/service.test.ts +++ b/packages/backend/src/asset/service.test.ts @@ -57,12 +57,16 @@ describe('Asset Service', (): void => { ${BigInt(5)} | ${BigInt(5)} | ${BigInt(500)} `( 'Asset can be created and fetched', - async ({ withdrawalThreshold, liquidityThresholdLow, liquidityThresholdHigh }): Promise => { + async ({ + withdrawalThreshold, + liquidityThresholdLow, + liquidityThresholdHigh + }): Promise => { const options = { ...randomAsset(), withdrawalThreshold, liquidityThresholdLow, - liquidityThresholdHigh, + liquidityThresholdHigh } const asset = await assetService.create(options) assert.ok(!isAssetError(asset)) @@ -72,7 +76,7 @@ describe('Asset Service', (): void => { ledger: asset.ledger, withdrawalThreshold: withdrawalThreshold || null, liquidityThresholdLow: liquidityThresholdLow || null, - liquidityThresholdHigh: liquidityThresholdHigh || null, + liquidityThresholdHigh: liquidityThresholdHigh || null }) await expect(assetService.get(asset.id)).resolves.toEqual(asset) } @@ -150,7 +154,7 @@ describe('Asset Service', (): void => { describe('update', (): void => { describe.each` - withdrawalThreshold | liquidityThresholdLow | liquidityThresholdHigh + withdrawalThreshold | liquidityThresholdLow | liquidityThresholdHigh ${null} | ${null} | ${null} ${null} | ${null} | ${BigInt(500)} ${null} | ${BigInt(5)} | ${null} @@ -165,7 +169,11 @@ describe('Asset Service', (): void => { ${BigInt(5)} | ${BigInt(5)} | ${BigInt(500)} `( 'Asset threshold can be updated from withdrawalThreshold: $withdrawalThreshold, liquidityThresholdLow: $liquidityThresholdLow, liquidityThresholdHigh: $liquidityThresholdHigh', - ({ withdrawalThreshold, liquidityThresholdLow, liquidityThresholdHigh }): void => { + ({ + withdrawalThreshold, + liquidityThresholdLow, + liquidityThresholdHigh + }): void => { let assetId: string beforeEach(async (): Promise => { @@ -181,7 +189,7 @@ describe('Asset Service', (): void => { }) test.each` - withdrawalThreshold | liquidityThresholdLow | liquidityThresholdHigh + withdrawalThreshold | liquidityThresholdLow | liquidityThresholdHigh ${null} | ${null} | ${null} ${null} | ${null} | ${BigInt(500)} ${null} | ${BigInt(5)} | ${null} diff --git a/packages/backend/src/asset/service.ts b/packages/backend/src/asset/service.ts index 67ddde756a..bb34fd04c6 100644 --- a/packages/backend/src/asset/service.ts +++ b/packages/backend/src/asset/service.ts @@ -72,7 +72,13 @@ export async function createAssetService({ async function createAsset( deps: ServiceDependencies, - { code, scale, withdrawalThreshold, liquidityThresholdLow, liquidityThresholdHigh }: CreateOptions + { + code, + scale, + withdrawalThreshold, + liquidityThresholdLow, + liquidityThresholdHigh + }: CreateOptions ): Promise { try { // check if exists but deleted | by code-scale @@ -101,7 +107,7 @@ async function createAsset( scale, withdrawalThreshold, liquidityThresholdLow, - liquidityThresholdHigh, + liquidityThresholdHigh }) await deps.accountingService.createLiquidityAndLinkedSettlementAccount( asset, @@ -120,14 +126,23 @@ async function createAsset( async function updateAsset( deps: ServiceDependencies, - { id, withdrawalThreshold, liquidityThresholdLow, liquidityThresholdHigh }: UpdateOptions + { + id, + withdrawalThreshold, + liquidityThresholdLow, + liquidityThresholdHigh + }: UpdateOptions ): Promise { if (!deps.knex) { throw new Error('Knex undefined') } try { return await Asset.query(deps.knex) - .patchAndFetchById(id, { withdrawalThreshold, liquidityThresholdLow, liquidityThresholdHigh }) + .patchAndFetchById(id, { + withdrawalThreshold, + liquidityThresholdLow, + liquidityThresholdHigh + }) .throwIfNotFound() } catch (err) { if (err instanceof NotFoundError) { diff --git a/packages/backend/src/graphql/resolvers/asset.test.ts b/packages/backend/src/graphql/resolvers/asset.test.ts index 78e9021f59..71acce38cc 100644 --- a/packages/backend/src/graphql/resolvers/asset.test.ts +++ b/packages/backend/src/graphql/resolvers/asset.test.ts @@ -59,14 +59,14 @@ describe('Asset Resolvers', (): void => { describe('Create Asset', (): void => { test.each` - withdrawalThreshold | expectedWithdrawalThreshold | liquidityThresholdLow | expectedLiquidityThresholdLow | liquidityThresholdHigh | expectedLiquidityThresholdHigh - ${undefined} | ${null} | ${undefined} | ${null} | ${undefined} | ${null} - ${BigInt(0)} | ${'0'} | ${undefined} | ${null} | ${undefined} | ${null} - ${BigInt(5)} | ${'5'} | ${undefined} | ${null} | ${undefined} | ${null} - ${undefined} | ${null} | ${BigInt(0)} | ${'0'} | ${BigInt(100)} | ${'100'} - ${undefined} | ${null} | ${BigInt(5)} | ${'5'} | ${BigInt(5000)} | ${'5000'} - ${BigInt(0)} | ${'0'} | ${BigInt(0)} | ${'0'} | ${BigInt(100)} | ${'100'} - ${BigInt(5)} | ${'5'} | ${BigInt(5)} | ${'5'} | ${BigInt(5000)} | ${'5000'} + withdrawalThreshold | expectedWithdrawalThreshold | liquidityThresholdLow | expectedLiquidityThresholdLow | liquidityThresholdHigh | expectedLiquidityThresholdHigh + ${undefined} | ${null} | ${undefined} | ${null} | ${undefined} | ${null} + ${BigInt(0)} | ${'0'} | ${undefined} | ${null} | ${undefined} | ${null} + ${BigInt(5)} | ${'5'} | ${undefined} | ${null} | ${undefined} | ${null} + ${undefined} | ${null} | ${BigInt(0)} | ${'0'} | ${BigInt(100)} | ${'100'} + ${undefined} | ${null} | ${BigInt(5)} | ${'5'} | ${BigInt(5000)} | ${'5000'} + ${BigInt(0)} | ${'0'} | ${BigInt(0)} | ${'0'} | ${BigInt(100)} | ${'100'} + ${BigInt(5)} | ${'5'} | ${BigInt(5)} | ${'5'} | ${BigInt(5000)} | ${'5000'} `( 'Can create an asset (withdrawalThreshold: $withdrawalThreshold, liquidityThresholdLow: $liquidityThresholdLow, liquidityThresholdHigh: $liquidityThresholdHigh)', async ({ @@ -293,7 +293,7 @@ describe('Asset Resolvers', (): void => { const asset = await assetService.create({ ...randomAsset(), withdrawalThreshold: BigInt(10), - liquidityThreshold: BigInt(100) + liquidityThresholdLow: BigInt(100) }) assert.ok(!isAssetError(asset)) assert.ok(asset.withdrawalThreshold) @@ -331,7 +331,8 @@ describe('Asset Resolvers', (): void => { scale: asset.scale, liquidity: '0', withdrawalThreshold: asset.withdrawalThreshold.toString(), - liquidityThreshold: asset.liquidityThreshold?.toString(), + liquidityThresholdLow: asset.liquidityThresholdLow?.toString(), + liquidityThresholdHigh: asset.liquidityThresholdHigh?.toString(), createdAt: new Date(+asset.createdAt).toISOString() }) @@ -348,7 +349,8 @@ describe('Asset Resolvers', (): void => { scale: asset.scale, liquidity: '100', withdrawalThreshold: asset.withdrawalThreshold.toString(), - liquidityThreshold: asset.liquidityThreshold?.toString(), + liquidityThresholdLow: asset.liquidityThresholdLow?.toString(), + liquidityThresholdHigh: asset.liquidityThresholdHigh?.toString(), createdAt: new Date(+asset.createdAt).toISOString() }) }) @@ -628,7 +630,11 @@ describe('Asset Resolvers', (): void => { ${BigInt(5)} | ${BigInt(5)} | ${BigInt(5000)} `( 'from withdrawalThreshold: $withdrawalThreshold, liquidityThresholdLow: $liquidityThresholdLow and liquidityThresholdHigh: $liquidityThresholdHigh', - ({ withdrawalThreshold, liquidityThresholdLow, liquidityThresholdHigh }): void => { + ({ + withdrawalThreshold, + liquidityThresholdLow, + liquidityThresholdHigh + }): void => { let asset: AssetModel beforeEach(async (): Promise => { @@ -643,7 +649,7 @@ describe('Asset Resolvers', (): void => { test.each` withdrawalThreshold | liquidityThresholdLow | liquidityThresholdHigh - ${null} | ${null} | ${null} + ${null} | ${null} | ${null} ${BigInt(0)} | ${null} | ${null} ${BigInt(5)} | ${null} | ${null} ${null} | ${BigInt(0)} | ${BigInt(1000)} diff --git a/packages/backend/src/graphql/resolvers/asset.ts b/packages/backend/src/graphql/resolvers/asset.ts index f2bce9dd98..e6c20d7c1c 100644 --- a/packages/backend/src/graphql/resolvers/asset.ts +++ b/packages/backend/src/graphql/resolvers/asset.ts @@ -94,7 +94,7 @@ export const updateAsset: MutationResolvers['updateAsset'] = id: args.input.id, withdrawalThreshold: args.input.withdrawalThreshold ?? null, liquidityThresholdLow: args.input.liquidityThresholdLow ?? null, - liquidityThresholdHigh: args.input.liquidityThresholdHigh ?? null, + liquidityThresholdHigh: args.input.liquidityThresholdHigh ?? null }) if (isAssetError(assetOrError)) { throw new GraphQLError(errorToMessage[assetOrError], { diff --git a/packages/backend/src/payment-method/ilp/auto-peering/service.test.ts b/packages/backend/src/payment-method/ilp/auto-peering/service.test.ts index af2c2e2282..ff707a31c1 100644 --- a/packages/backend/src/payment-method/ilp/auto-peering/service.test.ts +++ b/packages/backend/src/payment-method/ilp/auto-peering/service.test.ts @@ -214,7 +214,7 @@ describe('Auto Peering Service', (): void => { peerUrl: 'http://peer.rafiki.money', assetId: asset.id, maxPacketAmount: 1000n, - liquidityThreshold: 100n + liquidityThresholdLow: 100n } const peerDetails: PeeringDetails = { @@ -261,7 +261,7 @@ describe('Auto Peering Service', (): void => { }, maxPacketAmount: args.maxPacketAmount, name: peerDetails.name, - liquidityThreshold: args.liquidityThreshold + liquidityThreshold: args.liquidityThresholdLow }) scope.done() @@ -274,7 +274,7 @@ describe('Auto Peering Service', (): void => { peerUrl: 'http://peer.rafiki.money', assetId: asset.id, maxPacketAmount: 1000n, - liquidityThreshold: 100n, + liquidityThresholdLow: 100n, liquidityToDeposit: 10000n } @@ -320,7 +320,7 @@ describe('Auto Peering Service', (): void => { peerUrl: 'http://peer.rafiki.money', assetId: asset.id, maxPacketAmount: 1000n, - liquidityThreshold: 100n, + liquidityThresholdLow: 100n, liquidityToDeposit: -10000n } diff --git a/packages/backend/src/payment-method/ilp/peer/model.test.ts b/packages/backend/src/payment-method/ilp/peer/model.test.ts index a664509eb1..47193c3955 100644 --- a/packages/backend/src/payment-method/ilp/peer/model.test.ts +++ b/packages/backend/src/payment-method/ilp/peer/model.test.ts @@ -89,7 +89,7 @@ describe('Models', (): void => { code: asset.code, scale: asset.scale }, - liquidityThreshold: peer.liquidityThreshold?.toString(), + liquidityThreshold: peer.liquidityThresholdLow?.toString(), balance: balance.toString() } }) diff --git a/packages/backend/src/payment-method/ilp/peer/model.ts b/packages/backend/src/payment-method/ilp/peer/model.ts index ceb524f87c..d517d98765 100644 --- a/packages/backend/src/payment-method/ilp/peer/model.ts +++ b/packages/backend/src/payment-method/ilp/peer/model.ts @@ -54,12 +54,18 @@ export class Peer public name?: string - private async checkAndInsertEvent(balance: bigint, threshold: bigint | null, eventType: PeerEventType) { + private async checkAndInsertEvent( + balance: bigint, + threshold: bigint | null, + eventType: PeerEventType + ) { if (threshold === null) { return } - const isThresholdCrossed = (eventType === PeerEventType.LiquidityLow && balance <= threshold) || (eventType === PeerEventType.LiquidityHigh && balance >= threshold) + const isThresholdCrossed = + (eventType === PeerEventType.LiquidityLow && balance <= threshold) || + (eventType === PeerEventType.LiquidityHigh && balance >= threshold) if (isThresholdCrossed) { await PeerEvent.query().insert({ @@ -81,8 +87,16 @@ export class Peer public async onDebit({ balance }: OnDebitOptions): Promise { await Promise.all([ - this.checkAndInsertEvent(balance, this.liquidityThresholdLow, PeerEventType.LiquidityLow), - this.checkAndInsertEvent(balance, this.liquidityThresholdHigh, PeerEventType.LiquidityHigh) + this.checkAndInsertEvent( + balance, + this.liquidityThresholdLow, + PeerEventType.LiquidityLow + ), + this.checkAndInsertEvent( + balance, + this.liquidityThresholdHigh, + PeerEventType.LiquidityHigh + ) ]) return this } diff --git a/packages/backend/src/payment-method/ilp/peer/service.test.ts b/packages/backend/src/payment-method/ilp/peer/service.test.ts index 9d0a7ae430..81f0051b76 100644 --- a/packages/backend/src/payment-method/ilp/peer/service.test.ts +++ b/packages/backend/src/payment-method/ilp/peer/service.test.ts @@ -39,7 +39,8 @@ describe('Peer Service', (): void => { maxPacketAmount: BigInt(100), staticIlpAddress: 'test.' + uuid(), name: faker.person.fullName(), - liquidityThreshold: BigInt(10000), + liquidityThresholdLow: BigInt(10000), + liquidityThresholdHigh: BigInt(100000), ...override }) @@ -223,12 +224,12 @@ describe('Peer Service', (): void => { describe('Update Peer', (): void => { test.each` - liquidityThreshold + liquidityThresholdLow ${null} ${BigInt(2000)} `( - 'Can update a peer, liquidityThreshold: $liquidityThreshold', - async ({ liquidityThreshold }): Promise => { + 'Can update a peer, liquidityThresholdLow: $liquidityThresholdLow', + async ({ liquidityThresholdLow }): Promise => { const peer = await createPeer(deps) const { http, maxPacketAmount, staticIlpAddress, name } = randomPeer() const updateOptions: UpdateOptions = { @@ -237,7 +238,7 @@ describe('Peer Service', (): void => { maxPacketAmount, staticIlpAddress, name, - liquidityThreshold + liquidityThresholdLow } const peerOrError = await peerService.update(updateOptions) @@ -252,7 +253,7 @@ describe('Peer Service', (): void => { maxPacketAmount: updateOptions.maxPacketAmount, staticIlpAddress: updateOptions.staticIlpAddress, name: updateOptions.name, - liquidityThreshold: updateOptions.liquidityThreshold || null + liquidityThresholdLow: updateOptions.liquidityThresholdLow || null } expect(peerOrError).toMatchObject(expectedPeer) await expect(peerService.get(peer.id)).resolves.toEqual(peerOrError) diff --git a/packages/backend/src/payment-method/ilp/peer/service.ts b/packages/backend/src/payment-method/ilp/peer/service.ts index 1d21b0deee..81ef131750 100644 --- a/packages/backend/src/payment-method/ilp/peer/service.ts +++ b/packages/backend/src/payment-method/ilp/peer/service.ts @@ -140,7 +140,7 @@ async function createPeer( staticIlpAddress: options.staticIlpAddress, name: options.name, liquidityThresholdLow: options.liquidityThresholdLow, - liquidityThresholdHigh: options.liquidityThresholdHigh, + liquidityThresholdHigh: options.liquidityThresholdHigh }) .withGraphFetched('asset') diff --git a/packages/backend/src/tests/peer.ts b/packages/backend/src/tests/peer.ts index 1c723dfcbb..c92ff162d5 100644 --- a/packages/backend/src/tests/peer.ts +++ b/packages/backend/src/tests/peer.ts @@ -36,7 +36,7 @@ export async function createPeer( if (options.liquidityThresholdHigh) { peerOptions.liquidityThresholdHigh = options.liquidityThresholdHigh } - + const peerService = await deps.use('peerService') const peer = await peerService.create(peerOptions) if (isPeerError(peer)) { diff --git a/packages/mock-account-service-lib/src/requesters.ts b/packages/mock-account-service-lib/src/requesters.ts index 113b63279f..9ba1f27829 100644 --- a/packages/mock-account-service-lib/src/requesters.ts +++ b/packages/mock-account-service-lib/src/requesters.ts @@ -78,7 +78,13 @@ export function createRequesters( } { return { createAsset: (code, scale, liquidityThresholdLow, liquidityThresholdHigh) => - createAsset(apolloClient, code, scale, liquidityThresholdLow, liquidityThresholdHigh), + createAsset( + apolloClient, + code, + scale, + liquidityThresholdLow, + liquidityThresholdHigh + ), createPeer: ( staticIlpAddress, outgoingEndpoint, diff --git a/packages/mock-account-service-lib/src/seed.ts b/packages/mock-account-service-lib/src/seed.ts index a2f33a4cc5..bb1c3b0ed6 100644 --- a/packages/mock-account-service-lib/src/seed.ts +++ b/packages/mock-account-service-lib/src/seed.ts @@ -44,12 +44,24 @@ export async function setupFromSeed( } = createRequesters(apolloClient, logger) const assets: Record = {} - for (const { code, scale, liquidity, liquidityThresholdLow, liquidityThresholdHigh } of config.seed - .assets) { - + for (const { + code, + scale, + liquidity, + liquidityThresholdLow, + liquidityThresholdHigh + } of config.seed.assets) { let asset = await getAssetByCodeAndScale(code, scale) if (!asset) { - asset = (await createAsset(code, scale, liquidityThresholdLow, liquidityThresholdHigh)).asset || null + asset = + ( + await createAsset( + code, + scale, + liquidityThresholdLow, + liquidityThresholdHigh + ) + ).asset || null } if (!asset) { From dc11aaf4bc654f526e1b8f94d33c4a38d3faff8a Mon Sep 17 00:00:00 2001 From: golobitch Date: Thu, 7 Nov 2024 21:01:55 +0100 Subject: [PATCH 6/8] test(backend): asset and peer resolver + ilp --- packages/backend/src/graphql/resolvers/asset.test.ts | 9 ++++++--- packages/backend/src/graphql/resolvers/peer.test.ts | 9 ++++++--- packages/backend/src/openapi/specs/webhooks.yaml | 2 ++ .../payment-method/ilp/auto-peering/service.test.ts | 2 +- .../backend/src/payment-method/ilp/peer/model.test.ts | 2 +- packages/backend/src/payment-method/ilp/peer/model.ts | 2 +- .../src/payment-method/ilp/peer/service.test.ts | 10 +++++----- packages/mock-account-service-lib/src/requesters.ts | 2 +- packages/mock-account-service-lib/src/types.ts | 4 +++- test/integration/lib/integration-server.ts | 5 +++++ 10 files changed, 31 insertions(+), 16 deletions(-) diff --git a/packages/backend/src/graphql/resolvers/asset.test.ts b/packages/backend/src/graphql/resolvers/asset.test.ts index 71acce38cc..9c6365fb1e 100644 --- a/packages/backend/src/graphql/resolvers/asset.test.ts +++ b/packages/backend/src/graphql/resolvers/asset.test.ts @@ -225,7 +225,8 @@ describe('Asset Resolvers', (): void => { const asset = await assetService.create({ ...randomAsset(), withdrawalThreshold: BigInt(10), - liquidityThresholdLow: BigInt(100) + liquidityThresholdLow: BigInt(100), + liquidityThresholdHigh: BigInt(1000) }) assert.ok(!isAssetError(asset)) assert.ok(asset.withdrawalThreshold) @@ -293,7 +294,8 @@ describe('Asset Resolvers', (): void => { const asset = await assetService.create({ ...randomAsset(), withdrawalThreshold: BigInt(10), - liquidityThresholdLow: BigInt(100) + liquidityThresholdLow: BigInt(100), + liquidityThresholdHigh: BigInt(1000) }) assert.ok(!isAssetError(asset)) assert.ok(asset.withdrawalThreshold) @@ -309,7 +311,8 @@ describe('Asset Resolvers', (): void => { scale liquidity withdrawalThreshold - liquidityThreshold + liquidityThresholdLow + liquidityThresholdHigh createdAt } } diff --git a/packages/backend/src/graphql/resolvers/peer.test.ts b/packages/backend/src/graphql/resolvers/peer.test.ts index 829551b094..2e95b7e75c 100644 --- a/packages/backend/src/graphql/resolvers/peer.test.ts +++ b/packages/backend/src/graphql/resolvers/peer.test.ts @@ -374,7 +374,8 @@ describe('Peer Resolvers', (): void => { staticIlpAddress liquidity name - liquidityThreshold + liquidityThresholdLow + liquidityThresholdHigh } } `, @@ -407,7 +408,8 @@ describe('Peer Resolvers', (): void => { maxPacketAmount: peer.maxPacketAmount?.toString(), liquidity: '0', name: peer.name, - liquidityThreshold: '100' + liquidityThresholdLow: '100', + liquidityThresholdHigh: '2000' }) await accountingService.createDeposit({ @@ -435,7 +437,8 @@ describe('Peer Resolvers', (): void => { maxPacketAmount: peer.maxPacketAmount?.toString(), liquidity: '100', name: peer.name, - liquidityThreshold: '100' + liquidityThresholdLow: '100', + liquidityThresholdHigh: '2000' }) }) diff --git a/packages/backend/src/openapi/specs/webhooks.yaml b/packages/backend/src/openapi/specs/webhooks.yaml index d775db1bcc..5f17046f57 100644 --- a/packages/backend/src/openapi/specs/webhooks.yaml +++ b/packages/backend/src/openapi/specs/webhooks.yaml @@ -319,7 +319,9 @@ components: type: string enum: - asset.liquidity_low + - asset.liquidity_high - peer.liquidity_low + - peer.liquidity_high data: type: object required: diff --git a/packages/backend/src/payment-method/ilp/auto-peering/service.test.ts b/packages/backend/src/payment-method/ilp/auto-peering/service.test.ts index ff707a31c1..589e39ef8b 100644 --- a/packages/backend/src/payment-method/ilp/auto-peering/service.test.ts +++ b/packages/backend/src/payment-method/ilp/auto-peering/service.test.ts @@ -261,7 +261,7 @@ describe('Auto Peering Service', (): void => { }, maxPacketAmount: args.maxPacketAmount, name: peerDetails.name, - liquidityThreshold: args.liquidityThresholdLow + liquidityThresholdLow: args.liquidityThresholdLow }) scope.done() diff --git a/packages/backend/src/payment-method/ilp/peer/model.test.ts b/packages/backend/src/payment-method/ilp/peer/model.test.ts index 47193c3955..1e2ace25b4 100644 --- a/packages/backend/src/payment-method/ilp/peer/model.test.ts +++ b/packages/backend/src/payment-method/ilp/peer/model.test.ts @@ -58,7 +58,7 @@ describe('Models', (): void => { maxPacketAmount: BigInt(100), staticIlpAddress: 'test.' + uuid(), name: faker.person.fullName(), - liquidityThreshold: BigInt(100) + liquidityThresholdLow: BigInt(100) } const peerOrError = await peerService.create(options) if (!isPeerError(peerOrError)) { diff --git a/packages/backend/src/payment-method/ilp/peer/model.ts b/packages/backend/src/payment-method/ilp/peer/model.ts index d517d98765..cfa48dccc4 100644 --- a/packages/backend/src/payment-method/ilp/peer/model.ts +++ b/packages/backend/src/payment-method/ilp/peer/model.ts @@ -69,7 +69,7 @@ export class Peer if (isThresholdCrossed) { await PeerEvent.query().insert({ - assetId: this.id, + peerId: this.id, type: eventType, data: { id: this.id, diff --git a/packages/backend/src/payment-method/ilp/peer/service.test.ts b/packages/backend/src/payment-method/ilp/peer/service.test.ts index 81f0051b76..43da9d3308 100644 --- a/packages/backend/src/payment-method/ilp/peer/service.test.ts +++ b/packages/backend/src/payment-method/ilp/peer/service.test.ts @@ -65,12 +65,12 @@ describe('Peer Service', (): void => { describe('Create/Get Peer', (): void => { test.each` - liquidityThreshold + liquidityThresholdLow ${undefined} ${BigInt(1000)} `( - 'A peer can be created and fetched, liquidityThreshold: $liquidityThreshold', - async ({ liquidityThreshold }): Promise => { + 'A peer can be created and fetched, liquidityThresholdLow: $liquidityThresholdLow', + async ({ liquidityThresholdLow }): Promise => { const options = { assetId: asset.id, http: { @@ -81,7 +81,7 @@ describe('Peer Service', (): void => { }, staticIlpAddress: 'test.' + uuid(), name: faker.person.fullName(), - liquidityThreshold + liquidityThresholdLow } const peer = await peerService.create(options) assert.ok(!isPeerError(peer)) @@ -92,7 +92,7 @@ describe('Peer Service', (): void => { }, staticIlpAddress: options.staticIlpAddress, name: options.name, - liquidityThreshold: liquidityThreshold || null + liquidityThresholdLow: liquidityThresholdLow || null }) const retrievedPeer = await peerService.get(peer.id) if (!retrievedPeer) throw new Error('peer not found') diff --git a/packages/mock-account-service-lib/src/requesters.ts b/packages/mock-account-service-lib/src/requesters.ts index 9ba1f27829..ac240e5124 100644 --- a/packages/mock-account-service-lib/src/requesters.ts +++ b/packages/mock-account-service-lib/src/requesters.ts @@ -478,7 +478,7 @@ async function getAssetByCodeAndScale( id code scale - liquidityThreshold + liquidityThresholdLow } } ` diff --git a/packages/mock-account-service-lib/src/types.ts b/packages/mock-account-service-lib/src/types.ts index 6fdc9ee90f..32384af1b4 100644 --- a/packages/mock-account-service-lib/src/types.ts +++ b/packages/mock-account-service-lib/src/types.ts @@ -68,5 +68,7 @@ export enum WebhookEventType { WalletAddressWebMonetization = 'wallet_address.web_monetization', WalletAddressNotFound = 'wallet_address.not_found', AssetLiquidityLow = 'asset.liquidity_low', - PeerLiquidityLow = 'peer.liquidity_low' + PeerLiquidityLow = 'peer.liquidity_low', + AssetLiquidityHigh = 'asset.liquidity_high', + PeerLiquidityHigh = 'peer.liquidity_high' } diff --git a/test/integration/lib/integration-server.ts b/test/integration/lib/integration-server.ts index 54ba96559c..b1b640e160 100644 --- a/test/integration/lib/integration-server.ts +++ b/test/integration/lib/integration-server.ts @@ -105,6 +105,11 @@ export class WebhookEventHandler { break case WebhookEventType.OutgoingPaymentCompleted: break + case WebhookEventType.AssetLiquidityHigh: + case WebhookEventType.AssetLiquidityLow: + case WebhookEventType.PeerLiquidityHigh: + case WebhookEventType.PeerLiquidityLow: + break default: console.log(`unknown event type: ${webhookEvent.type}`) } From c061abcd5e17640f4f30240b9976ed5941cd0cc9 Mon Sep 17 00:00:00 2001 From: golobitch Date: Thu, 7 Nov 2024 21:37:29 +0100 Subject: [PATCH 7/8] docs(bruno): update admin and webhook apis with liquidity threshold low and high --- bruno/collections/Rafiki/Rafiki Admin APIs/Create Asset.bru | 6 ++++-- bruno/collections/Rafiki/Rafiki Admin APIs/Create Peer.bru | 6 ++++-- bruno/collections/Rafiki/Rafiki Admin APIs/Delete Asset.bru | 3 ++- .../Rafiki Admin APIs/Get Asset By Code And Scale.bru | 3 ++- bruno/collections/Rafiki/Rafiki Admin APIs/Get Asset.bru | 3 ++- bruno/collections/Rafiki/Rafiki Admin APIs/Get Assets.bru | 3 ++- .../Rafiki Admin APIs/Get Peer By Address and Asset Id.bru | 3 ++- bruno/collections/Rafiki/Rafiki Admin APIs/Get Peer.bru | 3 ++- bruno/collections/Rafiki/Rafiki Admin APIs/Get Peers.bru | 3 ++- bruno/collections/Rafiki/Rafiki Admin APIs/Update Asset.bru | 6 ++++-- bruno/collections/Rafiki/Rafiki Admin APIs/Update Peer.bru | 6 ++++-- .../Rafiki/Sample Webhook Events/Asset Liquidity Low.bru | 3 ++- .../Rafiki/Sample Webhook Events/Peer Liquidity Low.bru | 3 ++- 13 files changed, 34 insertions(+), 17 deletions(-) diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Asset.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Asset.bru index 053fc31526..d8736e88fc 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Asset.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Asset.bru @@ -19,7 +19,8 @@ body:graphql { id scale withdrawalThreshold - liquidityThreshold + liquidityThresholdLow + liquidityThresholdHigh } } } @@ -31,7 +32,8 @@ body:graphql:vars { "code": "JPY", "scale": 6, "withdrawalThreshold": null, - "liquidityThreshold": "100000000" + "liquidityThresholdLow": "100000000", + "liquidityThresholdHigh": "10000000000" } } } diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Peer.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Peer.bru index d0d957d65b..1e314019b2 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Peer.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Peer.bru @@ -17,7 +17,8 @@ body:graphql { id name liquidity - liquidityThreshold + liquidityThresholdLow + liquidityThresholdHigh asset{ id scale @@ -40,7 +41,8 @@ body:graphql:vars { }, "assetId": "{{assetId}}", "maxPacketAmount": 1000, - "liquidityThreshold": 100000000, + "liquidityThresholdLow": 100000000, + "liquidityThresholdHigh": "100000000", "initialLiquidity": 200000000 } } diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Delete Asset.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Delete Asset.bru index d5fbaa9570..2bd4a671ee 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Delete Asset.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Delete Asset.bru @@ -19,7 +19,8 @@ body:graphql { id scale withdrawalThreshold - liquidityThreshold + liquidityThresholdLow + liquidityThresholdHigh } } } diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Asset By Code And Scale.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Asset By Code And Scale.bru index 4f2e88f7d9..dc46a8e77f 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Asset By Code And Scale.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Asset By Code And Scale.bru @@ -18,7 +18,8 @@ body:graphql { id scale withdrawalThreshold - liquidityThreshold + liquidityThresholdLow + liquidityThresholdHigh sendingFee { id type diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Asset.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Asset.bru index 44f7dc482b..f2ce2b6120 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Asset.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Asset.bru @@ -18,7 +18,8 @@ body:graphql { id scale withdrawalThreshold - liquidityThreshold + liquidityThresholdLow + liquidityThresholdHigh sendingFee { id type diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Assets.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Assets.bru index e1198c5cd6..8bd3788d78 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Assets.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Assets.bru @@ -21,7 +21,8 @@ body:graphql { id scale withdrawalThreshold - liquidityThreshold + liquidityThresholdLow + liquidityThresholdHigh liquidity sendingFee { id diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peer By Address and Asset Id.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peer By Address and Asset Id.bru index a00d70c013..4065edfadc 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peer By Address and Asset Id.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peer By Address and Asset Id.bru @@ -22,7 +22,8 @@ body:graphql { } } liquidity - liquidityThreshold + liquidityThresholdLow + liquidityThresholdHigh } } diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peer.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peer.bru index bc035ba90f..cbbbdb0485 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peer.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peer.bru @@ -22,7 +22,8 @@ body:graphql { } } liquidity - liquidityThreshold + liquidityThresholdLow + liquidityThresholdHigh } } } diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peers.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peers.bru index 482fa702ba..ecb3d2545e 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peers.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peers.bru @@ -23,7 +23,8 @@ body:graphql { scale } liquidity - liquidityThreshold + liquidityThresholdLow + liquidityThresholdHigh staticIlpAddress http { outgoing { diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Update Asset.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Update Asset.bru index 0e5000adf3..9942000461 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Update Asset.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Update Asset.bru @@ -19,7 +19,8 @@ body:graphql { id scale withdrawalThreshold - liquidityThreshold + liquidityThresholdLow + liquidityThresholdHigh } } } @@ -30,7 +31,8 @@ body:graphql:vars { "input": { "id": "{{assetId}}", "withdrawalThreshold": 100, - "liquidityThreshold": 100 + "liquidityThresholdLow": 100, + "liquidityThresholdHigh": 500 } } } diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Update Peer.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Update Peer.bru index e424a4c9fc..ca0213f5fe 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Update Peer.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Update Peer.bru @@ -23,7 +23,8 @@ body:graphql { } } liquidity - liquidityThreshold + liquidityThresholdLow + liquidityThresholdHigh } } } @@ -39,7 +40,8 @@ body:graphql:vars { "outgoing": {"endpoint": "http://peer-backend:3002", "authToken": "test"} }, "maxPacketAmount": 1000, - "liquidityThreshold": 100 + "liquidityThresholdLow": 100 + "liquidityThresholdHigh": 500 } } } diff --git a/bruno/collections/Rafiki/Sample Webhook Events/Asset Liquidity Low.bru b/bruno/collections/Rafiki/Sample Webhook Events/Asset Liquidity Low.bru index a20ffb085f..4812aedd36 100644 --- a/bruno/collections/Rafiki/Sample Webhook Events/Asset Liquidity Low.bru +++ b/bruno/collections/Rafiki/Sample Webhook Events/Asset Liquidity Low.bru @@ -21,7 +21,8 @@ body:json { "code": "EUR", "scale": 2 }, - "liquidityThreshold": "10000", + "liquidityThresholdLow": "10000", + "liquidityThresholdHigh": "1000000", "balance": "9980" } } diff --git a/bruno/collections/Rafiki/Sample Webhook Events/Peer Liquidity Low.bru b/bruno/collections/Rafiki/Sample Webhook Events/Peer Liquidity Low.bru index 3f25aab70c..e9b528ca7f 100644 --- a/bruno/collections/Rafiki/Sample Webhook Events/Peer Liquidity Low.bru +++ b/bruno/collections/Rafiki/Sample Webhook Events/Peer Liquidity Low.bru @@ -21,7 +21,8 @@ body:json { "code": "USD", "scale": 2 }, - "liquidityThreshold": "10000", + "liquidityThresholdLow": "10000", + "liquidityThresholdHigh": "1000000", "balance": "9850" } } From 750cb07979384a96b284ff57cc70e1e01ecd46d0 Mon Sep 17 00:00:00 2001 From: golobitch Date: Thu, 7 Nov 2024 22:08:45 +0100 Subject: [PATCH 8/8] docs(bruno): add webhook event samples for asset and peer liquidity high --- .../Asset Liquidity High.bru | 32 +++++++++++++++++++ .../Peer Liquidity High.bru | 32 +++++++++++++++++++ .../Peer Liquidity Low.bru | 5 ++- .../Wallet Address Web Monetization.bru | 2 +- .../generated/graphql.ts | 4 ++- .../src/graphql/generated/graphql.schema.json | 14 +++++++- .../backend/src/graphql/generated/graphql.ts | 4 ++- packages/backend/src/graphql/schema.graphql | 4 ++- packages/frontend/app/generated/graphql.ts | 4 ++- .../src/generated/graphql.ts | 4 ++- test/integration/lib/generated/graphql.ts | 4 ++- 11 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 bruno/collections/Rafiki/Sample Webhook Events/Asset Liquidity High.bru create mode 100644 bruno/collections/Rafiki/Sample Webhook Events/Peer Liquidity High.bru diff --git a/bruno/collections/Rafiki/Sample Webhook Events/Asset Liquidity High.bru b/bruno/collections/Rafiki/Sample Webhook Events/Asset Liquidity High.bru new file mode 100644 index 0000000000..c65494efe1 --- /dev/null +++ b/bruno/collections/Rafiki/Sample Webhook Events/Asset Liquidity High.bru @@ -0,0 +1,32 @@ +meta { + name: Asset Liquidity High + type: http + seq: 9 +} + +post { + url: {{cloudNineWalletWebhookUrl}} + body: json + auth: none +} + +body:json { + { + "id": "{{uuid}}", + "type": "asset.liquidity_low", + "data": { + "id": "{{assetId}}", + "asset": { + "id": "{{assetId}}", + "code": "EUR", + "scale": 2 + }, + "liquidityThresholdHigh": "9950", + "balance": "9980" + } + } +} + +script:pre-request { + bru.setVar('uuid', require("uuid").v4()); +} \ No newline at end of file diff --git a/bruno/collections/Rafiki/Sample Webhook Events/Peer Liquidity High.bru b/bruno/collections/Rafiki/Sample Webhook Events/Peer Liquidity High.bru new file mode 100644 index 0000000000..f2efb15f06 --- /dev/null +++ b/bruno/collections/Rafiki/Sample Webhook Events/Peer Liquidity High.bru @@ -0,0 +1,32 @@ +meta { + name: Peer Liquidity High + type: http + seq: 11 +} + +post { + url: {{cloudNineWalletWebhookUrl}} + body: json + auth: none +} + +body:json { + { + "id": "{{uuid}}", + "type": "peer.liquidity_low", + "data": { + "id": "{{peerId}}", + "asset": { + "id": "{{assetId}}", + "code": "USD", + "scale": 2 + }, + "liquidityThresholdHigh": "9800", + "balance": "9850" + } + } +} + +script:pre-request { + bru.setVar('uuid', require("uuid").v4()); +} diff --git a/bruno/collections/Rafiki/Sample Webhook Events/Peer Liquidity Low.bru b/bruno/collections/Rafiki/Sample Webhook Events/Peer Liquidity Low.bru index e9b528ca7f..888af1dde6 100644 --- a/bruno/collections/Rafiki/Sample Webhook Events/Peer Liquidity Low.bru +++ b/bruno/collections/Rafiki/Sample Webhook Events/Peer Liquidity Low.bru @@ -1,7 +1,7 @@ meta { name: Peer Liquidity Low type: http - seq: 9 + seq: 10 } post { @@ -21,8 +21,7 @@ body:json { "code": "USD", "scale": 2 }, - "liquidityThresholdLow": "10000", - "liquidityThresholdHigh": "1000000", + "liquidityThreshold": "10000", "balance": "9850" } } diff --git a/bruno/collections/Rafiki/Sample Webhook Events/Wallet Address Web Monetization.bru b/bruno/collections/Rafiki/Sample Webhook Events/Wallet Address Web Monetization.bru index 17b4c390e7..1610d5db0e 100644 --- a/bruno/collections/Rafiki/Sample Webhook Events/Wallet Address Web Monetization.bru +++ b/bruno/collections/Rafiki/Sample Webhook Events/Wallet Address Web Monetization.bru @@ -1,7 +1,7 @@ meta { name: Wallet Address Web Monetization type: http - seq: 10 + seq: 12 } post { diff --git a/localenv/mock-account-servicing-entity/generated/graphql.ts b/localenv/mock-account-servicing-entity/generated/graphql.ts index da9f49993c..2a52305733 100644 --- a/localenv/mock-account-servicing-entity/generated/graphql.ts +++ b/localenv/mock-account-servicing-entity/generated/graphql.ts @@ -243,8 +243,10 @@ export type CreateOrUpdatePeerByUrlInput = { assetId: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if peer liquidity is higher than this value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if peer liquidity falls below this value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** Amount of liquidity to deposit for the peer. */ liquidityToDeposit?: InputMaybe; /** Maximum packet amount that the peer accepts. */ diff --git a/packages/backend/src/graphql/generated/graphql.schema.json b/packages/backend/src/graphql/generated/graphql.schema.json index 159433ccdc..77b176bca6 100644 --- a/packages/backend/src/graphql/generated/graphql.schema.json +++ b/packages/backend/src/graphql/generated/graphql.schema.json @@ -1391,7 +1391,19 @@ "deprecationReason": null }, { - "name": "liquidityThreshold", + "name": "liquidityThresholdHigh", + "description": "A webhook event will notify the Account Servicing Entity if peer liquidity is higher than this value.", + "type": { + "kind": "SCALAR", + "name": "UInt64", + "ofType": null + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "liquidityThresholdLow", "description": "A webhook event will notify the Account Servicing Entity if peer liquidity falls below this value.", "type": { "kind": "SCALAR", diff --git a/packages/backend/src/graphql/generated/graphql.ts b/packages/backend/src/graphql/generated/graphql.ts index da9f49993c..2a52305733 100644 --- a/packages/backend/src/graphql/generated/graphql.ts +++ b/packages/backend/src/graphql/generated/graphql.ts @@ -243,8 +243,10 @@ export type CreateOrUpdatePeerByUrlInput = { assetId: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if peer liquidity is higher than this value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if peer liquidity falls below this value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** Amount of liquidity to deposit for the peer. */ liquidityToDeposit?: InputMaybe; /** Maximum packet amount that the peer accepts. */ diff --git a/packages/backend/src/graphql/schema.graphql b/packages/backend/src/graphql/schema.graphql index fa6d4a7e23..fa637c0b4b 100644 --- a/packages/backend/src/graphql/schema.graphql +++ b/packages/backend/src/graphql/schema.graphql @@ -423,7 +423,9 @@ input CreateOrUpdatePeerByUrlInput { "Internal name for the peer, used to override auto-peering default names." name: String "A webhook event will notify the Account Servicing Entity if peer liquidity falls below this value." - liquidityThreshold: UInt64 + liquidityThresholdLow: UInt64 + "A webhook event will notify the Account Servicing Entity if peer liquidity is higher than this value." + liquidityThresholdHigh: UInt64 "Amount of liquidity to deposit for the peer." liquidityToDeposit: UInt64 "Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency)." diff --git a/packages/frontend/app/generated/graphql.ts b/packages/frontend/app/generated/graphql.ts index 70771b5aae..294bfd295b 100644 --- a/packages/frontend/app/generated/graphql.ts +++ b/packages/frontend/app/generated/graphql.ts @@ -243,8 +243,10 @@ export type CreateOrUpdatePeerByUrlInput = { assetId: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if peer liquidity is higher than this value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if peer liquidity falls below this value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** Amount of liquidity to deposit for the peer. */ liquidityToDeposit?: InputMaybe; /** Maximum packet amount that the peer accepts. */ diff --git a/packages/mock-account-service-lib/src/generated/graphql.ts b/packages/mock-account-service-lib/src/generated/graphql.ts index da9f49993c..2a52305733 100644 --- a/packages/mock-account-service-lib/src/generated/graphql.ts +++ b/packages/mock-account-service-lib/src/generated/graphql.ts @@ -243,8 +243,10 @@ export type CreateOrUpdatePeerByUrlInput = { assetId: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if peer liquidity is higher than this value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if peer liquidity falls below this value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** Amount of liquidity to deposit for the peer. */ liquidityToDeposit?: InputMaybe; /** Maximum packet amount that the peer accepts. */ diff --git a/test/integration/lib/generated/graphql.ts b/test/integration/lib/generated/graphql.ts index da9f49993c..2a52305733 100644 --- a/test/integration/lib/generated/graphql.ts +++ b/test/integration/lib/generated/graphql.ts @@ -243,8 +243,10 @@ export type CreateOrUpdatePeerByUrlInput = { assetId: Scalars['String']['input']; /** Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency). */ idempotencyKey?: InputMaybe; + /** A webhook event will notify the Account Servicing Entity if peer liquidity is higher than this value. */ + liquidityThresholdHigh?: InputMaybe; /** A webhook event will notify the Account Servicing Entity if peer liquidity falls below this value. */ - liquidityThreshold?: InputMaybe; + liquidityThresholdLow?: InputMaybe; /** Amount of liquidity to deposit for the peer. */ liquidityToDeposit?: InputMaybe; /** Maximum packet amount that the peer accepts. */