Skip to content

Commit 532572c

Browse files
committed
feat: update ocp protos; update currency service to support mint metadata retrieval
Signed-off-by: Brandon McAnsh <[email protected]>
1 parent 6407f42 commit 532572c

File tree

25 files changed

+476
-50
lines changed

25 files changed

+476
-50
lines changed

definitions/opencode/protos/src/main/proto/account/v1/account_service.proto

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ message GetTokenAccountInfosRequest {
7676
oneof Filter {
7777
common.v1.SolanaAccountId filter_by_token_address = 10;
7878
common.v1.AccountType filter_by_account_type = 11;
79+
common.v1.SolanaAccountId filter_by_mint_address = 12;
7980
}
8081
}
8182

@@ -204,12 +205,6 @@ message TokenAccountInfo {
204205
// The token account's mint
205206
common.v1.SolanaAccountId mint = 13;
206207

207-
// Reserved for the number of decimals configured for the mint
208-
reserved 14;
209-
210-
// Reserved for a user-friendly display name for the mint
211-
reserved 15;
212-
213208
// Deprecated relationship
214209
reserved 16;
215210

definitions/opencode/protos/src/main/proto/common/v1/model.proto

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,24 @@ import "google/protobuf/timestamp.proto";
88

99
// AccountType associates a type to an account, which infers how an account is used
1010
// within the Code ecosystem.
11-
//
12-
// todo: Deprecate legacy accounts (temporary, buckets, legacy primary, relationship, swap)
1311
enum AccountType {
1412
UNKNOWN = 0;
1513
PRIMARY = 1;
16-
TEMPORARY_INCOMING = 2;
17-
TEMPORARY_OUTGOING = 3;
18-
BUCKET_1_KIN = 4;
19-
BUCKET_10_KIN = 5;
20-
BUCKET_100_KIN = 6;
21-
BUCKET_1_000_KIN = 7;
22-
BUCKET_10_000_KIN = 8;
23-
BUCKET_100_000_KIN = 9;
24-
BUCKET_1_000_000_KIN = 10;
25-
LEGACY_PRIMARY_2022 = 11;
2614
REMOTE_SEND_GIFT_CARD = 12;
27-
RELATIONSHIP = 13;
2815
SWAP = 14;
2916
ASSOCIATED_TOKEN_ACCOUNT = 15;
3017
POOL = 16;
18+
reserved 2; // Deprecated TEMPORARY_INCOMING
19+
reserved 3; // Deprecated TEMPORARY_OUTGOING
20+
reserved 4; // Deprecated BUCKET_1_KIN
21+
reserved 5; // Deprecated BUCKET_10_KIN
22+
reserved 6; // Deprecated BUCKET_100_KIN
23+
reserved 7; // Deprecated BUCKET_1_000_KIN
24+
reserved 8; // Deprecated BUCKET_10_000_KIN
25+
reserved 9; // Deprecated BUCKET_100_000_KIN
26+
reserved 10; // Deprecated BUCKET_1_000_000_KIN
27+
reserved 11; // Deprecated LEGACY_PRIMARY_2022
28+
reserved 13; // Deprecated RELATIONSHIP
3129
}
3230
// SolanaAccountId is a raw binary Ed25519 public key for a Solana account
3331
message SolanaAccountId {

definitions/opencode/protos/src/main/proto/currency/v1/currency_service.proto

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ package code.currency.v1;
33
option go_package = "github.com/code-payments/code-protobuf-api/generated/go/currency/v1;currency";
44
option java_package = "com.codeinc.opencode.gen.currency.v1";
55
option objc_class_prefix = "CPBCurrencyV1";
6+
import "common/v1/model.proto";
67

78
import "google/protobuf/timestamp.proto";
89
service Currency {
910
// GetAllRates returns the exchange rates for the core mint token against all
1011
// available currencies
1112
rpc GetAllRates(GetAllRatesRequest) returns (GetAllRatesResponse);
13+
// GetMints gets mint account metadata by address
14+
rpc GetMints(GetMintsRequest) returns (GetMintsResponse);
1215
}
1316
message GetAllRatesRequest {
1417
// If timestamp is included, the returned rate will be the most recent available
@@ -29,3 +32,72 @@ message GetAllRatesResponse {
2932
// letter lowercase currency code.
3033
map<string, double> rates = 3 ;
3134
}
35+
message GetMintsRequest {
36+
repeated common.v1.SolanaAccountId addresses = 1 ;
37+
}
38+
message GetMintsResponse {
39+
Result result = 1;
40+
enum Result {
41+
OK = 0;
42+
NOT_FOUND = 1;
43+
}
44+
map<string, Mint> metadata_by_address = 2;
45+
}
46+
message Mint {
47+
// Token mint address
48+
common.v1.SolanaAccountId address = 1;
49+
// The number of decimals configured for the mint
50+
uint32 decimals = 2;
51+
// Currency name
52+
string name = 3 ;
53+
// Currency ticker symbol
54+
string symbol = 4 ;
55+
// Currency description
56+
string description = 5 ;
57+
// URL to currency image
58+
string image_url = 6 ;
59+
// Available when a VM exists for the given mint, and can be used for deriving
60+
// VM deposit PDAs
61+
//
62+
// Note: Only currencies with a VM are useable for payments
63+
VmMetadata vm_metadata = 7;
64+
// Available when created by the launchpad via the currency creator program, and
65+
// can be used for calculating price, market cap, etc. based on the exponential
66+
// bonding curve
67+
LaunchpadMetadata launchpad_metadata = 8;
68+
}
69+
message VmMetadata {
70+
// VM address
71+
common.v1.SolanaAccountId vm = 1;
72+
// Authority that subsidizes and authorizes all transactions against the VM
73+
common.v1.SolanaAccountId authority = 2;
74+
// Lock duration of Virtual Timelock Accounts on the VM, currently hardcoded
75+
// to 21 days
76+
uint32 lock_duration_in_days = 3;
77+
}
78+
message LaunchpadMetadata {
79+
// The address of the currency config
80+
common.v1.SolanaAccountId currency_config = 1;
81+
// The address of the liquidity pool
82+
common.v1.SolanaAccountId liquidity_pool = 2;
83+
// The random seed used during currency creation
84+
common.v1.SolanaAccountId seed = 3;
85+
// The address of the authority for the currency
86+
common.v1.SolanaAccountId authority = 4;
87+
// The address where this mint's tokens are locked against the liquidity pool
88+
common.v1.SolanaAccountId mint_vault = 5;
89+
// The address where core mint tokens are locked against the liquidity pool
90+
common.v1.SolanaAccountId core_mint_vault = 6;
91+
// Reserved for mint_fees if we enable buy fees
92+
reserved 7;
93+
// The address where core mint fees are paid
94+
common.v1.SolanaAccountId core_mint_fees = 8;
95+
// Current circulating mint token supply in quarks
96+
uint64 supply_from_bonding = 9;
97+
// Current core mint quarks locked in the liquidity pool
98+
uint64 core_mint_locked = 10;
99+
// Reserved for buy_fee_bps if we enable buy fees
100+
reserved 11;
101+
// Precent fee for sells in basis points, currently hardcoded to 1%
102+
uint32 sell_fee_bps = 12;
103+
}

definitions/opencode/protos/src/main/proto/transaction/v2/transaction_service.proto

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,13 @@ message GetLimitsResponse {
175175
double usd_transacted = 6;
176176
}
177177
message CanWithdrawToAccountRequest {
178+
// The destination account attempted to be withdrawn to. Can be an owner or
179+
// token account.
178180
common.v1.SolanaAccountId account = 1;
181+
// The mint that the withdraw will be operating against. For backwards
182+
// compatibility, if no mint is set, then it is assumed to be the core
183+
// mint.
184+
common.v1.SolanaAccountId mint = 2;
179185
}
180186
message CanWithdrawToAccountResponse {
181187
// Server-controlled flag to indicate if the account can be withdrawn to.
@@ -202,6 +208,8 @@ message CanWithdrawToAccountResponse {
202208
// the intent.
203209
//
204210
// This will be set when requires_initialization = true
211+
//
212+
// Note: The fee is always paid in the core mint.
205213
ExchangeDataWithoutRate fee_amount = 4;
206214
}
207215
message AirdropRequest {
@@ -282,6 +290,10 @@ message OpenAccountsMetadata {
282290
USER = 0; // Opens a set of user accounts
283291
POOL = 1; // Opens a pool account
284292
}
293+
// The mint that this action will be operating against. For backwards
294+
// compatibility, if no mint is set, then it is assumed to be the core
295+
// mint.
296+
common.v1.SolanaAccountId mint = 2;
285297
}
286298
// Send a payment to a destination account publicly.
287299
//
@@ -319,6 +331,10 @@ message SendPublicPaymentMetadata {
319331
bool is_withdrawal = 3;
320332
// Is the payment going to a new gift card? Note is_withdrawal must be false.
321333
bool is_remote_send = 5;
334+
// The mint that this intent will be operating against. For backwards
335+
// compatibility, if no mint is set, then it is assumed to be the core
336+
// mint.
337+
common.v1.SolanaAccountId mint = 7;
322338
}
323339
// Receive funds into a user-owned account publicly. All use cases of this intent
324340
// close the account, so all funds must be moved.
@@ -340,6 +356,10 @@ message ReceivePaymentsPubliclyMetadata {
340356
// part of creating the gift card account. This is purely a server-provided value.
341357
// SubmitIntent will disallow this being set.
342358
ExchangeData exchange_data = 5;
359+
// The mint that this intent will be operating against. For backwards
360+
// compatibility, if no mint is set, then it is assumed to be the core
361+
// mint.
362+
common.v1.SolanaAccountId mint = 6;
343363
}
344364
// Distribute funds from a pool account publicly to one or more user-owned accounts.
345365
//
@@ -364,6 +384,10 @@ message PublicDistributionMetadata {
364384
// The amount of funds to distribute to the destination
365385
uint64 quarks = 2;
366386
}
387+
// The mint that this intent will be operating against. For backwards
388+
// compatibility, if no mint is set, then it is assumed to be the core
389+
// mint.
390+
common.v1.SolanaAccountId mint = 3;
367391
}
368392
//
369393
// Action Definitions
@@ -406,6 +430,10 @@ message OpenAccountAction {
406430
// using the private key of the authority account. This provides a proof
407431
// of authorization to link authority to owner.
408432
common.v1.Signature authority_signature = 6;
433+
// The mint that this action will be operating against. For backwards
434+
// compatibility, if no mint is set, then it is assumed to be the core
435+
// mint.
436+
common.v1.SolanaAccountId mint = 7;
409437
}
410438
// Compact message signature required
411439
message NoPrivacyTransferAction {
@@ -417,6 +445,10 @@ message NoPrivacyTransferAction {
417445
common.v1.SolanaAccountId destination = 3;
418446
// The core mint quark amount to transfer
419447
uint64 amount = 4;
448+
// The mint that this action will be operating against. For backwards
449+
// compatibility, if no mint is set, then it is assumed to be the core
450+
// mint.
451+
common.v1.SolanaAccountId mint = 5;
420452
}
421453
// Compact message signature required
422454
message NoPrivacyWithdrawAction {
@@ -435,6 +467,10 @@ message NoPrivacyWithdrawAction {
435467
// scheduling at its own discretion to return funds back to the owner (to their primary
436468
// account) that funded source.
437469
bool is_auto_return = 6;
470+
// The mint that this action will be operating against. For backwards
471+
// compatibility, if no mint is set, then it is assumed to be the core
472+
// mint.
473+
common.v1.SolanaAccountId mint = 7;
438474
}
439475
// Compact message signature required
440476
message FeePaymentAction {
@@ -450,6 +486,10 @@ message FeePaymentAction {
450486
common.v1.SolanaAccountId source = 3;
451487
// The core mint quark amount to transfer
452488
uint64 amount = 4;
489+
// The mint that this action will be operating against. For backwards
490+
// compatibility, if no mint is set, then it is assumed to be the core
491+
// mint.
492+
common.v1.SolanaAccountId mint = 5;
453493
}
454494
//
455495
// Server Parameter Definitions
@@ -551,6 +591,10 @@ message ExchangeData {
551591
// The exact amount of quarks to send. This will be used as the source of
552592
// truth for validating transaction transfer amounts.
553593
uint64 quarks = 4;
594+
// The crypto mint that is being operated against for the exchange.
595+
// For backwards compatibility, if no mint is set, then it is assumed
596+
// to be the core mint.
597+
common.v1.SolanaAccountId mint = 5;
554598
}
555599
message ExchangeDataWithoutRate {
556600
// ISO 4217 alpha-3 currency code.

services/opencode/src/main/kotlin/com/getcode/opencode/ExchangeFactory.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package com.getcode.opencode
33
import android.content.Context
44
import com.getcode.opencode.exchange.Exchange
55
import com.getcode.opencode.inject.OpenCodeModule
6+
import com.getcode.opencode.internal.domain.mapping.LaunchpadMetadataMapper
7+
import com.getcode.opencode.internal.domain.mapping.MintMapper
8+
import com.getcode.opencode.internal.domain.mapping.VmMetadataMapper
69
import com.getcode.opencode.internal.network.api.CurrencyApi
710
import com.getcode.opencode.internal.network.services.CurrencyService
811
import com.getcode.util.locale.LocaleModule
@@ -27,9 +30,13 @@ object ExchangeFactory {
2730

2831

2932
val api = CurrencyApi(module.provideManagedChannel(context, config))
33+
val mintMapper = MintMapper(
34+
vmMetadataMapper = VmMetadataMapper(),
35+
launchpadMetadataMapper = LaunchpadMetadataMapper(),
36+
)
3037
val locale = localeModule.bindLocaleHelper(context)
3138
val resources = AndroidResources(context)
32-
val service = CurrencyService(api)
39+
val service = CurrencyService(api, mintMapper)
3340
return module.providesExchange(service, resources, locale)
3441
}
3542
}

services/opencode/src/main/kotlin/com/getcode/opencode/RepositoryFactory.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ package com.getcode.opencode
22

33
import android.content.Context
44
import com.getcode.opencode.inject.OpenCodeModule
5+
import com.getcode.opencode.internal.domain.mapping.LaunchpadMetadataMapper
6+
import com.getcode.opencode.internal.domain.mapping.MintMapper
57
import com.getcode.opencode.internal.domain.mapping.TransactionMetadataMapper
8+
import com.getcode.opencode.internal.domain.mapping.VmMetadataMapper
69
import com.getcode.opencode.internal.network.api.AccountApi
10+
import com.getcode.opencode.internal.network.api.CurrencyApi
711
import com.getcode.opencode.internal.network.api.MessagingApi
812
import com.getcode.opencode.internal.network.api.TransactionApi
913
import com.getcode.opencode.internal.network.services.AccountService
14+
import com.getcode.opencode.internal.network.services.CurrencyService
1015
import com.getcode.opencode.internal.network.services.MessagingService
1116
import com.getcode.opencode.internal.network.services.TransactionService
1217
import com.getcode.opencode.repositories.AccountRepository
18+
import com.getcode.opencode.repositories.CurrencyRepository
1319
import com.getcode.opencode.repositories.EventRepository
1420
import com.getcode.opencode.repositories.MessagingRepository
1521
import com.getcode.opencode.repositories.TransactionRepository
@@ -84,4 +90,26 @@ object RepositoryFactory {
8490
val service = TransactionService(api, mapper)
8591
return module.providesTransactionRepository(service)
8692
}
93+
94+
fun createCurrencyRepository(
95+
context: Context,
96+
config: ProtocolConfig
97+
): CurrencyRepository {
98+
val appContext = context.applicationContext ?: throw IllegalStateException(
99+
"applicationContext was not provided",
100+
)
101+
102+
val module = EntryPointAccessors.fromApplication(
103+
appContext,
104+
OpenCodeModule::class.java,
105+
)
106+
107+
val api = CurrencyApi(module.provideManagedChannel(context, config))
108+
val mintMapper = MintMapper(
109+
vmMetadataMapper = VmMetadataMapper(),
110+
launchpadMetadataMapper = LaunchpadMetadataMapper(),
111+
)
112+
val service = CurrencyService(api, mintMapper)
113+
return module.providesCurrencyRepository(service)
114+
}
87115
}

services/opencode/src/main/kotlin/com/getcode/opencode/controllers/AccountController.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ class AccountController @Inject constructor(
4545

4646
suspend fun getAccounts(
4747
accountOwner: AccountCluster,
48-
requestingOwner: AccountCluster
48+
requestingOwner: AccountCluster,
49+
filter: AccountFilter? = null,
4950
): Result<AccountResponse> {
5051
return accountRepository.getAccounts(
5152
accountOwner = accountOwner.authority.keyPair,
52-
requestingOwner = requestingOwner.authority.keyPair
53+
requestingOwner = requestingOwner.authority.keyPair,
54+
filter = filter,
5355
)
5456
}
5557

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.getcode.opencode.controllers
2+
3+
import com.getcode.opencode.model.financial.CurrencyCode
4+
import com.getcode.opencode.model.financial.MintMetadata
5+
import com.getcode.opencode.model.financial.Rate
6+
import com.getcode.opencode.repositories.CurrencyRepository
7+
import com.getcode.solana.keys.PublicKey
8+
import kotlinx.coroutines.CoroutineScope
9+
import kotlinx.coroutines.Dispatchers
10+
import kotlinx.coroutines.SupervisorJob
11+
import kotlinx.datetime.Instant
12+
import javax.inject.Inject
13+
import javax.inject.Singleton
14+
15+
@Singleton
16+
class CurrencyController @Inject constructor(
17+
private val repository: CurrencyRepository,
18+
) {
19+
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
20+
21+
suspend fun getRates(
22+
from: Instant?
23+
): Result<Map<CurrencyCode, Rate>> {
24+
return repository.getRates(from)
25+
}
26+
27+
suspend fun getMints(
28+
addresses: List<PublicKey>
29+
): Result<List<MintMetadata>> {
30+
return repository.getMints(addresses)
31+
}
32+
}

0 commit comments

Comments
 (0)