Skip to content

Commit 1ebfb76

Browse files
authored
Merge pull request #8 from YoubetDao/feat/params
feat: params
2 parents 7c9b2e3 + 8c1152a commit 1ebfb76

File tree

6 files changed

+52
-46
lines changed

6 files changed

+52
-46
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {
22
SDK,
3-
NetworkType,
43
type GoalInfo,
54
formatResult,
65
type Task,
76
} from "youbet-sdk";
87

9-
export const sdk = new SDK({ networkType: NetworkType.Testnet });
8+
import { openCampusTestOptions } from "./options";
9+
10+
export const sdk = new SDK(openCampusTestOptions);
1011

1112
export { type GoalInfo, type Task, formatResult };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { SdkCtorOptions } from "youbet-sdk";
2+
3+
export const lineaOptions: SdkCtorOptions = {
4+
networkOptions: {
5+
contractAddress: '0x902e2f3179aa959137fdc823754555b10c40f5b1',
6+
rpcUrl: 'https://rpc.linea.build',
7+
chainId: 59144,
8+
},
9+
chainName: 'Linea',
10+
}
11+
12+
export const openCampusTestOptions: SdkCtorOptions = {
13+
networkOptions: {
14+
rpcUrl: 'https://open-campus-codex-sepolia.drpc.org',
15+
chainId: 656476,
16+
contractAddress: '0xD5C57B49b58744202EB1e67F4b7e6cB1aD06844f',
17+
},
18+
chainName: 'OpenCampus-Testnet',
19+
};

packages/youbet-sdk/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"module": "./dist/esm/index.js",
77
"exports": {
88
"import": "./dist/esm/main.js",
9-
"require": "./dist/cjs/main.js"
9+
"require": "./dist/cjs/main.js",
10+
"types": "./dist/esm/main.d.ts"
1011
},
1112
"types": "./dist/esm/main.d.ts",
1213
"scripts": {

packages/youbet-sdk/src/modules/contractModule.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class ContractModule {
3232
const hexChainId = '0x' + Number(this.sdk.sdkOptions.networkOptions.chainId).toString(16);
3333
await provider.send('wallet_addEthereumChain', [{
3434
chainId: hexChainId,
35-
chainName: 'OpenCampus-Testnet',
35+
chainName: this.sdk.sdkOptions.chainName || 'Unknown Chain',
3636
rpcUrls: [this.sdk.sdkOptions.networkOptions.rpcUrl],
3737
}]);
3838
const signer = await provider.getSigner()

packages/youbet-sdk/src/sdk.ts

+8-42
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,7 @@ import ABI from './lib/abi/bet.json';
33
import { ClientModule } from './modules/clientModule';
44
import { ContractModule } from './modules/contractModule';
55
// import { EventModule } from './modules/eventModule';
6-
7-
export enum NetworkType {
8-
Mainnet,
9-
Testnet,
10-
}
11-
12-
export type SdkCtorOptions = {
13-
privateKey?: string;
14-
networkType?: NetworkType;
15-
}
16-
17-
export type SdkOptions = {
18-
privateKey?: string;
19-
networkOptions: NetworkOptions;
20-
}
21-
22-
export type NetworkOptions = {
23-
contractAddress: string;
24-
rpcUrl: string;
25-
chainId: number;
26-
abi: any;
27-
}
6+
import { SdkCtorOptions, SdkOptions } from './types';
287

298
export class SDK {
309
private _sdkOptions: SdkOptions;
@@ -33,31 +12,18 @@ export class SDK {
3312
// private _event: EventModule;
3413

3514
constructor(options?: SdkCtorOptions) {
36-
const { networkType } = { ...options };
37-
38-
const mainnetOptions = {
39-
contractAddress: '0x902e2f3179aa959137fdc823754555b10c40f5b1',
40-
rpcUrl: 'https://rpc.linea.build',
41-
chainId: 59144,
42-
abi: ABI
43-
}
44-
45-
const testnetOptions = {
46-
contractAddress: '0xD5C57B49b58744202EB1e67F4b7e6cB1aD06844f',
47-
rpcUrl: 'https://open-campus-codex-sepolia.drpc.org',
48-
chainId: 656476,
49-
abi: ABI
50-
}
51-
52-
let networkOptions = mainnetOptions
15+
const { networkOptions } = { ...options };
5316

54-
if (networkType === NetworkType.Testnet) {
55-
networkOptions = testnetOptions
17+
if (!networkOptions) {
18+
throw new Error('Network options are required');
5619
}
5720

5821
this._sdkOptions = {
5922
privateKey: options?.privateKey,
60-
networkOptions
23+
networkOptions: {
24+
...networkOptions,
25+
abi: ABI
26+
}
6127
}
6228

6329
this._client = new ClientModule(this);

packages/youbet-sdk/src/types/index.ts

+19
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,22 @@ export interface Task {
2222
sub: string;
2323
completed: boolean;
2424
}
25+
26+
export type SdkCtorOptions = {
27+
privateKey?: string;
28+
networkOptions: Omit<NetworkOptions, 'abi'>;
29+
chainName?: string;
30+
}
31+
32+
export type SdkOptions = {
33+
privateKey?: string;
34+
networkOptions: NetworkOptions;
35+
chainName?: string;
36+
}
37+
38+
export type NetworkOptions = {
39+
contractAddress: string;
40+
rpcUrl: string;
41+
chainId: number;
42+
abi: any;
43+
}

0 commit comments

Comments
 (0)