Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support peer service adding initial amount of liquidity #1882

Merged
merged 139 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 128 commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
4f458ba
feat(backend): WIP - add feeid to quote table
BlairCurrey Aug 15, 2023
7dc1d60
refactor(backend): rename quote gql field
BlairCurrey Aug 15, 2023
e39bb88
Merge branch 'main' into bc/1639/add-fees-to-quote
BlairCurrey Aug 18, 2023
35ed878
Merge branch 'main' into bc/1639/add-fees-to-quote
BlairCurrey Aug 21, 2023
752df9b
fix(backend): add fee relation
BlairCurrey Aug 21, 2023
088058b
feat(backend): WIP calculate fees in quote create
BlairCurrey Aug 21, 2023
5cce896
refactor(backend): rename gql quote field
BlairCurrey Aug 23, 2023
7bc19df
fix(backend): rm unused with graph fetched
BlairCurrey Aug 23, 2023
8383ed5
Merge branch 'main' into bc/1639/add-fees-to-quote
BlairCurrey Aug 23, 2023
a0b2c30
Merge branch 'main' into bc/1639/add-fees-to-quote
BlairCurrey Aug 28, 2023
874bcf6
feat(backend): move fee calculation to quote service
BlairCurrey Aug 30, 2023
d58532c
fix(backend): use quote error
BlairCurrey Aug 31, 2023
4026c23
Merge branch 'main' into bc/1639/add-fees-to-quote
BlairCurrey Aug 31, 2023
d4e0bdf
Merge branch 'main' into bc/1639/add-fees-to-quote
BlairCurrey Sep 2, 2023
9635035
fix(backend): rm unused fn
BlairCurrey Sep 2, 2023
1fd63fd
refactor(backend): rename quote send amount value
BlairCurrey Sep 4, 2023
dc88ba8
refactor(backend): rename quote send amount to debit amount
BlairCurrey Sep 4, 2023
e393681
refactor(backend): rename out payment send amount to debit
BlairCurrey Sep 4, 2023
9a09017
chore(backend): format
BlairCurrey Sep 4, 2023
393198b
chore(documentation): update gql docs
BlairCurrey Sep 4, 2023
c5ea21d
fix(backend,localenv): trx amount
BlairCurrey Sep 4, 2023
46cb2cd
fix(backend): handle cross currency fee in quote
BlairCurrey Sep 6, 2023
28f096a
Merge branch 'main' into bc/1639/add-fees-to-quote
BlairCurrey Sep 6, 2023
4c3ae8e
refactor: update spec and rename more fields
BlairCurrey Sep 7, 2023
93a0da7
fix(backend): outgoing limit test
BlairCurrey Sep 7, 2023
4904216
refactor(backend): rename limits field
BlairCurrey Sep 7, 2023
198b4ea
rename sendAmount to debitAmount
BlairCurrey Sep 7, 2023
44e2884
fix(localenv): postman ecommerce flow
BlairCurrey Sep 7, 2023
75b328a
Merge branch 'main' into bc/1639/add-fees-to-quote
BlairCurrey Sep 7, 2023
56bd689
fix(backend): remove useless checks
BlairCurrey Sep 7, 2023
84c8421
chore(auth): update open-payments package version
BlairCurrey Sep 7, 2023
3a1b353
chore(backend): rm commented out code
BlairCurrey Sep 8, 2023
b33aed1
fix(auth): migration to rename jsonb col
BlairCurrey Sep 8, 2023
fc6d045
Merge branch 'main' into bc/1639/add-fees-to-quote
BlairCurrey Sep 8, 2023
316e7f7
chore(auth): format
BlairCurrey Sep 8, 2023
a74de35
feat: add DuplicatePeer error
mkurapov Sep 11, 2023
62577f3
fix: pass in peerService to autoPeeringService
mkurapov Sep 8, 2023
01cfbf3
chore: update diff
mkurapov Sep 11, 2023
3677482
chore: add to peer resolver test
mkurapov Sep 11, 2023
2ba0761
feat: accept peering request
mkurapov Sep 11, 2023
7e2df45
fix(backend): remove asset join
BlairCurrey Sep 11, 2023
6a5bf5b
refactor(backend): remove variable assignment
BlairCurrey Sep 11, 2023
e361481
feat: wire up router for auto peering
mkurapov Sep 12, 2023
fc27cef
fix: update auto peering service
mkurapov Sep 12, 2023
18f9bf3
feat: correct config
mkurapov Sep 12, 2023
221c269
config: update auto peering routes & errors
mkurapov Sep 12, 2023
3e74ebc
chore: prettier
mkurapov Sep 12, 2023
6ee3165
Merge branch 'mk/1761/duplicate-peer' into mk/1802/accept-peering-req…
mkurapov Sep 12, 2023
6203c79
feat: add createPeerByUrl mutation to schema
mkurapov Sep 12, 2023
51a6bfc
feat: add initiatePeeringRequest method to auto peering service
mkurapov Sep 12, 2023
0609169
feat: add createPeerByUrl resolver
mkurapov Sep 12, 2023
d12bc7b
chore: fix lint
mkurapov Sep 12, 2023
46db7e7
Merge branch 'main' into mk/1765/auto-peering-mutation
mkurapov Sep 12, 2023
d28883f
chore: add generate graphql files
mkurapov Sep 12, 2023
b7a7ba6
Merge branch 'main' into mk/1802/accept-peering-request
mkurapov Sep 12, 2023
cc81785
Merge branch 'mk/1802/accept-peering-request' into mk/1765/auto-peeri…
mkurapov Sep 12, 2023
139426c
Merge branch 'main' into mk/1761/duplicate-peer
mkurapov Sep 12, 2023
788a203
Merge branch 'mk/1761/duplicate-peer' into mk/1802/accept-peering-req…
mkurapov Sep 12, 2023
f523d87
chore: update graphql schema comment
mkurapov Sep 12, 2023
3a69dd6
fix: add type to /post peer error
mkurapov Sep 12, 2023
4d98970
feat: add postman request
mkurapov Sep 12, 2023
afa767f
chore: address comments
mkurapov Sep 13, 2023
3ad9a83
Merge branch 'mk/1761/duplicate-peer' into mk/1802/accept-peering-req…
mkurapov Sep 13, 2023
d28da05
Update packages/backend/src/auto-peering/errors.ts
mkurapov Sep 13, 2023
a52658c
Merge branch 'mk/1802/accept-peering-request' of github.com:interledg…
mkurapov Sep 13, 2023
6cb6419
chore: remove axios from app
mkurapov Sep 13, 2023
0ac7e08
Merge branch 'mk/1802/accept-peering-request' into mk/1765/auto-peeri…
mkurapov Sep 13, 2023
d5089e2
chore: add axios to app
mkurapov Sep 13, 2023
1e1d461
chore: fix whitespace
mkurapov Sep 13, 2023
310fce3
feature(backend): change error
BlairCurrey Sep 13, 2023
937e495
Merge branch 'main' into bc/1639/add-fees-to-quote
BlairCurrey Sep 13, 2023
e6f6f34
reactor(documentation): update fee explanation
BlairCurrey Sep 13, 2023
0567cf0
feat: use assetId in getByDestinationAddress
mkurapov Sep 13, 2023
76bceb4
feat: update peer on duplicate peering request
mkurapov Sep 13, 2023
5a1e0c7
Merge branch 'mk/1802/accept-peering-request' into mk/1765/auto-peeri…
mkurapov Sep 13, 2023
de3a256
chore: remove quote url references
BlairCurrey Sep 13, 2023
2079eac
feat: use proper outgoing/incoming http tokens
mkurapov Sep 13, 2023
59015f9
feat: update error during auto-peering request
mkurapov Sep 13, 2023
633ed35
fix(openapi): missing server warning
BlairCurrey Sep 13, 2023
b9910e1
Merge branch 'main' into mk/1802/accept-peering-request
mkurapov Sep 13, 2023
c540606
chore: fix route tests
mkurapov Sep 13, 2023
b0b90c2
feat: support maxPacketAmount and name in peering request
mkurapov Sep 13, 2023
ae971f7
Merge branch 'mk/1802/accept-peering-request' into mk/1765/auto-peeri…
mkurapov Sep 13, 2023
2204d81
chore: add fields to peering request
mkurapov Sep 13, 2023
d3648c1
feat: support maxPacketAmount and name in peering request
mkurapov Sep 13, 2023
ba0f6a9
Merge branch 'mk/1802/accept-peering-request' of github.com:interledg…
mkurapov Sep 13, 2023
733f80a
Merge branch 'mk/1802/accept-peering-request' into mk/1765/auto-peeri…
mkurapov Sep 13, 2023
b4d7b89
feat: default to peer given name if no name provided
mkurapov Sep 13, 2023
069214b
chore: lint
mkurapov Sep 13, 2023
0e9ccf1
fix: remove getter
mkurapov Sep 13, 2023
ae52e0d
Merge branch 'mk/1802/accept-peering-request' into mk/1765/auto-peeri…
mkurapov Sep 13, 2023
bc7c69a
Temporary fix
raducristianpopa Sep 14, 2023
874b7cc
Merge branch 'mk/1802/accept-peering-request' into mk/1765/auto-peeri…
mkurapov Sep 14, 2023
6d3fe2e
Revert "Temporary fix"
mkurapov Sep 14, 2023
05155a8
chore(token-introspection): generate types
BlairCurrey Sep 14, 2023
9619132
Merge branch 'main' into mk/1802/accept-peering-request
mkurapov Sep 14, 2023
7c62a39
Merge branch 'mk/1802/accept-peering-request' into mk/1765/auto-peeri…
mkurapov Sep 14, 2023
0789378
chore: update tests
mkurapov Sep 14, 2023
db49061
refactor(documentation): rename sendAmount to debitAmount
BlairCurrey Sep 14, 2023
8fb0154
Merge branch 'bc/1639/add-fees-to-quote' into mk/1802/accept-peering-…
mkurapov Sep 14, 2023
8e8c1a5
Revert "Merge branch 'bc/1639/add-fees-to-quote' into mk/1802/accept-…
mkurapov Sep 14, 2023
a217d32
ci: test heap bump
mkurapov Sep 14, 2023
66293e5
ci: logheapusage
mkurapov Sep 14, 2023
efb5d04
chore: bump jest
mkurapov Sep 14, 2023
0b803cd
Merge branch 'mk/1802/accept-peering-request' of github.com:interledg…
mkurapov Sep 14, 2023
be95eec
chore: update tests
mkurapov Sep 14, 2023
a7a9f65
chore: update tests
mkurapov Sep 14, 2023
c165506
Merge branch 'mk/1802/accept-peering-request' of github.com:interledg…
mkurapov Sep 14, 2023
0f2b805
Merge branch 'main' into mk/1802/accept-peering-request
mkurapov Sep 14, 2023
8bb493e
Revert "ci: logheapusage"
mkurapov Sep 14, 2023
5e2ac6b
Merge branch 'main' into mk/1765/auto-peering-mutation
mkurapov Sep 14, 2023
d61dca0
Merge branch 'main' into mk/1802/accept-peering-request
mkurapov Sep 14, 2023
67692f3
Merge branch 'mk/1802/accept-peering-request' into mk/1765/auto-peeri…
mkurapov Sep 14, 2023
875642f
Merge branch 'main' into mk/1802/accept-peering-request
mkurapov Sep 14, 2023
9e670aa
Merge branch 'mk/1802/accept-peering-request' into mk/1765/auto-peeri…
mkurapov Sep 14, 2023
10bb608
revert fix
mkurapov Sep 14, 2023
f940eb1
fix: revert pnpm lock
mkurapov Sep 14, 2023
8892ad2
Merge branch 'mk/1802/accept-peering-request' into mk/1765/auto-peeri…
mkurapov Sep 14, 2023
776e8d7
Update mutation request
mkurapov Sep 14, 2023
719f730
feat: allow knex trx to be used in transfer creation
mkurapov Sep 15, 2023
3381713
feat: add initial amount of liquidity in peer service
mkurapov Sep 15, 2023
18cd4ae
feat: add max amount of liquidity during auto-peering
mkurapov Sep 15, 2023
08d556a
feat: support (new) liquidityThreshold param
mkurapov Sep 15, 2023
519c465
Merge branch 'mk/1765/auto-peering-mutation' into mk/1855/add-initial…
mkurapov Sep 15, 2023
2f4cfc9
chore: lint
mkurapov Sep 15, 2023
fb2ef2f
chore: fix test
mkurapov Sep 16, 2023
1b53f92
Update `createPeer` and `createPeerByUrl` mutations in postman
mkurapov Sep 17, 2023
5073f3d
Revert "Update `createPeer` and `createPeerByUrl` mutations in postman"
mkurapov Sep 17, 2023
0965ee0
chore: rename to CreateOrUpdatePeerByUrlInput
mkurapov Sep 18, 2023
0cc8632
feat: update peer on duplicate request
mkurapov Sep 18, 2023
f2e844f
feat: update auto-peering resolver
mkurapov Sep 18, 2023
39c3790
Merge branch 'mk/1765/auto-peering-mutation' into mk/1855/add-initial…
mkurapov Sep 18, 2023
19ec601
Merge branch 'main' into mk/1765/auto-peering-mutation
mkurapov Sep 19, 2023
f18a7b8
Merge branch 'main' into mk/1802/accept-peering-request
mkurapov Sep 19, 2023
b35f284
Merge branch 'mk/1802/accept-peering-request' into mk/1765/auto-peeri…
mkurapov Sep 19, 2023
6c63b76
Merge branch 'mk/1765/auto-peering-mutation' into mk/1855/add-initial…
mkurapov Sep 19, 2023
ea056db
Update mutation
mkurapov Sep 19, 2023
ce65b7e
Merge branch 'mk/1765/auto-peering-mutation' into mk/1855/add-initial…
mkurapov Sep 19, 2023
b287606
Merge branch 'main' into mk/1855/add-initial-peer-liquidity
mkurapov Sep 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions localenv/mock-account-servicing-entity/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions packages/backend/src/accounting/psql/ledger-account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ export async function createAccount(

export async function getLiquidityAccount(
deps: ServiceDependencies,
accountRef: string
accountRef: string,
trx?: TransactionOrKnex
): Promise<LedgerAccount | undefined> {
return LedgerAccount.query(deps.knex)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious what the intent of adding a transaction here is, since these look like they're just reading the database.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are creating the account and reading it in the same transaction, we also need it here: https://github.com/interledger/rafiki/pull/1882/files#diff-4b287690c751dd38900f4202d32f2e0c023b378614a7363fbf791226fa926f45R152-R167

return LedgerAccount.query(trx ?? deps.knex)
.findOne({ accountRef })
.whereNot({ type: LedgerAccountType.SETTLEMENT })
}

export async function getSettlementAccount(
deps: ServiceDependencies,
accountRef: string
accountRef: string,
trx?: TransactionOrKnex
): Promise<LedgerAccount | undefined> {
return LedgerAccount.query(deps.knex)
return LedgerAccount.query(trx ?? deps.knex)
.findOne({ accountRef })
.where({ type: LedgerAccountType.SETTLEMENT })
}
20 changes: 11 additions & 9 deletions packages/backend/src/accounting/psql/ledger-transfer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,27 @@ function validateTransferStateUpdate(

export async function createTransfers(
deps: ServiceDependencies,
transfers: CreateLedgerTransferArgs[]
transfers: CreateLedgerTransferArgs[],
trx?: TransactionOrKnex
): Promise<CreateTransfersResult> {
const trx = await deps.knex.transaction()
const transaction =
(await trx?.transaction()) ?? (await deps.knex.transaction())

const errors: CreateTransferError[] = []
const results: LedgerTransfer[] = []

for (const [index, transfer] of transfers.entries()) {
const error = await validateTransfer(deps, transfer, trx)
const error = await validateTransfer(deps, transfer, transaction)

if (error) {
errors.push({ index, error })
break
}

try {
const createdTransfer = await LedgerTransfer.query(trx).insertAndFetch(
prepareTransfer(transfer)
)
const createdTransfer = await LedgerTransfer.query(
transaction
).insertAndFetch(prepareTransfer(transfer))

results.push(createdTransfer)
} catch (error) {
Expand All @@ -183,16 +185,16 @@ export async function createTransfers(
}

if (errors.length > 0) {
await trx.rollback()
await transaction.rollback()
return { results: [], errors }
}

try {
await trx.commit()
await transaction.commit()

return { results, errors: [] }
} catch (error) {
await trx.rollback()
await transaction.rollback()

const errorMessage = 'Could not create transfer(s)'
deps.logger.error(
Expand Down
11 changes: 6 additions & 5 deletions packages/backend/src/accounting/psql/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function createAccountingService(
getAccountsTotalReceived(deps, accountRefs),
getSettlementBalance: (ledger) => getSettlementBalance(deps, ledger),
createTransfer: (options) => createTransfer(deps, options),
createDeposit: (transfer) => createAccountDeposit(deps, transfer),
createDeposit: (transfer, trx) => createAccountDeposit(deps, transfer, trx),
createWithdrawal: (transfer) => createAccountWithdrawal(deps, transfer),
postWithdrawal: (withdrawalRef) => postTransfers(deps, [withdrawalRef]),
voidWithdrawal: (withdrawalRef) => voidTransfers(deps, [withdrawalRef])
Expand Down Expand Up @@ -290,7 +290,8 @@ function handleTransferCreateResults(

async function createAccountDeposit(
deps: ServiceDependencies,
args: Deposit
args: Deposit,
trx?: TransactionOrKnex
): Promise<void | TransferError> {
const {
id: transferRef,
Expand All @@ -302,8 +303,8 @@ async function createAccountDeposit(
} = args

const [account, settlementAccount] = await Promise.all([
getLiquidityAccount(deps, accountRef),
getSettlementAccount(deps, assetRef)
getLiquidityAccount(deps, accountRef, trx),
getSettlementAccount(deps, assetRef, trx)
])

if (!account) {
Expand All @@ -322,7 +323,7 @@ async function createAccountDeposit(
type: LedgerTransferType.DEPOSIT
}

const { errors } = await createTransfers(deps, [transfer])
const { errors } = await createTransfers(deps, [transfer], trx)

if (errors[0]) {
return errors[0].error
Expand Down
5 changes: 4 additions & 1 deletion packages/backend/src/accounting/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ export interface AccountingService {
getAccountsTotalReceived(ids: string[]): Promise<(bigint | undefined)[]>
getSettlementBalance(ledger: number): Promise<bigint | undefined>
createTransfer(options: TransferOptions): Promise<Transaction | TransferError>
createDeposit(deposit: Deposit): Promise<void | TransferError>
createDeposit(
deposit: Deposit,
trx?: TransactionOrKnex
): Promise<void | TransferError>
createWithdrawal(withdrawal: Withdrawal): Promise<void | TransferError>
postWithdrawal(id: string): Promise<void | TransferError>
voidWithdrawal(id: string): Promise<void | TransferError>
Expand Down
5 changes: 3 additions & 2 deletions packages/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import { FeeService } from './fee/service'
import { AutoPeeringService } from './auto-peering/service'
import { AutoPeeringRoutes } from './auto-peering/routes'
import { Rafiki as ConnectorApp } from './connector/core'
import { AxiosInstance } from 'axios'

export interface AppContextData {
logger: Logger
Expand Down Expand Up @@ -177,6 +178,7 @@ const PAYMENT_POINTER_PATH = '/:paymentPointerPath+'
export interface AppServices {
logger: Promise<Logger>
knex: Promise<Knex>
axios: Promise<AxiosInstance>
config: Promise<IAppConfig>
httpTokenService: Promise<HttpTokenService>
assetService: Promise<AssetService>
Expand Down Expand Up @@ -487,8 +489,7 @@ export class App {
const router = new Router<DefaultState, AppContext>()

router.use(bodyParser())

router.get('/', autoPeeringRoutes.get)
router.post('/', autoPeeringRoutes.acceptPeerRequest)

koa.use(router.routes())

Expand Down
39 changes: 39 additions & 0 deletions packages/backend/src/auto-peering/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export enum AutoPeeringError {
InvalidIlpConfiguration = 'InvalidIlpConfiguration',
InvalidPeerIlpConfiguration = 'InvalidPeerIlpConfiguration',
UnknownAsset = 'UnknownAsset',
PeerUnsupportedAsset = 'PeerUnsupportedAsset',
InvalidPeerUrl = 'InvalidPeerUrl',
InvalidPeeringRequest = 'InvalidPeeringRequest',
DuplicatePeer = 'DuplicatePeer'
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
export const isAutoPeeringError = (o: any): o is AutoPeeringError =>
Object.values(AutoPeeringError).includes(o)

export const errorToCode: {
[key in AutoPeeringError]: number
} = {
[AutoPeeringError.InvalidIlpConfiguration]: 400,
[AutoPeeringError.InvalidPeerIlpConfiguration]: 400,
[AutoPeeringError.UnknownAsset]: 404,
[AutoPeeringError.PeerUnsupportedAsset]: 400,
[AutoPeeringError.InvalidPeerUrl]: 400,
[AutoPeeringError.InvalidPeeringRequest]: 400,
[AutoPeeringError.DuplicatePeer]: 409
}

export const errorToMessage: {
[key in AutoPeeringError]: string
} = {
[AutoPeeringError.InvalidIlpConfiguration]:
'The ILP configuration is misconfigured',
[AutoPeeringError.InvalidPeerIlpConfiguration]: `Requested peer's ILP configuration is misconfigured`,
[AutoPeeringError.UnknownAsset]: 'Unknown asset',
[AutoPeeringError.PeerUnsupportedAsset]: 'Peer does not support asset',
[AutoPeeringError.InvalidPeerUrl]:
'Peer URL is invalid or peer does not support auto-peering',
[AutoPeeringError.InvalidPeeringRequest]: 'Invalid peering request',
[AutoPeeringError.DuplicatePeer]: 'Duplicate peer'
}
Loading