@solworks/poll-api-client 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +3 -3
- package/dist/client.js +6 -6
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +44 -19
- package/package.json +1 -1
- package/tests/fixtures/index.ts +14 -8
- package/tests/unit/client.test.ts +2 -2
package/dist/client.d.ts
CHANGED
|
@@ -20,12 +20,12 @@ export declare class PollClient {
|
|
|
20
20
|
getBet(id: string): Promise<Bet>;
|
|
21
21
|
getMyBets(): Promise<Bet[]>;
|
|
22
22
|
createBet(params: CreateBetParams): Promise<Bet>;
|
|
23
|
-
joinBet(
|
|
23
|
+
joinBet(marketPubkey: string): Promise<unknown>;
|
|
24
24
|
placeWager(params: PlaceWagerParams): Promise<unknown>;
|
|
25
25
|
cancelWager(params: CancelWagerParams): Promise<unknown>;
|
|
26
|
-
initiateVote(
|
|
26
|
+
initiateVote(marketPubkey: string): Promise<unknown>;
|
|
27
27
|
vote(params: VoteParams): Promise<unknown>;
|
|
28
|
-
settleBet(
|
|
28
|
+
settleBet(marketPubkey: string): Promise<unknown>;
|
|
29
29
|
getProbabilityHistory(betAddress: string): Promise<ProbabilityPoint[]>;
|
|
30
30
|
getMyWagers(params?: {
|
|
31
31
|
active?: boolean;
|
package/dist/client.js
CHANGED
|
@@ -123,8 +123,8 @@ export class PollClient {
|
|
|
123
123
|
const res = await this.request('POST', '/api/bets-usdc', params);
|
|
124
124
|
return res.data;
|
|
125
125
|
}
|
|
126
|
-
async joinBet(
|
|
127
|
-
return this.request('POST', '/api/bets-usdc/join', {
|
|
126
|
+
async joinBet(marketPubkey) {
|
|
127
|
+
return this.request('POST', '/api/bets-usdc/join', { marketPubkey });
|
|
128
128
|
}
|
|
129
129
|
async placeWager(params) {
|
|
130
130
|
return this.request('POST', '/api/bets-usdc/wager', params);
|
|
@@ -132,16 +132,16 @@ export class PollClient {
|
|
|
132
132
|
async cancelWager(params) {
|
|
133
133
|
return this.request('POST', '/api/bets-usdc/wager/cancel', params);
|
|
134
134
|
}
|
|
135
|
-
async initiateVote(
|
|
135
|
+
async initiateVote(marketPubkey) {
|
|
136
136
|
return this.request('POST', '/api/bets-usdc/vote/initiate', {
|
|
137
|
-
|
|
137
|
+
marketPubkey,
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
140
|
async vote(params) {
|
|
141
141
|
return this.request('POST', '/api/bets-usdc/vote', params);
|
|
142
142
|
}
|
|
143
|
-
async settleBet(
|
|
144
|
-
return this.request('POST', '/api/bets-usdc/settle', {
|
|
143
|
+
async settleBet(marketPubkey) {
|
|
144
|
+
return this.request('POST', '/api/bets-usdc/settle', { marketPubkey });
|
|
145
145
|
}
|
|
146
146
|
async getProbabilityHistory(betAddress) {
|
|
147
147
|
// API returns { data: { betAddress, dataPoints: [...] } }
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { PollClient } from './client.js';
|
|
2
2
|
export { PollApiError } from './errors.js';
|
|
3
|
-
export type { PollClientConfig, Bet, UserAccount, UserProfile, Balance, Wager, LeaderboardEntry, Friend, WalletTransaction, Notification, StreakInfo, ProbabilityPoint, CreateBetParams, PlaceWagerParams, VoteParams, CancelWagerParams, ApiToken, } from './types.js';
|
|
3
|
+
export type { PollClientConfig, Side, Bet, BetWager, BetVote, UserAccount, UserProfile, Balance, Wager, LeaderboardEntry, Friend, WalletTransaction, Notification, StreakInfo, ProbabilityPoint, CreateBetParams, PlaceWagerParams, VoteParams, CancelWagerParams, ApiToken, } from './types.js';
|
package/dist/types.d.ts
CHANGED
|
@@ -4,15 +4,35 @@ export interface PollClientConfig {
|
|
|
4
4
|
fetch?: typeof globalThis.fetch;
|
|
5
5
|
clientId?: string;
|
|
6
6
|
}
|
|
7
|
+
export type Side = 'for' | 'against';
|
|
7
8
|
export interface Bet {
|
|
8
|
-
|
|
9
|
+
betAddress: string;
|
|
9
10
|
question: string;
|
|
10
|
-
options: string[];
|
|
11
11
|
status: string;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
creator: string;
|
|
13
|
+
creatorDisplayName: string;
|
|
14
|
+
totalOiFor: number;
|
|
15
|
+
totalOiAgainst: number;
|
|
16
|
+
inviteCode: string;
|
|
17
|
+
isPublic: boolean;
|
|
18
|
+
createdAt: number;
|
|
19
|
+
updatedAt: number;
|
|
20
|
+
wagers: BetWager[];
|
|
21
|
+
votes: BetVote[];
|
|
22
|
+
userRole?: 'creator' | 'wagered' | 'joined' | null;
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface BetWager {
|
|
26
|
+
user: string;
|
|
27
|
+
userDisplayName?: string;
|
|
28
|
+
amount: number;
|
|
29
|
+
outcome: string;
|
|
30
|
+
status: string;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
export interface BetVote {
|
|
34
|
+
user: string;
|
|
35
|
+
userDisplayName?: string;
|
|
16
36
|
[key: string]: unknown;
|
|
17
37
|
}
|
|
18
38
|
export interface UserAccount {
|
|
@@ -38,11 +58,12 @@ export interface Balance {
|
|
|
38
58
|
error: string | null;
|
|
39
59
|
}
|
|
40
60
|
export interface Wager {
|
|
41
|
-
|
|
42
|
-
|
|
61
|
+
user: string;
|
|
62
|
+
userDisplayName?: string;
|
|
43
63
|
amount: number;
|
|
44
|
-
|
|
64
|
+
outcome: string;
|
|
45
65
|
status: string;
|
|
66
|
+
betAddress?: string;
|
|
46
67
|
[key: string]: unknown;
|
|
47
68
|
}
|
|
48
69
|
export interface LeaderboardEntry {
|
|
@@ -89,26 +110,30 @@ export interface ProbabilityPoint {
|
|
|
89
110
|
}
|
|
90
111
|
export interface CreateBetParams {
|
|
91
112
|
question: string;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
113
|
+
expectedUserCount?: number;
|
|
114
|
+
minimumVoteCount?: number;
|
|
115
|
+
isCreatorResolver?: boolean;
|
|
116
|
+
isPublic?: boolean;
|
|
117
|
+
allWagersDueBy?: string;
|
|
118
|
+
minimumWagerAmount?: number;
|
|
119
|
+
customOptionFor?: string;
|
|
120
|
+
customOptionAgainst?: string;
|
|
96
121
|
[key: string]: unknown;
|
|
97
122
|
}
|
|
98
123
|
export interface PlaceWagerParams {
|
|
99
|
-
|
|
100
|
-
optionIndex: number;
|
|
124
|
+
marketPubkey: string;
|
|
101
125
|
amount: number;
|
|
126
|
+
side: Side;
|
|
127
|
+
jito?: boolean;
|
|
102
128
|
[key: string]: unknown;
|
|
103
129
|
}
|
|
104
130
|
export interface VoteParams {
|
|
105
|
-
|
|
106
|
-
|
|
131
|
+
marketPubkey: string;
|
|
132
|
+
outcome: Side;
|
|
107
133
|
[key: string]: unknown;
|
|
108
134
|
}
|
|
109
135
|
export interface CancelWagerParams {
|
|
110
|
-
|
|
111
|
-
wagerAddress: string;
|
|
136
|
+
marketPubkey: string;
|
|
112
137
|
[key: string]: unknown;
|
|
113
138
|
}
|
|
114
139
|
export interface ApiToken {
|
package/package.json
CHANGED
package/tests/fixtures/index.ts
CHANGED
|
@@ -8,14 +8,19 @@ function nextId(): string {
|
|
|
8
8
|
|
|
9
9
|
export function createBetFixture(overrides?: Partial<Bet>): Bet {
|
|
10
10
|
return {
|
|
11
|
-
|
|
11
|
+
betAddress: `bet_${nextId()}`,
|
|
12
12
|
question: 'Will BTC hit $100k by end of year?',
|
|
13
|
-
options: ['Yes', 'No'],
|
|
14
13
|
status: 'OPEN',
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
creator: 'SoLAddr123',
|
|
15
|
+
creatorDisplayName: 'TestCreator',
|
|
16
|
+
totalOiFor: 3000,
|
|
17
|
+
totalOiAgainst: 2000,
|
|
18
18
|
inviteCode: 'ABC123',
|
|
19
|
+
isPublic: true,
|
|
20
|
+
createdAt: Date.now(),
|
|
21
|
+
updatedAt: Date.now(),
|
|
22
|
+
wagers: [],
|
|
23
|
+
votes: [],
|
|
19
24
|
...overrides,
|
|
20
25
|
};
|
|
21
26
|
}
|
|
@@ -35,11 +40,12 @@ export function createUserFixture(overrides?: Partial<UserAccount>): UserAccount
|
|
|
35
40
|
|
|
36
41
|
export function createWagerFixture(overrides?: Partial<Wager>): Wager {
|
|
37
42
|
return {
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
user: `SoLAddr_${nextId()}`,
|
|
44
|
+
userDisplayName: 'TestUser',
|
|
40
45
|
amount: 100,
|
|
41
|
-
|
|
46
|
+
outcome: 'for',
|
|
42
47
|
status: 'PLACED',
|
|
48
|
+
betAddress: `bet_${nextId()}`,
|
|
43
49
|
...overrides,
|
|
44
50
|
};
|
|
45
51
|
}
|
|
@@ -25,7 +25,7 @@ describe('PollClient core request logic', () => {
|
|
|
25
25
|
|
|
26
26
|
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
27
27
|
const [url, init] = mockFetch.mock.calls[0];
|
|
28
|
-
expect(url).toBe('https://api.poll.fun/api/user
|
|
28
|
+
expect(url).toBe('https://api.poll.fun/api/user');
|
|
29
29
|
expect(init.headers['Authorization']).toBe('Bearer my-secret-token');
|
|
30
30
|
expect(init.headers['Content-Type']).toBe('application/json');
|
|
31
31
|
});
|
|
@@ -161,6 +161,6 @@ describe('PollClient core request logic', () => {
|
|
|
161
161
|
await client.getAccount();
|
|
162
162
|
|
|
163
163
|
const [url] = mockFetch.mock.calls[0];
|
|
164
|
-
expect(url).toBe('https://api.poll.fun/api/user
|
|
164
|
+
expect(url).toBe('https://api.poll.fun/api/user');
|
|
165
165
|
});
|
|
166
166
|
});
|