Skip to content

Commit

Permalink
Update Unified API Anchorage examples (#106)
Browse files Browse the repository at this point in the history
* Migration, data is persisted per-connection (#88)

* schema migration to scope all data per connection

* data migration script

* fix provider type per connection

* unique keys order

* fixed failing tests

* added connectionId to mock data in transfer and sync tests

* handle known destination connections to connectionId

* abstract away single tie to connection change from known destinations

* filter on correct row in wallet repository

* updated migration script to duplicate provider resources

* updates existing transfers

* Pass through known destination (#90)

* Add CSR public key format for FB connection (#92)

* Add CSR public key format for FB connection

* Add optional CSR format in the public key DTO

* Add describe block

* Pin node-forge version

* Remove wallet connections list (#95)

* Scope operations by connection (#96)

* Scope operations by connection

* Scope sync operations by connection

* Fix supertest wrapper to work with query method

* Use signed request util in the wallet E2E tests

* Fix flaky tests

* Add back connection list endpoint

* Fix address E2E tests

* Bump SDK version

* Add network and asset endpoints in the SDK

* Adding BitGo connection

* ScopedSync by RawAccounts (#84)

* duplicated sync, poc working

* fixed rebase conflicts and format

* cleanup rebase merge, correctly insert connectionId on scope sync

* fireblocks scoped-sync updates

* use vault label

* added updates to anchorage's scoped sync service

* add tests on anchorage scoped sync

* cleaned up anchorage scope sync tests

* map fireblocks assetWallets to network specific accounts

* fixed not found test expectation

* test fireblocks scoped sync

* fixed rebase conflicts

* changed externalId standard

* Adding Raw Accounts endpoint & Assed/Network bootstrap

* Adding includeAddress query param so fireblocks does not always fetch addresses

* Cache assets & refactor network cache (#98)

* Cache asset

Refactor network to use cache manager

* Remove draft config

* Pin cache-manager version

* Lower case cache keys

* Fix findAll method

* Endpoints to fetch scoped-syncs (#101)

* scoped sync persists stringified raw accounts

* add status fetching endpoints for scoped syncs

* use prismaservice methods to json stringify and parse

* Minor fixes before release connection-specific (#102)

* Add back the nested wallet and account endpoints in the connection

* Minor fix on scope sync logs

Connection ID is mandatory in the Vault Client

* connect a new connection triggers full sync on anchorage (#103)

* connect a new connection triggers full sync on anchorage

* fix test excpetation for empty raw accounts on anchorage

* Add listProviderRawAccounts method in the Vault SDK

* removed references to 'sync' and dropped table

* removed syncService from connection test

* deleted sync e2e test

* re-generated sdk without scoped sync methods

* Revert "re-generated sdk without scoped sync methods"

This reverts commit 66dccdfa2bd909d2f6c015b153e87c3728004dd2.

* Revert "removed references to 'sync' and dropped table"

This reverts commit 9c2cd022b95439ce9bc4a45a44d7c67da0cdc535.

* Revert "deleted sync e2e test"

This reverts commit 2f4a252650fb871662cbe92ba149aa9e2dc5d0c6.

* Revert "removed syncService from connection test"

This reverts commit 450ece6a34ec5ef04bf170c176f56de4e71b97c9.

* removed sync functionality except list

* removed deprecated imports

---------

Co-authored-by: Ptroger <[email protected]>
Co-authored-by: Pierre Troger <[email protected]>

* Feature/nar 2059 make scoped sync quicker (#104)

* fireblocks query uniquely scoped accounts, handle duplicated rawAccounts

* optimized queries per wallet

* anchorage scoped syncs swallow not found errors

* batch requests to control rate limiting

* removed connection-sync event handler

* manage error handling in promiseAllSettled

* use httpstatus

* expect precisely one account

* Asset fallback (#105)

* Asset fallback for Anchorage and Fireblocks

* Add TransferAssetService

* Remove findTransferAsset from AssetService

* Remove fallback type

* Refactor TransferAssetService

* Fix integration test types

* Fix E2E tests

* Fix provider

* Update Unified API examples

* Remove pagination

* Update README

* Update quickstart README

* Quickstart, Select Accounts section

* Adding `.` before quickstart readme so it orders first in gist

* Update SDK version

* Ignore config.*.yaml files in git

---------

Co-authored-by: Ptroger <[email protected]>
Co-authored-by: Matt Schoch <[email protected]>
Co-authored-by: Pierre Troger <[email protected]>
  • Loading branch information
4 people authored Jan 27, 2025
1 parent 8faa5ef commit d1f17e5
Show file tree
Hide file tree
Showing 14 changed files with 208 additions and 388 deletions.
3 changes: 2 additions & 1 deletion examples/unified-api/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
node_modules
config.json
config.yaml
config.*.yaml
38 changes: 33 additions & 5 deletions examples/unified-api/1-connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { config, setConfig, vaultClient } from './vault.client'
dotenv.config()

const main = async () => {
const apiKey = config.connectionApiKey
const privateKey = config.connectionPrivateKey
const url = config.connectionUrl
const apiKey = config.connection.credentials.apiKey
const privateKey = config.connection.credentials.privateKey
const url = config.connection.url
const credentials = {
apiKey,
privateKey
Expand All @@ -22,12 +22,40 @@ const main = async () => {
data: { url, encryptedCredentials, provider: 'anchorage' }
})

const rawAccounts = await vaultClient.listProviderRawAccounts({
connectionId: connection.data.connectionId
})

console.log(
'Syncing raw accounts',
rawAccounts.data.map((rawAccount) => `${rawAccount.label} - ${rawAccount.externalId}`)
)

await vaultClient.scopedSync({
data: {
connectionId: connection.data.connectionId,
rawAccounts: rawAccounts.data
}
})

// Save the connectionId to the config file
setConfig('connectionId', connection.data.connectionId)
setConfig('connection.id', connection.data.connectionId)

console.dir(connection.data)
}

main()
.then(() => console.log('done'))
.catch(console.error)
.catch((error) => {
if ('response' in error) {
console.dir(
{
status: error.response?.status,
body: error.response?.data
},
{ depth: null }
)
} else {
console.error('Error', error)
}
})
34 changes: 27 additions & 7 deletions examples/unified-api/2-read-wallets.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
import { AxiosError } from 'axios'
import { config, vaultClient } from './vault.client'

const main = async () => {
if (!config.connectionId) {
console.error('No connectionId found in config.json. Please connect first.')
if (!config.connection.id) {
console.error('No connection.id found in config.yaml. Please connect first.')
process.exit(1)
}

const { data, page } = await vaultClient.listProviderWallets({
connectionId: config.connectionId
const { data } = await vaultClient.listProviderWallets({
connectionId: config.connection.id,
pagination: { limit: 100 }
})

console.dir(
data.map((wallet) => ({
label: wallet.label,
walletId: wallet.walletId,
provider: wallet.provider,
externalId: wallet.externalId
}))
externalId: wallet.externalId,
accounts: (wallet.accounts || []).map((account) => ({
accountId: account.accountId,
networkId: account.networkId,
label: account.label
}))
})),
{ depth: null }
)
}

main()
.then(() => console.log('done'))
.catch(console.error)
.catch((error) => {
if (error instanceof AxiosError) {
console.dir(
{
status: error.response?.status,
body: error.response?.data
},
{ depth: null }
)
} else {
console.error(error)
}
})
36 changes: 20 additions & 16 deletions examples/unified-api/3-read-accounts.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import { AxiosError } from 'axios'
import { config, vaultClient } from './vault.client'

const main = async () => {
if (!config.connectionId) {
console.error('No connectionId found in config.json. Please connect first.')
if (!config.connection.id) {
console.error('No connection.id found in config.yaml. Please connect first.')
process.exit(1)
}

const { data, page } = await vaultClient.listProviderAccounts({
connectionId: config.connectionId
const { data } = await vaultClient.listProviderAccounts({
connectionId: config.connection.id,
pagination: { limit: 100 }
})

console.dir(
data.map((account) => ({
label: account.label,
accountId: account.accountId,
provider: account.provider,
externalId: account.externalId,
networkId: account.networkId,
walletId: account.walletId,
addresses: account?.addresses?.map((address) => address.address)
}))
)
console.dir(data, { depth: null })
}

main()
.then(() => console.log('done'))
.catch(console.error)
.catch((error) => {
if (error instanceof AxiosError) {
console.dir(
{
status: error.response?.status,
body: error.response?.data
},
{ depth: null }
)
} else {
console.error(error)
}
})
21 changes: 17 additions & 4 deletions examples/unified-api/4-create-transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const main = async () => {
? { address: config.destinationAddress }
: null

if (!config.connectionId || !config.sourceId || !destination || !config.assetId || !config.amount) {
if (!config.connection.id || !config.sourceId || !destination || !config.assetId || !config.amount) {
console.error('Please provide transfer parameters in config.json')
process.exit(1)
}

const initiatedTransfer = await vaultClient.sendTransfer({
connectionId: config.connectionId,
connectionId: config.connection.id,
data: {
idempotenceId: uuid(),
source: {
Expand Down Expand Up @@ -56,9 +56,10 @@ const main = async () => {

// Poll transfer status until it's no longer processing
let transfer

do {
transfer = await vaultClient.getTransfer({
connectionId: config.connectionId,
connectionId: config.connection.id,
transferId: initiatedTransfer.data.transferId
})

Expand All @@ -74,4 +75,16 @@ const main = async () => {

main()
.then(() => console.log('done'))
.catch(console.error)
.catch((error) => {
if ('response' in error) {
console.dir(
{
status: error.response?.status,
body: error.response?.data
},
{ depth: null }
)
} else {
console.error('Error', error)
}
})
26 changes: 0 additions & 26 deletions examples/unified-api/5-sync.ts

This file was deleted.

18 changes: 0 additions & 18 deletions examples/unified-api/6-known-destinations.ts

This file was deleted.

Loading

0 comments on commit d1f17e5

Please sign in to comment.