@triadxyz/triad-protocol 4.0.4 → 4.0.6
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/README.md +99 -12
- package/dist/customer.d.ts +3 -10
- package/dist/customer.js +5 -22
- package/dist/index.d.ts +7 -4
- package/dist/index.js +11 -8
- package/dist/poseidon.d.ts +0 -21
- package/dist/poseidon.js +0 -49
- package/dist/predictor.d.ts +0 -1
- package/dist/stake.d.ts +0 -1
- package/dist/trade.d.ts +0 -1
- package/dist/types/customer.d.ts +0 -6
- package/dist/types/idl_triad_protocol.json +283 -276
- package/dist/types/index.d.ts +2 -1
- package/dist/types/predictor.d.ts +0 -1
- package/dist/types/trade.d.ts +0 -1
- package/dist/types/triad_protocol.d.ts +310 -274
- package/dist/utils/constants.d.ts +0 -3
- package/dist/utils/constants.js +1 -3
- package/dist/utils/pda.d.ts +0 -1
- package/package.json +6 -10
package/README.md
CHANGED
|
@@ -1,27 +1,114 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<h1>Triad Protocol</h1>
|
|
2
|
+
<h1>Triad Protocol SDK</h1>
|
|
3
|
+
<p>The official TypeScript SDK for interacting with the Triad Protocol on Solana.</p>
|
|
3
4
|
</div>
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
---
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
## ✨ Features
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
- **Market Management**: Create and manage prediction markets (Standard & Pyth-based).
|
|
11
|
+
- **Order Book**: Place limit/market bids and asks, cancel orders, and claim payouts.
|
|
12
|
+
- **Liquidity Pools**: Create and manage liquidity pools for groups of markets.
|
|
13
|
+
- **Staking**: Stake tokens, request unstakes, and claim rewards.
|
|
14
|
+
- **Predictor Accounts**: Initialize and manage user predictor profiles.
|
|
15
|
+
- **Customer Management**: Register frontends and manage custom fee structures.
|
|
10
16
|
|
|
11
|
-
## Quick Setup
|
|
17
|
+
## 🚀 Quick Setup
|
|
12
18
|
|
|
13
19
|
### Install
|
|
14
20
|
|
|
15
|
-
|
|
21
|
+
```bash
|
|
22
|
+
# npm
|
|
23
|
+
npm install @triadxyz/triad-protocol
|
|
16
24
|
|
|
17
|
-
|
|
25
|
+
# yarn
|
|
26
|
+
yarn add @triadxyz/triad-protocol
|
|
27
|
+
```
|
|
18
28
|
|
|
19
|
-
|
|
20
|
-
|
|
29
|
+
### Initialize SDK
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
33
|
+
import { TriadProtocol } from '@triadxyz/triad-protocol';
|
|
34
|
+
import { Wallet } from '@coral-xyz/anchor';
|
|
35
|
+
|
|
36
|
+
const connection = new Connection("https://api.mainnet-beta.solana.com");
|
|
37
|
+
const wallet = ...; // Your Solana wallet
|
|
38
|
+
|
|
39
|
+
const sdk = new TriadProtocol(connection, wallet, {
|
|
40
|
+
commitment: 'confirmed'
|
|
41
|
+
});
|
|
21
42
|
```
|
|
22
43
|
|
|
23
|
-
|
|
44
|
+
## 📖 Usage Examples
|
|
24
45
|
|
|
25
|
-
|
|
26
|
-
|
|
46
|
+
### Fetching Markets
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
// Get all active markets
|
|
50
|
+
const markets = await sdk.getAllMarkets()
|
|
51
|
+
|
|
52
|
+
// Get a specific market by ID
|
|
53
|
+
const market = await sdk.getMarketById(123)
|
|
54
|
+
console.log(`Question: ${market.question}`)
|
|
27
55
|
```
|
|
56
|
+
|
|
57
|
+
### Creating a Market
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
await sdk.createMarket({
|
|
61
|
+
markets: [
|
|
62
|
+
{
|
|
63
|
+
marketId: 456,
|
|
64
|
+
question: 'Will Bitcoin reach $100k by 2026?',
|
|
65
|
+
startTime: Math.floor(Date.now() / 1000),
|
|
66
|
+
endTime: 1767225600, // Jan 1, 2026
|
|
67
|
+
feeBps: 100, // 1%
|
|
68
|
+
payoutFee: 50 // 0.5%
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
customer: new PublicKey('...'),
|
|
72
|
+
poolId: null
|
|
73
|
+
})
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Placing a Bet (Trade)
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
// Place a bid (YES) on market 456
|
|
80
|
+
await sdk.trade.placeBidOrder({
|
|
81
|
+
marketId: 456,
|
|
82
|
+
amount: new BN(1 * 1e6), // 1 USDC
|
|
83
|
+
price: 500, // 50% probability
|
|
84
|
+
direction: WinningDirection.Yes
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Staking
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
// Stake tokens
|
|
92
|
+
await sdk.stake.stakeToken({
|
|
93
|
+
amount: new BN(1000000000),
|
|
94
|
+
mint: new PublicKey('...')
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
// Claim rewards
|
|
98
|
+
await sdk.stake.claimStakeRewards()
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## 🛠 Developer Guide
|
|
102
|
+
|
|
103
|
+
To generate the full API documentation (TypeDoc):
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
yarn install
|
|
107
|
+
yarn docs
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
The documentation will be available in the `docs/` folder.
|
|
111
|
+
|
|
112
|
+
## 📄 License
|
|
113
|
+
|
|
114
|
+
ISC
|
package/dist/customer.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
/// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
|
|
2
1
|
import { PublicKey } from '@solana/web3.js';
|
|
3
2
|
import { Program } from '@coral-xyz/anchor';
|
|
4
3
|
import { TriadProtocol } from './types/triad_protocol';
|
|
5
4
|
import { RpcOptions } from './types';
|
|
6
|
-
import { CreateCustomerArgs
|
|
5
|
+
import { CreateCustomerArgs } from './types/customer';
|
|
7
6
|
export default class Customer {
|
|
8
7
|
private program;
|
|
9
8
|
private rpcOptions;
|
|
@@ -16,12 +15,12 @@ export default class Customer {
|
|
|
16
15
|
* Get Costumer By Wallet Address
|
|
17
16
|
* @param wallet - The wallet address of the customer
|
|
18
17
|
*/
|
|
19
|
-
getCustomerByWallet(wallet: PublicKey): Promise<import("
|
|
18
|
+
getCustomerByWallet(wallet: PublicKey): Promise<import("./types/customer").Customer>;
|
|
20
19
|
/**
|
|
21
20
|
* Get Customer By ID
|
|
22
21
|
* @param customerId - The ID of the customer
|
|
23
22
|
*/
|
|
24
|
-
getCustomerById(customerId: number): Promise<import("
|
|
23
|
+
getCustomerById(customerId: number): Promise<import("./types/customer").Customer>;
|
|
25
24
|
/**
|
|
26
25
|
* Create Customer
|
|
27
26
|
* @param args.id - The ID of the customer
|
|
@@ -30,10 +29,4 @@ export default class Customer {
|
|
|
30
29
|
* @param args.feeRecipient - The fee recipient of the customer
|
|
31
30
|
*/
|
|
32
31
|
createCustomer({ id, name, authority, feeRecipient }: CreateCustomerArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
33
|
-
/**
|
|
34
|
-
* Update Customer Fee
|
|
35
|
-
* @param customerId - Customer ID
|
|
36
|
-
* @param feeBps - Fee in basis points
|
|
37
|
-
*/
|
|
38
|
-
updateCustomerFee({ customerId, feeBps, feeRecipient }: UpdateCustomerFeeArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
39
32
|
}
|
package/dist/customer.js
CHANGED
|
@@ -12,8 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const helpers_1 = require("./utils/helpers");
|
|
15
16
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
16
|
-
const
|
|
17
|
+
const pda_1 = require("./utils/pda");
|
|
17
18
|
class Customer {
|
|
18
19
|
constructor(program, rpcOptions) {
|
|
19
20
|
this.program = program;
|
|
@@ -42,7 +43,7 @@ class Customer {
|
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
]);
|
|
45
|
-
return (0,
|
|
46
|
+
return (0, helpers_1.formatCustomer)(customer.account, customer.publicKey);
|
|
46
47
|
});
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
@@ -51,9 +52,9 @@ class Customer {
|
|
|
51
52
|
*/
|
|
52
53
|
getCustomerById(customerId) {
|
|
53
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
const customerPDA = (0,
|
|
55
|
+
const customerPDA = (0, pda_1.getCustomerPDA)(this.program.programId, customerId);
|
|
55
56
|
const customer = yield this.program.account.customer.fetch(customerPDA, this.rpcOptions.commitment);
|
|
56
|
-
return (0,
|
|
57
|
+
return (0, helpers_1.formatCustomer)(customer, customerPDA);
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
60
|
/**
|
|
@@ -76,23 +77,5 @@ class Customer {
|
|
|
76
77
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
77
78
|
});
|
|
78
79
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Update Customer Fee
|
|
81
|
-
* @param customerId - Customer ID
|
|
82
|
-
* @param feeBps - Fee in basis points
|
|
83
|
-
*/
|
|
84
|
-
updateCustomerFee({ customerId, feeBps, feeRecipient }) {
|
|
85
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
const ixs = [
|
|
87
|
-
yield this.program.methods
|
|
88
|
-
.updateCustomerFee({ id: customerId, feeBps, feeRecipient })
|
|
89
|
-
.accounts({
|
|
90
|
-
signer: this.program.provider.publicKey
|
|
91
|
-
})
|
|
92
|
-
.instruction()
|
|
93
|
-
];
|
|
94
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
80
|
}
|
|
98
81
|
exports.default = Customer;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
|
|
2
1
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
3
2
|
import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
|
|
4
3
|
import { TriadProtocol as TriadProtocolIDL } from './types/triad_protocol';
|
|
@@ -104,7 +103,7 @@ export default class TriadProtocol {
|
|
|
104
103
|
* @param question - The question of the pool
|
|
105
104
|
* @param markets - The markets of the pool
|
|
106
105
|
*/
|
|
107
|
-
createPool({ poolId, question, markets, customer, startTime, endTime, feeBps, payoutFee, isFast }: CreatePoolArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
106
|
+
createPool({ poolId, question, markets, customer, startTime, endTime, feeBps, payoutFee, isFast, isPyth, feedId }: CreatePoolArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
108
107
|
/**
|
|
109
108
|
* Update Market Winning Direction
|
|
110
109
|
* @param args.marketId - The ID of the Market
|
|
@@ -143,9 +142,13 @@ export default class TriadProtocol {
|
|
|
143
142
|
}[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
144
143
|
/**
|
|
145
144
|
* Close Order Book
|
|
146
|
-
* @param
|
|
145
|
+
* @param markets.id - Market IDs
|
|
146
|
+
* @param markets.authority - The authority of the market
|
|
147
147
|
*/
|
|
148
|
-
closeOrderBook(
|
|
148
|
+
closeOrderBook(markets: {
|
|
149
|
+
id: number;
|
|
150
|
+
authority: PublicKey;
|
|
151
|
+
}[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
149
152
|
/**
|
|
150
153
|
* Update Pool Question
|
|
151
154
|
* @param poolId - Pool ID
|
package/dist/index.js
CHANGED
|
@@ -269,7 +269,7 @@ class TriadProtocol {
|
|
|
269
269
|
* @param question - The question of the pool
|
|
270
270
|
* @param markets - The markets of the pool
|
|
271
271
|
*/
|
|
272
|
-
createPool({ poolId, question, markets, customer, startTime, endTime, feeBps, payoutFee, isFast }) {
|
|
272
|
+
createPool({ poolId, question, markets, customer, startTime, endTime, feeBps, payoutFee, isFast, isPyth, feedId }) {
|
|
273
273
|
return __awaiter(this, void 0, void 0, function* () {
|
|
274
274
|
if (question.length > 80) {
|
|
275
275
|
throw new Error('Pool question must be less than 80 characters');
|
|
@@ -280,7 +280,9 @@ class TriadProtocol {
|
|
|
280
280
|
.createPool({
|
|
281
281
|
poolId: new bn_js_1.default(poolId),
|
|
282
282
|
question: (0, helpers_1.encodeString)(question, 80),
|
|
283
|
-
isFast
|
|
283
|
+
isFast,
|
|
284
|
+
isPyth,
|
|
285
|
+
feedId
|
|
284
286
|
})
|
|
285
287
|
.accounts({
|
|
286
288
|
signer: this.program.provider.publicKey,
|
|
@@ -422,18 +424,19 @@ class TriadProtocol {
|
|
|
422
424
|
}
|
|
423
425
|
/**
|
|
424
426
|
* Close Order Book
|
|
425
|
-
* @param
|
|
427
|
+
* @param markets.id - Market IDs
|
|
428
|
+
* @param markets.authority - The authority of the market
|
|
426
429
|
*/
|
|
427
|
-
closeOrderBook(
|
|
430
|
+
closeOrderBook(markets) {
|
|
428
431
|
return __awaiter(this, void 0, void 0, function* () {
|
|
429
432
|
const ixs = [];
|
|
430
|
-
for (const
|
|
433
|
+
for (const market of markets) {
|
|
431
434
|
ixs.push(yield this.program.methods
|
|
432
435
|
.closeOrderBook()
|
|
433
436
|
.accounts({
|
|
434
|
-
|
|
435
|
-
market: (0, pda_1.getMarketPDA)(this.program.programId,
|
|
436
|
-
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId,
|
|
437
|
+
authority: market.authority,
|
|
438
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, market.id),
|
|
439
|
+
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, market.id)
|
|
437
440
|
})
|
|
438
441
|
.instruction());
|
|
439
442
|
}
|
package/dist/poseidon.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
|
|
2
1
|
import { Program } from '@coral-xyz/anchor';
|
|
3
2
|
import { PublicKey } from '@solana/web3.js';
|
|
4
3
|
import { TriadProtocol } from './types/triad_protocol';
|
|
@@ -7,17 +6,6 @@ export default class Poseidon {
|
|
|
7
6
|
private program;
|
|
8
7
|
private rpcOptions;
|
|
9
8
|
constructor(program: Program<TriadProtocol>, rpcOptions: RpcOptions);
|
|
10
|
-
/**
|
|
11
|
-
* Transfer Poseidon
|
|
12
|
-
* @param args.poseidonAsset - Poseidon Asset
|
|
13
|
-
* @param args.ticketAsset - Ticket Asset
|
|
14
|
-
* @param args.ticketNumber - Ticket Number
|
|
15
|
-
*/
|
|
16
|
-
transferPoseidon(poseidons: {
|
|
17
|
-
poseidonAsset: PublicKey;
|
|
18
|
-
ticketAsset: PublicKey;
|
|
19
|
-
ticketNumber: number;
|
|
20
|
-
}[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
21
9
|
/**
|
|
22
10
|
* Withdraw Poseidon
|
|
23
11
|
* @param poseidonAsset - Poseidon Asset - CORE PublicKey
|
|
@@ -41,13 +29,4 @@ export default class Poseidon {
|
|
|
41
29
|
* @param poseidonAsset - Poseidon Asset
|
|
42
30
|
*/
|
|
43
31
|
removeTraderPoseidon(user: PublicKey, poseidonAsset: PublicKey): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
44
|
-
/**
|
|
45
|
-
* Update Metadata
|
|
46
|
-
* @param poseidons.uri - URI
|
|
47
|
-
* @param poseidons.asset - Asset
|
|
48
|
-
*/
|
|
49
|
-
updateMetadata(poseidons: {
|
|
50
|
-
uri: string;
|
|
51
|
-
asset: PublicKey;
|
|
52
|
-
}[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
53
32
|
}
|
package/dist/poseidon.js
CHANGED
|
@@ -20,33 +20,6 @@ class Poseidon {
|
|
|
20
20
|
this.program = program;
|
|
21
21
|
this.rpcOptions = rpcOptions;
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Transfer Poseidon
|
|
25
|
-
* @param args.poseidonAsset - Poseidon Asset
|
|
26
|
-
* @param args.ticketAsset - Ticket Asset
|
|
27
|
-
* @param args.ticketNumber - Ticket Number
|
|
28
|
-
*/
|
|
29
|
-
transferPoseidon(poseidons) {
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
const ixs = [];
|
|
32
|
-
for (const poseidon of poseidons) {
|
|
33
|
-
ixs.push(yield this.program.methods
|
|
34
|
-
.transferPoseidon()
|
|
35
|
-
.accounts({
|
|
36
|
-
signer: this.program.provider.publicKey,
|
|
37
|
-
nft: (0, pda_1.getNftPDA)(this.program.programId, poseidon.ticketNumber),
|
|
38
|
-
poseidonAsset: poseidon.poseidonAsset,
|
|
39
|
-
ticketAsset: poseidon.ticketAsset,
|
|
40
|
-
poseidonCollection: (0, pda_1.getCollectionPDA)(this.program.programId, constants_1.POSEIDON_COLLECTION_SYMBOL),
|
|
41
|
-
ticketCollection: (0, pda_1.getCollectionPDA)(this.program.programId, constants_1.TICKET_COLLECTION_SYMBOL),
|
|
42
|
-
coreTicketCollection: constants_1.TICKET_CORE_COLLECTION,
|
|
43
|
-
corePoseidonCollection: constants_1.POSEIDON_CORE_COLLECTION
|
|
44
|
-
})
|
|
45
|
-
.instruction());
|
|
46
|
-
}
|
|
47
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
23
|
/**
|
|
51
24
|
* Withdraw Poseidon
|
|
52
25
|
* @param poseidonAsset - Poseidon Asset - CORE PublicKey
|
|
@@ -127,27 +100,5 @@ class Poseidon {
|
|
|
127
100
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
128
101
|
});
|
|
129
102
|
}
|
|
130
|
-
/**
|
|
131
|
-
* Update Metadata
|
|
132
|
-
* @param poseidons.uri - URI
|
|
133
|
-
* @param poseidons.asset - Asset
|
|
134
|
-
*/
|
|
135
|
-
updateMetadata(poseidons) {
|
|
136
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
const ixs = [];
|
|
138
|
-
for (const poseidon of poseidons) {
|
|
139
|
-
ixs.push(yield this.program.methods
|
|
140
|
-
.updateMetadata(poseidon.uri)
|
|
141
|
-
.accounts({
|
|
142
|
-
signer: this.program.provider.publicKey,
|
|
143
|
-
corePoseidonCollection: constants_1.POSEIDON_CORE_COLLECTION,
|
|
144
|
-
poseidonCollection: (0, pda_1.getCollectionPDA)(this.program.programId, constants_1.POSEIDON_COLLECTION_SYMBOL),
|
|
145
|
-
poseidonAsset: poseidon.asset
|
|
146
|
-
})
|
|
147
|
-
.instruction());
|
|
148
|
-
}
|
|
149
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
103
|
}
|
|
153
104
|
exports.default = Poseidon;
|
package/dist/predictor.d.ts
CHANGED
package/dist/stake.d.ts
CHANGED
package/dist/trade.d.ts
CHANGED
package/dist/types/customer.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
|
|
2
1
|
import { PublicKey } from '@solana/web3.js';
|
|
3
2
|
export type Customer = {
|
|
4
3
|
id: number;
|
|
@@ -15,8 +14,3 @@ export type CreateCustomerArgs = {
|
|
|
15
14
|
authority: PublicKey;
|
|
16
15
|
feeRecipient: PublicKey;
|
|
17
16
|
};
|
|
18
|
-
export type UpdateCustomerFeeArgs = {
|
|
19
|
-
customerId: number;
|
|
20
|
-
feeBps: number;
|
|
21
|
-
feeRecipient: PublicKey | null;
|
|
22
|
-
};
|