@triadxyz/triad-protocol 0.5.0-beta → 0.5.2-beta.devnet

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.
@@ -2,7 +2,7 @@ export declare const TRIAD_PROTOCOL_PROGRAM_ID = "TRDwq3BN4mP3m9KsuNUWSN6QDff93V
2
2
  export declare const ATA_PROGRAM_ID = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
3
3
  export declare const ADMIN = "";
4
4
  export declare const VERIFIER = "42n6BHufivUKrb5Bi6tXbMZvM8NHovrDLX1Rt5w2a919";
5
- export declare const STAKE_SEASON = "Triad Share 1";
5
+ export declare const STAKE_VAULT_NAME = "Triad Share 1";
6
6
  export declare const TTRIAD_DECIMALS = 6;
7
7
  export declare const TTRIAD_MINT = "t3DohmswhKk94PPbPYwA6ZKACyY3y5kbcqeQerAJjmV";
8
8
  export declare const TTRIAD_FEE = 2;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NOOP_PROGRAM_ID = exports.ORE_PROGRAM_ID = exports.TTRIAD_FEE = exports.TTRIAD_MINT = exports.TTRIAD_DECIMALS = exports.STAKE_SEASON = exports.VERIFIER = exports.ADMIN = exports.ATA_PROGRAM_ID = exports.TRIAD_PROTOCOL_PROGRAM_ID = void 0;
3
+ exports.NOOP_PROGRAM_ID = exports.ORE_PROGRAM_ID = exports.TTRIAD_FEE = exports.TTRIAD_MINT = exports.TTRIAD_DECIMALS = exports.STAKE_VAULT_NAME = exports.VERIFIER = exports.ADMIN = exports.ATA_PROGRAM_ID = exports.TRIAD_PROTOCOL_PROGRAM_ID = void 0;
4
4
  exports.TRIAD_PROTOCOL_PROGRAM_ID = 'TRDwq3BN4mP3m9KsuNUWSN6QDff93VKGSwE95Jbr9Ss';
5
5
  exports.ATA_PROGRAM_ID = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
6
6
  exports.ADMIN = '';
7
7
  exports.VERIFIER = '42n6BHufivUKrb5Bi6tXbMZvM8NHovrDLX1Rt5w2a919';
8
- exports.STAKE_SEASON = 'Triad Share 1';
8
+ exports.STAKE_VAULT_NAME = 'Triad Share 1';
9
9
  exports.TTRIAD_DECIMALS = 6;
10
10
  exports.TTRIAD_MINT = 't3DohmswhKk94PPbPYwA6ZKACyY3y5kbcqeQerAJjmV';
11
11
  exports.TTRIAD_FEE = 2;
package/dist/vault.d.ts CHANGED
@@ -45,35 +45,4 @@ export default class Vault {
45
45
  longPositionsOpened: BN;
46
46
  shortPositionsOpened: BN;
47
47
  }>;
48
- /**
49
- * Open Position
50
- * @param tickerPDA - Ticker PDA
51
- * @param amount - The amount to deposit
52
- * @param position - Long or Short
53
- * @param mint - Token mint for the vault (e.g. USDC)
54
- */
55
- openPosition({ tickerPDA, amount, position, mint }: {
56
- tickerPDA: PublicKey;
57
- amount: string;
58
- position: 'Long' | 'Short';
59
- mint: PublicKey;
60
- }, options?: {
61
- priorityFee: number;
62
- }): Promise<string>;
63
- /**
64
- * Withdraw from a vault
65
- * @param tickerPDA - Ticker PDA
66
- * @param amount - The amount to deposit
67
- * @param position - Long or Short
68
- * @param mint - Token mint for the vault (e.g. USDC)
69
- * @param positionPubkey - The position public key
70
- *
71
- */
72
- closePosition({ tickerPDA, mint, positionIndex }: {
73
- tickerPDA: PublicKey;
74
- mint: PublicKey;
75
- positionIndex: number;
76
- }, options?: {
77
- priorityFee: number;
78
- }): Promise<string>;
79
48
  }
package/dist/vault.js CHANGED
@@ -9,8 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const anchor_1 = require("@coral-xyz/anchor");
13
- const web3_js_1 = require("@solana/web3.js");
14
12
  const helpers_1 = require("./utils/helpers");
15
13
  const spl_token_1 = require("@solana/spl-token");
16
14
  class Vault {
@@ -42,146 +40,5 @@ class Vault {
42
40
  }
43
41
  });
44
42
  }
45
- /**
46
- * Open Position
47
- * @param tickerPDA - Ticker PDA
48
- * @param amount - The amount to deposit
49
- * @param position - Long or Short
50
- * @param mint - Token mint for the vault (e.g. USDC)
51
- */
52
- openPosition({ tickerPDA, amount, position, mint }, options) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- try {
55
- const UserPositionPDA = (0, helpers_1.getUserPositionAddressSync)(this.program.programId, this.provider.wallet.publicKey, tickerPDA);
56
- const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, tickerPDA);
57
- const userTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(mint, this.provider.wallet.publicKey);
58
- let hasUserPosition = false;
59
- try {
60
- yield this.program.account.userPosition.fetch(UserPositionPDA);
61
- hasUserPosition = true;
62
- }
63
- catch (_a) { }
64
- const instructions = [];
65
- if (options === null || options === void 0 ? void 0 : options.priorityFee) {
66
- instructions.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
67
- microLamports: options.priorityFee
68
- }));
69
- }
70
- if (!hasUserPosition) {
71
- instructions.push(yield this.program.methods
72
- .createUserPosition()
73
- .accounts({
74
- signer: this.provider.wallet.publicKey,
75
- ticker: tickerPDA
76
- })
77
- .instruction());
78
- }
79
- instructions.push(yield this.program.methods
80
- .openPosition({
81
- amount: new anchor_1.BN(amount),
82
- isLong: position === 'Long'
83
- })
84
- .accounts({
85
- userPosition: UserPositionPDA,
86
- ticker: tickerPDA,
87
- vault: VaultPDA,
88
- userTokenAccount
89
- })
90
- .instruction());
91
- const { blockhash } = yield this.provider.connection.getLatestBlockhash();
92
- const message = new web3_js_1.TransactionMessage({
93
- payerKey: this.provider.wallet.publicKey,
94
- recentBlockhash: blockhash,
95
- instructions
96
- }).compileToV0Message();
97
- const hash = yield this.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(message));
98
- const { blockhash: blockhash2, lastValidBlockHeight } = yield this.provider.connection.getLatestBlockhash();
99
- const confirmTx = yield this.provider.connection.confirmTransaction({
100
- signature: hash,
101
- blockhash: blockhash2,
102
- lastValidBlockHeight
103
- }, 'finalized');
104
- if (confirmTx.value.err) {
105
- throw new Error('Failed to open position');
106
- }
107
- return hash;
108
- }
109
- catch (error) {
110
- console.error(error);
111
- }
112
- });
113
- }
114
- /**
115
- * Withdraw from a vault
116
- * @param tickerPDA - Ticker PDA
117
- * @param amount - The amount to deposit
118
- * @param position - Long or Short
119
- * @param mint - Token mint for the vault (e.g. USDC)
120
- * @param positionPubkey - The position public key
121
- *
122
- */
123
- closePosition({ tickerPDA, mint, positionIndex }, options) {
124
- return __awaiter(this, void 0, void 0, function* () {
125
- try {
126
- const UserPositionPDA = (0, helpers_1.getUserPositionAddressSync)(this.program.programId, this.provider.wallet.publicKey, tickerPDA);
127
- const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, tickerPDA);
128
- const VaultTokenAccountPDA = (0, helpers_1.getTokenVaultAddressSync)(this.program.programId, VaultPDA);
129
- const userTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(mint, this.provider.wallet.publicKey);
130
- let hasUser = false;
131
- try {
132
- yield this.program.account.userPosition.fetch(UserPositionPDA);
133
- hasUser = true;
134
- }
135
- catch (e) {
136
- console.log(e);
137
- }
138
- const instructions = [];
139
- if (options === null || options === void 0 ? void 0 : options.priorityFee) {
140
- instructions.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
141
- microLamports: options.priorityFee
142
- }));
143
- }
144
- if (!hasUser) {
145
- instructions.push(yield this.program.methods
146
- .createUserPosition()
147
- .accounts({
148
- signer: this.provider.wallet.publicKey,
149
- ticker: tickerPDA
150
- })
151
- .instruction());
152
- }
153
- instructions.push(yield this.program.methods
154
- .closePosition({ positionIndex })
155
- .accounts({
156
- userPosition: UserPositionPDA,
157
- ticker: tickerPDA,
158
- vault: VaultPDA,
159
- vaultTokenAccount: VaultTokenAccountPDA,
160
- userTokenAccount
161
- })
162
- .instruction());
163
- const { blockhash } = yield this.provider.connection.getLatestBlockhash();
164
- const message = new web3_js_1.TransactionMessage({
165
- payerKey: this.provider.wallet.publicKey,
166
- recentBlockhash: blockhash,
167
- instructions
168
- }).compileToV0Message();
169
- const hash = yield this.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(message));
170
- const { blockhash: blockhash2, lastValidBlockHeight } = yield this.provider.connection.getLatestBlockhash();
171
- const confirmTx = yield this.provider.connection.confirmTransaction({
172
- signature: hash,
173
- blockhash: blockhash2,
174
- lastValidBlockHeight
175
- }, 'finalized');
176
- if (confirmTx.value.err) {
177
- throw new Error('Failed to open position');
178
- }
179
- return hash;
180
- }
181
- catch (error) {
182
- console.error(error);
183
- }
184
- });
185
- }
186
43
  }
187
44
  exports.default = Vault;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "0.5.0-beta",
3
+ "version": "0.5.2-beta.devnet",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",