@triadxyz/triad-protocol 3.1.2-beta → 3.1.3-beta
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/claim.d.ts +47 -0
- package/dist/claim.js +143 -0
- package/dist/index.d.ts +2 -7
- package/dist/index.js +8 -32
- package/dist/stake.d.ts +3 -0
- package/dist/types/idl_triad_protocol.json +276 -115
- package/dist/types/index.d.ts +82 -35
- package/dist/types/triad_protocol.d.ts +341 -168
- package/dist/utils/helpers.d.ts +4 -3
- package/dist/utils/helpers.js +39 -9
- package/dist/utils/pda.d.ts +2 -0
- package/dist/utils/pda.js +9 -1
- package/package.json +1 -1
package/dist/claim.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Program } from '@coral-xyz/anchor';
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
3
|
+
import { TriadProtocol } from './types/triad_protocol';
|
|
4
|
+
import { RpcOptions, CreateClaimVaultArgs, ClaimTokenArgs, UpdateClaimVaultMerkleRootArgs, UpdateClaimVaultIsActiveArgs } from './types';
|
|
5
|
+
export default class Claim {
|
|
6
|
+
private program;
|
|
7
|
+
private rpcOptions;
|
|
8
|
+
constructor(program: Program<TriadProtocol>, rpcOptions: RpcOptions);
|
|
9
|
+
/**
|
|
10
|
+
* Get All Claim Vaults
|
|
11
|
+
*/
|
|
12
|
+
getAllClaimVaults(): Promise<import("./types").ClaimVault[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Get Claim Vault
|
|
15
|
+
* @param name - Name of the claim vault
|
|
16
|
+
*/
|
|
17
|
+
getClaimVault(name: string): Promise<import("./types").ClaimVault>;
|
|
18
|
+
/**
|
|
19
|
+
* Get Claimed User
|
|
20
|
+
* @param claimVault - Claim vault
|
|
21
|
+
* @param user - User
|
|
22
|
+
*/
|
|
23
|
+
getClaimedUser(claimVault: PublicKey, user: PublicKey): Promise<import("./types").ClaimedUser>;
|
|
24
|
+
/**
|
|
25
|
+
* Claim Token
|
|
26
|
+
* @param amount - Amount to claim
|
|
27
|
+
* @param merkleProof - Merkle proof
|
|
28
|
+
*/
|
|
29
|
+
claimToken({ amount, merkleProof, mint, claimVault }: ClaimTokenArgs): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Create Claim Vault
|
|
32
|
+
* @param args - Create Claim Vault Args
|
|
33
|
+
*/
|
|
34
|
+
createClaimVault({ totalAmount, totalUsers, name, isFirstComeFirstServed, endTs, merkleRoot, mint }: CreateClaimVaultArgs): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Update Claim Vault Is Active
|
|
37
|
+
* @param isActive - Is active
|
|
38
|
+
* @param claimVault - Claim vault
|
|
39
|
+
*/
|
|
40
|
+
updateClaimVaultIsActive({ isActive, claimVault }: UpdateClaimVaultIsActiveArgs): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Update Claim Vault Merkle Root
|
|
43
|
+
* @param merkleRoot - Merkle root
|
|
44
|
+
* @param claimVault - Claim vault
|
|
45
|
+
*/
|
|
46
|
+
updateClaimVaultMerkleRoot({ merkleRoot, claimVault }: UpdateClaimVaultMerkleRootArgs): Promise<string>;
|
|
47
|
+
}
|
package/dist/claim.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
16
|
+
const helpers_1 = require("./utils/helpers");
|
|
17
|
+
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
18
|
+
const pda_1 = require("./utils/pda");
|
|
19
|
+
class Claim {
|
|
20
|
+
constructor(program, rpcOptions) {
|
|
21
|
+
this.program = program;
|
|
22
|
+
this.rpcOptions = rpcOptions;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get All Claim Vaults
|
|
26
|
+
*/
|
|
27
|
+
getAllClaimVaults() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const claimVaults = yield this.program.account.claimVault.all();
|
|
30
|
+
return claimVaults.map(({ account, publicKey }) => (0, helpers_1.formatClaimVault)(account, publicKey));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get Claim Vault
|
|
35
|
+
* @param name - Name of the claim vault
|
|
36
|
+
*/
|
|
37
|
+
getClaimVault(name) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const claimVaultPDA = (0, pda_1.getClaimVaultPDA)(this.program.programId, name);
|
|
40
|
+
const claimVault = yield this.program.account.claimVault.fetch(claimVaultPDA);
|
|
41
|
+
return (0, helpers_1.formatClaimVault)(claimVault, claimVaultPDA);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get Claimed User
|
|
46
|
+
* @param claimVault - Claim vault
|
|
47
|
+
* @param user - User
|
|
48
|
+
*/
|
|
49
|
+
getClaimedUser(claimVault, user) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const claimedUserPDA = (0, pda_1.getClaimedUserPDA)(this.program.programId, claimVault, user);
|
|
52
|
+
const claimedUser = yield this.program.account.claimedUser.fetch(claimedUserPDA);
|
|
53
|
+
return (0, helpers_1.formatClaimedUser)(claimedUser, claimedUserPDA);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Claim Token
|
|
58
|
+
* @param amount - Amount to claim
|
|
59
|
+
* @param merkleProof - Merkle proof
|
|
60
|
+
*/
|
|
61
|
+
claimToken({ amount, merkleProof, mint, claimVault }) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const ixs = [
|
|
64
|
+
yield this.program.methods
|
|
65
|
+
.claimToken({
|
|
66
|
+
amount: new anchor_1.BN(amount),
|
|
67
|
+
merkleProof
|
|
68
|
+
})
|
|
69
|
+
.accounts({
|
|
70
|
+
signer: this.program.provider.publicKey,
|
|
71
|
+
mint,
|
|
72
|
+
claimVault
|
|
73
|
+
})
|
|
74
|
+
.instruction()
|
|
75
|
+
];
|
|
76
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create Claim Vault
|
|
81
|
+
* @param args - Create Claim Vault Args
|
|
82
|
+
*/
|
|
83
|
+
createClaimVault({ totalAmount, totalUsers, name, isFirstComeFirstServed, endTs, merkleRoot, mint }) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const ixs = [
|
|
86
|
+
yield this.program.methods
|
|
87
|
+
.createClaimVault({
|
|
88
|
+
totalAmount: new anchor_1.BN(totalAmount),
|
|
89
|
+
totalUsers: new anchor_1.BN(totalUsers),
|
|
90
|
+
name,
|
|
91
|
+
isFirstComeFirstServed,
|
|
92
|
+
endTs: new anchor_1.BN(endTs),
|
|
93
|
+
merkleRoot
|
|
94
|
+
})
|
|
95
|
+
.accounts({
|
|
96
|
+
signer: this.program.provider.publicKey,
|
|
97
|
+
mint
|
|
98
|
+
})
|
|
99
|
+
.instruction()
|
|
100
|
+
];
|
|
101
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Update Claim Vault Is Active
|
|
106
|
+
* @param isActive - Is active
|
|
107
|
+
* @param claimVault - Claim vault
|
|
108
|
+
*/
|
|
109
|
+
updateClaimVaultIsActive({ isActive, claimVault }) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
const ixs = [
|
|
112
|
+
yield this.program.methods
|
|
113
|
+
.updateClaimVaultIsActive(isActive)
|
|
114
|
+
.accounts({
|
|
115
|
+
signer: this.program.provider.publicKey,
|
|
116
|
+
claimVault
|
|
117
|
+
})
|
|
118
|
+
.instruction()
|
|
119
|
+
];
|
|
120
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Update Claim Vault Merkle Root
|
|
125
|
+
* @param merkleRoot - Merkle root
|
|
126
|
+
* @param claimVault - Claim vault
|
|
127
|
+
*/
|
|
128
|
+
updateClaimVaultMerkleRoot({ merkleRoot, claimVault }) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
const ixs = [
|
|
131
|
+
yield this.program.methods
|
|
132
|
+
.updateClaimVaultMerkleRoot(merkleRoot)
|
|
133
|
+
.accounts({
|
|
134
|
+
signer: this.program.provider.publicKey,
|
|
135
|
+
claimVault
|
|
136
|
+
})
|
|
137
|
+
.instruction()
|
|
138
|
+
];
|
|
139
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.default = Claim;
|
package/dist/index.d.ts
CHANGED
|
@@ -95,9 +95,9 @@ export default class TriadProtocolClient {
|
|
|
95
95
|
getUserTrade(wallet: PublicKey, userNonce?: number): Promise<{
|
|
96
96
|
bump: number;
|
|
97
97
|
authority: PublicKey;
|
|
98
|
-
totalDeposits: BN;
|
|
99
|
-
totalWithdraws: BN;
|
|
100
98
|
padding1: number[];
|
|
99
|
+
padding2: number[];
|
|
100
|
+
padding3: number[];
|
|
101
101
|
orders: {
|
|
102
102
|
ts: BN;
|
|
103
103
|
orderId: BN;
|
|
@@ -253,11 +253,6 @@ export default class TriadProtocolClient {
|
|
|
253
253
|
draw: {};
|
|
254
254
|
};
|
|
255
255
|
}): Promise<string>;
|
|
256
|
-
/**
|
|
257
|
-
* Collect Remaining Liquidity
|
|
258
|
-
* @param marketId - The ID of the market
|
|
259
|
-
*/
|
|
260
|
-
collectRemainingLiquidity(marketId: number): Promise<string>;
|
|
261
256
|
/**
|
|
262
257
|
* Payout Order
|
|
263
258
|
* @param args.marketId - The ID of the Market
|
package/dist/index.js
CHANGED
|
@@ -432,26 +432,6 @@ class TriadProtocolClient {
|
|
|
432
432
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
433
433
|
});
|
|
434
434
|
}
|
|
435
|
-
/**
|
|
436
|
-
* Collect Remaining Liquidity
|
|
437
|
-
* @param marketId - The ID of the market
|
|
438
|
-
*/
|
|
439
|
-
collectRemainingLiquidity(marketId) {
|
|
440
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
441
|
-
const ixs = [];
|
|
442
|
-
const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
|
|
443
|
-
const market = yield this.getMarketByAddress(marketPDA);
|
|
444
|
-
ixs.push(yield this.program.methods
|
|
445
|
-
.collectRemainingLiquidity()
|
|
446
|
-
.accounts({
|
|
447
|
-
signer: this.program.provider.publicKey,
|
|
448
|
-
market: marketPDA,
|
|
449
|
-
mint: market.mint
|
|
450
|
-
})
|
|
451
|
-
.instruction());
|
|
452
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
435
|
/**
|
|
456
436
|
* Payout Order
|
|
457
437
|
* @param args.marketId - The ID of the Market
|
|
@@ -722,9 +702,7 @@ class TriadProtocolClient {
|
|
|
722
702
|
signer: this.program.provider.publicKey,
|
|
723
703
|
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
724
704
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
725
|
-
userTrade: userTradePDA
|
|
726
|
-
mint: constants_1.USDC_MINT,
|
|
727
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
|
705
|
+
userTrade: userTradePDA
|
|
728
706
|
})
|
|
729
707
|
.instruction());
|
|
730
708
|
}
|
|
@@ -787,9 +765,7 @@ class TriadProtocolClient {
|
|
|
787
765
|
signer: this.program.provider.publicKey,
|
|
788
766
|
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
789
767
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
790
|
-
userTrade: this.getUserPDA(this.program.provider.publicKey, order.userNonce)
|
|
791
|
-
mint: constants_1.USDC_MINT,
|
|
792
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
|
768
|
+
userTrade: this.getUserPDA(this.program.provider.publicKey, order.userNonce)
|
|
793
769
|
})
|
|
794
770
|
.instruction());
|
|
795
771
|
}
|
|
@@ -944,12 +920,12 @@ class TriadProtocolClient {
|
|
|
944
920
|
market: marketPDA,
|
|
945
921
|
buyerTrade: userTradePDA,
|
|
946
922
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
947
|
-
mint: constants_1.USDC_MINT,
|
|
948
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
949
923
|
sellerAuthority: new web3_js_1.PublicKey(order.authority),
|
|
950
924
|
sellerTrade: this.getUserPDA(new web3_js_1.PublicKey(order.authority), Number(order.userNonce)),
|
|
951
925
|
marketAta: (0, pda_1.getTokenATA)(marketPDA, constants_1.USDC_MINT, spl_token_1.TOKEN_PROGRAM_ID),
|
|
952
|
-
buyerAta: (0, pda_1.getTokenATA)(this.program.provider.publicKey, constants_1.USDC_MINT, spl_token_1.TOKEN_PROGRAM_ID)
|
|
926
|
+
buyerAta: (0, pda_1.getTokenATA)(this.program.provider.publicKey, constants_1.USDC_MINT, spl_token_1.TOKEN_PROGRAM_ID),
|
|
927
|
+
mint: constants_1.USDC_MINT,
|
|
928
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
|
953
929
|
})
|
|
954
930
|
.instruction());
|
|
955
931
|
remainingUSDC = remainingUSDC.sub(usdcAmount);
|
|
@@ -1024,10 +1000,10 @@ class TriadProtocolClient {
|
|
|
1024
1000
|
buyerAuthority: new web3_js_1.PublicKey(order.authority),
|
|
1025
1001
|
buyerTrade: this.getUserPDA(new web3_js_1.PublicKey(order.authority), Number(order.userNonce)),
|
|
1026
1002
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
1027
|
-
mint: constants_1.USDC_MINT,
|
|
1028
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
1029
1003
|
marketAta: (0, pda_1.getTokenATA)(marketPDA, constants_1.USDC_MINT, spl_token_1.TOKEN_PROGRAM_ID),
|
|
1030
|
-
sellerTrade: this.getUserPDA(this.program.provider.publicKey, inputOrder.userNonce)
|
|
1004
|
+
sellerTrade: this.getUserPDA(this.program.provider.publicKey, inputOrder.userNonce),
|
|
1005
|
+
mint: constants_1.USDC_MINT,
|
|
1006
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
|
1031
1007
|
})
|
|
1032
1008
|
.instruction());
|
|
1033
1009
|
}
|