Class: Solrengine::Sdp::Token

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/solrengine/sdp/token.rb

Overview

Engine-owned record of a token issued through SDP: registered off-chain (create_token), then deployed on-chain (deploy_token), then minted/burned via supply actions. Mirrors Transfer’s “the row is the audit trail” posture. Mint authority is signing_wallet_id (a custodial treasury wallet).

Constant Summary collapse

STATUSES =
%w[created deployed failed].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.register!(name:, symbol:, signing_wallet_id:, decimals: 0) ⇒ Object

Registers the token with SDP (off-chain record) and persists it. Raises Sdp::Error if SDP rejects it (no row is created).



31
32
33
34
35
36
37
38
39
# File 'app/models/solrengine/sdp/token.rb', line 31

def register!(name:, symbol:, signing_wallet_id:, decimals: 0)
  sdp = Solrengine::Sdp.client.create_token(
    name: name, symbol: symbol, decimals: decimals, signing_wallet_id: signing_wallet_id
  )
  create!(
    name: name, symbol: symbol, decimals: decimals,
    signing_wallet_id: signing_wallet_id, sdp_token_id: sdp.id, status: "created"
  )
end

Instance Method Details

#burn!(source:, signing_wallet_id:, amount:, memo: nil) ⇒ Object

Records a burn and enqueues BurnJob (never retried). A burn is signed by the source wallet’s owner, so signing_wallet_id is the holder’s custodial wallet (the user), NOT the treasury. Returns the TokenBurn.



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/models/solrengine/sdp/token.rb', line 74

def burn!(source:, signing_wallet_id:, amount:, memo: nil)
  burn = burns.create!(
    source: source,
    signing_wallet_id: signing_wallet_id,
    amount: normalize_amount(amount),
    memo: memo,
    memo_token: "#{TokenBurn::MEMO_TOKEN_PREFIX}#{SecureRandom.hex(8)}",
    status: "burning",
    submitted_at: Time.current
  )
  BurnJob.perform_later(burn)
  burn
end

#deploy!Object

Custodial sign-and-send deploy → on-chain mint. Records the mint address; on failure the row is marked failed and the error re-raised for the caller to render. Never retried (money-path).



45
46
47
48
49
50
51
52
# File 'app/models/solrengine/sdp/token.rb', line 45

def deploy!
  sdp = Solrengine::Sdp.client.deploy_token(sdp_token_id)
  update!(mint_address: sdp.mint_address, status: "deployed")
  self
rescue ::Sdp::Error => e
  update!(status: "failed", sdp_error: e.message)
  raise
end

#deployed?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/solrengine/sdp/token.rb', line 24

def deployed?
  mint_address.present?
end

#mint!(destination:, amount:, memo: nil) ⇒ Object

Records a mint and enqueues MintJob (the mint POST runs off the web request, never retried). amount is a DECIMAL token amount — SDP scales it by the token’s decimals (whole numbers for a 0-decimal token). Returns the TokenMint row.



58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/models/solrengine/sdp/token.rb', line 58

def mint!(destination:, amount:, memo: nil)
  mint = mints.create!(
    destination: destination,
    amount: normalize_amount(amount),
    memo: memo,
    memo_token: "#{TokenMint::MEMO_TOKEN_PREFIX}#{SecureRandom.hex(8)}",
    status: "minting",
    submitted_at: Time.current
  )
  MintJob.perform_later(mint)
  mint
end