Class: Solrengine::Tokens::Portfolio

Inherits:
Object
  • Object
show all
Defined in:
lib/solrengine/tokens/portfolio.rb

Instance Method Summary collapse

Constructor Details

#initialize(wallet_address) ⇒ Portfolio

Returns a new instance of Portfolio.

Raises:

  • (ArgumentError)


4
5
6
7
8
9
# File 'lib/solrengine/tokens/portfolio.rb', line 4

def initialize(wallet_address)
  raise ArgumentError, "Invalid wallet address" unless Solrengine::Tokens.valid_address?(wallet_address)

  @wallet_address = wallet_address
  @token_service = TokenMetadataService.new
end

Instance Method Details

#nfts(page: 1, limit: 50) ⇒ Object



21
22
23
24
25
# File 'lib/solrengine/tokens/portfolio.rb', line 21

def nfts(page: 1, limit: 50)
  Solrengine::Tokens.cache_fetch("solrengine_tokens/wallet/#{@wallet_address}/nfts", expires_in: 60) do
    NftService.new.nfts_for(@wallet_address, page: page, limit: limit)
  end
end

#recent_transactions(limit: 5) ⇒ Object



27
28
29
30
31
# File 'lib/solrengine/tokens/portfolio.rb', line 27

def recent_transactions(limit: 5)
  Solrengine::Tokens.cache_fetch("solrengine_tokens/wallet/#{@wallet_address}/recent_txs", expires_in: 30) do
    Solrengine::Rpc.client.get_recent_signatures(@wallet_address, limit: limit)
  end
end

#tokensObject



11
12
13
14
15
# File 'lib/solrengine/tokens/portfolio.rb', line 11

def tokens
  Solrengine::Tokens.cache_fetch("solrengine_tokens/wallet/#{@wallet_address}/tokens", expires_in: 45) do
    @token_service.token_balances_for(@wallet_address)
  end
end

#total_usd_valueObject



17
18
19
# File 'lib/solrengine/tokens/portfolio.rb', line 17

def total_usd_value
  tokens.sum { |t| t[:usd_value] || 0 }
end