forked from Movalabs-crew/mova-store
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ts
More file actions
121 lines (104 loc) · 4.54 KB
/
Copy pathconfig.ts
File metadata and controls
121 lines (104 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { Networks } from "@stellar/stellar-sdk";
// ---------------------------------------------------------------------------
// Network + contract configuration.
//
// Set these in `.env.local` (see `.env.local.example`):
// NEXT_PUBLIC_STELLAR_NETWORK = "testnet" | "mainnet"
// NEXT_PUBLIC_STELLAR_RPC_URL = RPC endpoint
// NEXT_PUBLIC_STELLAR_NETWORK_PASSPHRASE = network passphrase
// NEXT_PUBLIC_CHECKOUT_CONTRACT_ID = deployed checkout contract id (C...)
// NEXT_PUBLIC_USDC_CONTRACT_ID = USDC token contract id (C...)
// NEXT_PUBLIC_NATIVE_ASSET_CONTRACT_ID = native XLM SAC contract id (C...)
// ---------------------------------------------------------------------------
export const NETWORK = process.env.NEXT_PUBLIC_STELLAR_NETWORK ?? "testnet";
export const IS_MAINNET = NETWORK === "mainnet";
export const RPC_URL =
process.env.NEXT_PUBLIC_STELLAR_RPC_URL ??
(IS_MAINNET
? "https://soroban-rpc.stellar.org"
: "https://soroban-testnet.stellar.org");
export const NETWORK_PASSPHRASE =
process.env.NEXT_PUBLIC_STELLAR_NETWORK_PASSPHRASE ??
(IS_MAINNET ? Networks.PUBLIC : Networks.TESTNET);
// Deployed checkout contract (see contracts/checkout + README).
export const CHECKOUT_CONTRACT_ID =
process.env.NEXT_PUBLIC_CHECKOUT_CONTRACT_ID ?? "";
// USDC via the Stellar Asset Contract.
export const TESTNET_USDC_CONTRACT_ID =
"CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA";
// Set NEXT_PUBLIC_USDC_CONTRACT_ID to the mainnet USDC SAC contract id.
export const USDC_CONTRACT_ID =
process.env.NEXT_PUBLIC_USDC_CONTRACT_ID ?? TESTNET_USDC_CONTRACT_ID;
// Testnet USDC is issued by Circle's classic testnet issuer (trustline only
// needed for non-native assets; native XLM needs no trustline).
export const TESTNET_USDC_ISSUER =
"GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5";
// Native XLM Stellar Asset Contract ids.
//
// Testnet value is empirically verified (balance/decimals simulated against
// soroban-testnet.stellar.org; see docs/ARCHITECTURE.md). The mainnet value
// comes from the stellar-cli `native` built-in alias table and should be
// confirmed against the live mainnet RPC before first use.
export const TESTNET_NATIVE_ASSET_CONTRACT_ID =
"CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC";
export const MAINNET_NATIVE_ASSET_CONTRACT_ID =
"CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA";
export const NATIVE_ASSET_CONTRACT_ID =
process.env.NEXT_PUBLIC_NATIVE_ASSET_CONTRACT_ID ??
(IS_MAINNET
? MAINNET_NATIVE_ASSET_CONTRACT_ID
: TESTNET_NATIVE_ASSET_CONTRACT_ID);
// All tokens accepted by the checkout contract's whitelist. The merchant adds
// each token on-chain via `add_token`; the frontend uses this registry for
// trustline/balance checks and for building `pay` invocations.
export interface TokenConfig {
contractId: string;
symbol: string;
name: string;
decimals: number;
/** Native XLM needs no trustline. */
isNative?: boolean;
/** Classic asset code + issuer used for trustline checks. */
assetCode?: string;
assetIssuer?: string;
}
export const SUPPORTED_TOKENS: TokenConfig[] = [
{
contractId: USDC_CONTRACT_ID,
symbol: "USDC",
name: "USD Coin",
decimals: 7,
assetCode: "USDC",
assetIssuer: TESTNET_USDC_ISSUER,
},
{
contractId: NATIVE_ASSET_CONTRACT_ID,
symbol: "XLM",
name: "Stellar Lumens",
decimals: 7,
isNative: true,
},
];
/** Default payment token (used by the checkout flow unless overridden). */
export function defaultToken(): TokenConfig {
return SUPPORTED_TOKENS[0];
}
export function tokenForContract(contractId: string): TokenConfig | undefined {
return SUPPORTED_TOKENS.find((t) => t.contractId === contractId);
}
// USDC uses 7 decimals (nativeToScVal / i128 amounts are raw units).
export const USDC_DECIMALS = 7;
// How many seconds to wait for a transaction to reach a final state.
export const TX_TIMEOUT_SECONDS = 60;
// How many seconds between getTransaction polls.
export const TX_POLL_INTERVAL_MS = 2500;
// Meridian / friendbot for funding testnet accounts.
export const FRIENDBOT_URL = "https://friendbot.stellar.org";
// Event indexing (lib/stellar/indexer.ts).
export const EVENT_POLL_INTERVAL_MS = 4000;
// How many ledgers behind the tip to start scanning on first connect.
export const EVENT_START_LEDGER_BACKFILL = 100;
// Pre-flight simulation (lib/stellar/simulate.ts).
// Safety buffer added on top of the simulated resource fee so the tx has
// headroom to cover fees that drift between simulation and inclusion.
export const FEE_BUFFER_STROOPS = BigInt(500000);