Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion lib/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TokenResult } from 'ambire-common/dist/src/libs/portfolio/interfaces'

export type PortfolioLibToken = Pick<
TokenResult,
'symbol' | 'address' | 'networkId' | 'decimals' | 'amount' | 'priceIn'
'symbol' | 'address' | 'chainId' | 'decimals' | 'amount' | 'priceIn'
>
export type NetworkPortfolioLibResponse = {
tokens: PortfolioLibToken[]
Expand Down
10 changes: 6 additions & 4 deletions lib/utils/portfolio.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fetch from 'node-fetch'
import { networks } from 'ambire-common/dist/src/consts/networks'
import { Network } from 'ambire-common/dist/src/interfaces/network'
import { getRpcProvider } from 'ambire-common/dist/src/services/provider/getRpcProvider'
import { Portfolio } from 'ambire-common/dist/src/libs/portfolio'
import { llmMockProcess } from './llm/mockedAI'
Expand All @@ -14,9 +15,9 @@ import {

export async function getPortfolioForNetwork(
address: string,
networkId: string
networkId: string | bigint
): Promise<NetworkPortfolioLibResponse> {
const network = networks.find((n: any) => n.id === networkId)
const network = networks.find((n: Network) => n.chainId === networkId || n.name === networkId)
if (!network) throw new Error(`Failed to find ${networkId} in configured networks`)

const provider = getRpcProvider(network.rpcUrls, network.chainId)
Expand All @@ -34,13 +35,14 @@ export async function getPortfolioVelcroV3(address: string): Promise<PortfolioFo
const output: PortfolioForNetwork[] = []

const responses = await Promise.all(
networks.map((network) => getPortfolioForNetwork(address, network.id))
networks.map((network) => getPortfolioForNetwork(address, network.chainId))
)

for (const resp of responses) {
const tokens = resp.tokens
.filter((t) => t.amount > 0n)
.map((t) => {
const network = networks.find((n) => n.chainId === t.chainId) as Network
const balance = Number(t.amount) / Math.pow(10, t.decimals)
const priceUSD = (t.priceIn.find((p) => p.baseCurrency === 'usd') || { price: 0 })
.price
Expand All @@ -49,7 +51,7 @@ export async function getPortfolioVelcroV3(address: string): Promise<PortfolioFo
symbol: t.symbol,
balance,
balanceUSD: balance * priceUSD,
network: t.networkId,
network: network.name,
address: t.address
}
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"dependencies": {
"@google/generative-ai": "^0.21.0",
"ambire-common": "github:AmbireTech/ambire-common#677651a49c49cf49ff7864bd1bd6dc32b580c789",
"ambire-common": "github:AmbireTech/ambire-common#378bba59e18430bfcc411504ca3dbc607f32d214",
"openai": "^4.85.4",
"tslib": "^2.8.1",
"zod": "^3.24.2"
Expand Down
10 changes: 5 additions & 5 deletions test/unit/portfolio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const mockedNetworkPortfolioResult: NetworkPortfolioLibResponse = {
{
symbol: 'USDC',
address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
networkId: 'ethereum',
chainId: 1n,
decimals: 6,
amount: 50000000n,
priceIn: [
Expand Down Expand Up @@ -55,7 +55,7 @@ const mockedLlmOutput: LlmProcessOutput = {
jest.mock('ambire-common/dist/src/consts/networks', () => {
const actual = jest.requireActual('ambire-common/dist/src/consts/networks')
return {
networks: actual.networks.filter((n: any) => ['ethereum'].includes(n.id))
networks: actual.networks.filter((n: any) => ['Ethereum'].includes(n.name))
}
})

Expand All @@ -75,7 +75,7 @@ describe('Portfolio unit tests', () => {
})

test('should successfully get portfolio for address on ethereum', async () => {
const res = await getPortfolioForNetwork(TEST_WALLET, 'ethereum')
const res = await getPortfolioForNetwork(TEST_WALLET, 'Ethereum')

expect(res).toHaveProperty('tokens')
expect(res.tokens).toHaveLength(1)
Expand All @@ -88,13 +88,13 @@ describe('Portfolio unit tests', () => {
expect(res).toHaveLength(1)
expect(res[0]).toHaveProperty('network')
expect(res[0]).toHaveProperty('tokens')
expect(res[0].network).toEqual('ethereum')
expect(res[0].network).toEqual('Ethereum')
expect(res[0].tokens).toHaveLength(1)

const mockedLibToken = mockedNetworkPortfolioResult.tokens[0]
expect(res[0].tokens[0].symbol).toEqual(mockedLibToken.symbol)
expect(res[0].tokens[0].address).toEqual(mockedLibToken.address)
expect(res[0].tokens[0].network).toEqual(mockedLibToken.networkId)
expect(res[0].tokens[0].network).toEqual('Ethereum')

const expectedBalance =
Number(mockedLibToken.amount) / Math.pow(10, mockedLibToken.decimals)
Expand Down
104 changes: 100 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.10.1.tgz#63430d04bd8c5e74f8d7d049338f1cd9d4f02069"
integrity sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw==

"@adraffy/ens-normalize@^1.10.1":
version "1.11.0"
resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.11.0.tgz#42cc67c5baa407ac25059fcd7d405cc5ecdb0c33"
integrity sha512-/3DDPKHqqIqxUULp8yP4zODUY1i+2xvVWsv8A79xGWdCAG+8sb0hRh0Rk2QyOJUnnbyPUAZYcpBuRe3nS2OIUg==

"@ampproject/remapping@^2.2.0":
version "2.3.0"
resolved "https://registry.yarnpkg.com/@ampproject/remapping/-/remapping-2.3.0.tgz#ed441b6fa600072520ce18b43d2c8cc8caecc7f4"
Expand Down Expand Up @@ -1000,18 +1005,42 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@lifi/types@^17.7.1":
version "17.16.0"
resolved "https://registry.yarnpkg.com/@lifi/types/-/types-17.16.0.tgz#bbbc582740b6cc7df7ad19120fdf1db2d7dc4915"
integrity sha512-jaJ1VGcfWLSjhQN65bIBSGs18K8U98avb8AlFwJvcROk237ueq6lD7Sd0OheAUohodI+v3udZ9KfrBp3SLghig==
dependencies:
viem "^2.24.3"

"@noble/ciphers@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@noble/ciphers/-/ciphers-1.3.0.tgz#f64b8ff886c240e644e5573c097f86e5b43676dc"
integrity sha512-2I0gnIVPtfnMw9ee9h1dJG7tp81+8Ob3OJb3Mv37rx5L40/b0i7djjCVvGOVqc9AEIQyvyu1i6ypKdFw8R8gQw==

"@noble/[email protected]":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35"
integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==
dependencies:
"@noble/hashes" "1.3.2"

"@noble/[email protected]", "@noble/curves@^1.6.0", "@noble/curves@~1.9.0":
version "1.9.1"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.9.1.tgz#9654a0bc6c13420ae252ddcf975eaf0f58f0a35c"
integrity sha512-k11yZxZg+t+gWvBbIswW0yoJlu8cHOC7dhunwOzoWH/mXGBiYyR4YY6hAEK/3EUs4UpB8la1RfdRpeGsFHkWsA==
dependencies:
"@noble/hashes" "1.8.0"

"@noble/[email protected]":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39"
integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==

"@noble/[email protected]", "@noble/hashes@^1.5.0", "@noble/hashes@~1.8.0":
version "1.8.0"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.8.0.tgz#cee43d801fcef9644b11b8194857695acd5f815a"
integrity sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A==

"@nodelib/[email protected]":
version "2.1.5"
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5"
Expand All @@ -1033,6 +1062,28 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@scure/base@~1.2.5":
version "1.2.5"
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.2.5.tgz#f9d1b232425b367d0dcb81c96611dcc651d58671"
integrity sha512-9rE6EOVeIQzt5TSu4v+K523F8u6DhBsoZWPGKlnCshhlDhy0kJzUX4V+tr2dWmzF1GdekvThABoEQBGBQI7xZw==

"@scure/[email protected]", "@scure/bip32@^1.5.0":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.7.0.tgz#b8683bab172369f988f1589640e53c4606984219"
integrity sha512-E4FFX/N3f4B80AKWp5dP6ow+flD1LQZo/w8UnLGYZO674jS6YnYeepycOOksv+vLPSpgN35wgKgy+ybfTb2SMw==
dependencies:
"@noble/curves" "~1.9.0"
"@noble/hashes" "~1.8.0"
"@scure/base" "~1.2.5"

"@scure/[email protected]", "@scure/bip39@^1.4.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-1.6.0.tgz#475970ace440d7be87a6086cbee77cb8f1a684f9"
integrity sha512-+lF0BbLiJNwVlev4eKelw1WWLaiKXw7sSl8T6FvBlWkdX+94aGJ4o8XjUdlyhTCjd8c+B3KT3JfS8P0bLRNU6A==
dependencies:
"@noble/hashes" "~1.8.0"
"@scure/base" "~1.2.5"

"@sinclair/typebox@^0.27.8":
version "0.27.8"
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e"
Expand Down Expand Up @@ -1374,6 +1425,11 @@
"@typescript-eslint/types" "8.23.0"
eslint-visitor-keys "^4.2.0"

[email protected], abitype@^1.0.6:
version "1.0.8"
resolved "https://registry.yarnpkg.com/abitype/-/abitype-1.0.8.tgz#3554f28b2e9d6e9f35eb59878193eabd1b9f46ba"
integrity sha512-ZeiI6h3GnW06uYDLx0etQtX/p8E24UaHHBj57RSjK7YBFe7iuVn07EDpOeP451D06sF27VOz9JJPlIKJmXgkEg==

abort-controller@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392"
Expand Down Expand Up @@ -1443,16 +1499,18 @@ ajv@^6.12.4:
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"

"ambire-common@github:AmbireTech/ambire-common#677651a49c49cf49ff7864bd1bd6dc32b580c789":
version "2.44.0"
resolved "https://codeload.github.com/AmbireTech/ambire-common/tar.gz/677651a49c49cf49ff7864bd1bd6dc32b580c789"
"ambire-common@github:AmbireTech/ambire-common#378bba59e18430bfcc411504ca3dbc607f32d214":
version "2.55.0"
resolved "https://codeload.github.com/AmbireTech/ambire-common/tar.gz/378bba59e18430bfcc411504ca3dbc607f32d214"
dependencies:
"@lifi/types" "^17.7.1"
aes-js "^3.1.2"
dotenv "^16.3.1"
eth-crypto "^2.6.0"
eth-rpc-errors "^4.0.3"
ethers "^6.8.0"
events "^3.3.0"
js-yaml "^4.1.0"
scrypt-js "^3.0.1"
uuid "9.0.0"

Expand Down Expand Up @@ -2438,7 +2496,7 @@ event-target-shim@^5.0.0:
resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789"
integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==

eventemitter3@^5.0.1:
eventemitter3@5.0.1, eventemitter3@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-5.0.1.tgz#53f5ffd0a492ac800721bb42c66b841de96423c4"
integrity sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==
Expand Down Expand Up @@ -3032,6 +3090,11 @@ isexe@^2.0.0:
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
integrity sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==

[email protected]:
version "1.0.7"
resolved "https://registry.yarnpkg.com/isows/-/isows-1.0.7.tgz#1c06400b7eed216fbba3bcbd68f12490fc342915"
integrity sha512-I1fSfDCZL5P0v33sVqeTDSpcstAg/N+wF5HS033mogOVIp4B+oHC7oOCsA3axAbBSGTJ8QubbNmnIRN/h8U7hg==

istanbul-lib-coverage@^3.0.0, istanbul-lib-coverage@^3.2.0:
version "3.2.2"
resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz#2d166c4b0644d43a39f04bf6c2edd1e585f31756"
Expand Down Expand Up @@ -3918,6 +3981,20 @@ optionator@^0.9.3:
type-check "^0.4.0"
word-wrap "^1.2.5"

[email protected]:
version "0.7.1"
resolved "https://registry.yarnpkg.com/ox/-/ox-0.7.1.tgz#fb23a770dd966c051ad916d4e2e655a6f995e1cf"
integrity sha512-+k9fY9PRNuAMHRFIUbiK9Nt5seYHHzSQs9Bj+iMETcGtlpS7SmBzcGSVUQO3+nqGLEiNK4598pHNFlVRaZbRsg==
dependencies:
"@adraffy/ens-normalize" "^1.10.1"
"@noble/ciphers" "^1.3.0"
"@noble/curves" "^1.6.0"
"@noble/hashes" "^1.5.0"
"@scure/bip32" "^1.5.0"
"@scure/bip39" "^1.4.0"
abitype "^1.0.6"
eventemitter3 "5.0.1"

p-limit@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1"
Expand Down Expand Up @@ -4743,6 +4820,20 @@ vary@~1.1.2:
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==

viem@^2.24.3:
version "2.30.1"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.30.1.tgz#22cdd653c57b4ff342524afd6974b08b302a7875"
integrity sha512-CkoS5Vv6kiRGmRF2xO2z275Gu90vTrKZHf/ckYXxP2J94UvCnFvUcbRdfit6uebj1I8nFwkGlkkOMuOZDHyO4w==
dependencies:
"@noble/curves" "1.9.1"
"@noble/hashes" "1.8.0"
"@scure/bip32" "1.7.0"
"@scure/bip39" "1.6.0"
abitype "1.0.8"
isows "1.0.7"
ox "0.7.1"
ws "8.18.2"

walker@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/walker/-/walker-1.0.8.tgz#bd498db477afe573dc04185f011d3ab8a8d7653f"
Expand Down Expand Up @@ -4821,6 +4912,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/ws/-/ws-8.17.1.tgz#9293da530bb548febc95371d90f9c878727d919b"
integrity sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==

[email protected]:
version "8.18.2"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.18.2.tgz#42738b2be57ced85f46154320aabb51ab003705a"
integrity sha512-DMricUmwGZUVr++AEAe2uiVM7UoO9MAVZMDu05UQOaUII0lp+zOzLLU4Xqh/JvTqklB1T4uELaaPBKyjE1r4fQ==

y18n@^5.0.5:
version "5.0.8"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
Expand Down