1
1
import { IAgentRuntime } from "@ai16z/eliza" ;
2
2
import { z } from "zod" ;
3
3
4
+ // Add ENV variable at the top
5
+ let ENV : string = "testnet" ;
6
+
4
7
export const nearEnvSchema = z . object ( {
5
8
NEAR_WALLET_SECRET_KEY : z . string ( ) . min ( 1 , "Wallet secret key is required" ) ,
6
9
NEAR_WALLET_PUBLIC_KEY : z . string ( ) . min ( 1 , "Wallet public key is required" ) ,
7
10
NEAR_ADDRESS : z . string ( ) . min ( 1 , "Near address is required" ) ,
8
11
SLIPPAGE : z . string ( ) . min ( 1 , "Slippage is required" ) ,
9
12
RPC_URL : z . string ( ) . min ( 1 , "RPC URL is required" ) ,
13
+ networkId : z . string ( ) ,
14
+ nodeUrl : z . string ( ) ,
15
+ walletUrl : z . string ( ) ,
16
+ WRAP_NEAR_CONTRACT_ID : z . string ( ) ,
17
+ REF_FI_CONTRACT_ID : z . string ( ) ,
18
+ REF_TOKEN_ID : z . string ( ) ,
19
+ indexerUrl : z . string ( ) ,
20
+ explorerUrl : z . string ( ) ,
21
+ REF_DCL_SWAP_CONTRACT_ID : z . string ( ) ,
10
22
} ) ;
11
23
12
24
export type NearConfig = z . infer < typeof nearEnvSchema > ;
13
25
26
+ export function getConfig (
27
+ env : string | undefined | null = ENV ||
28
+ process . env . NEAR_ENV ||
29
+ process . env . REACT_APP_REF_SDK_ENV
30
+ ) {
31
+ ENV = env || "testnet" ;
32
+ switch ( env ) {
33
+ case 'mainnet' :
34
+ return {
35
+ networkId : 'mainnet' ,
36
+ nodeUrl : 'https://rpc.mainnet.near.org' ,
37
+ walletUrl : 'https://wallet.near.org' ,
38
+ WRAP_NEAR_CONTRACT_ID : 'wrap.near' ,
39
+ REF_FI_CONTRACT_ID : 'v2.ref-finance.near' ,
40
+ REF_TOKEN_ID : 'token.v2.ref-finance.near' ,
41
+ indexerUrl : 'https://indexer.ref.finance' ,
42
+ explorerUrl : 'https://testnet.nearblocks.io' ,
43
+ REF_DCL_SWAP_CONTRACT_ID : 'dclv2.ref-labs.near' ,
44
+ } ;
45
+ case 'testnet' :
46
+ return {
47
+ networkId : 'testnet' ,
48
+ nodeUrl : 'https://rpc.testnet.near.org' ,
49
+ walletUrl : 'https://wallet.testnet.near.org' ,
50
+ indexerUrl : 'https://testnet-indexer.ref-finance.com' ,
51
+ WRAP_NEAR_CONTRACT_ID : 'wrap.testnet' ,
52
+ REF_FI_CONTRACT_ID : 'ref-finance-101.testnet' ,
53
+ REF_TOKEN_ID : 'ref.fakes.testnet' ,
54
+ explorerUrl : 'https://testnet.nearblocks.io' ,
55
+ REF_DCL_SWAP_CONTRACT_ID : 'dclv2.ref-dev.testnet' ,
56
+ } ;
57
+ default :
58
+ return {
59
+ networkId : 'mainnet' ,
60
+ nodeUrl : 'https://rpc.mainnet.near.org' ,
61
+ walletUrl : 'https://wallet.near.org' ,
62
+ REF_FI_CONTRACT_ID : 'v2.ref-finance.near' ,
63
+ WRAP_NEAR_CONTRACT_ID : 'wrap.near' ,
64
+ REF_TOKEN_ID : 'token.v2.ref-finance.near' ,
65
+ indexerUrl : 'https://indexer.ref.finance' ,
66
+ explorerUrl : 'https://nearblocks.io' ,
67
+ REF_DCL_SWAP_CONTRACT_ID : 'dclv2.ref-labs.near' ,
68
+ } ;
69
+ }
70
+ }
71
+
14
72
export async function validateNearConfig (
15
73
runtime : IAgentRuntime
16
74
) : Promise < NearConfig > {
17
75
try {
76
+ const envConfig = getConfig ( runtime . getSetting ( "NEAR_ENV" ) ?? undefined ) ;
18
77
const config = {
19
78
NEAR_WALLET_SECRET_KEY :
20
79
runtime . getSetting ( "NEAR_WALLET_SECRET_KEY" ) ||
@@ -27,6 +86,7 @@ export async function validateNearConfig(
27
86
runtime . getSetting ( "NEAR_ADDRESS" ) || process . env . NEAR_ADDRESS ,
28
87
SLIPPAGE : runtime . getSetting ( "SLIPPAGE" ) || process . env . SLIPPAGE ,
29
88
RPC_URL : runtime . getSetting ( "RPC_URL" ) || process . env . RPC_URL ,
89
+ ...envConfig // Spread the environment-specific config
30
90
} ;
31
91
32
92
return nearEnvSchema . parse ( config ) ;
0 commit comments