@triadxyz/triad-protocol 0.1.0-alpha.5 → 0.1.0-alpha.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/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /// <reference types="bn.js" />
2
- /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
3
2
  import { Address, AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
4
- import { Connection } from '@solana/web3.js';
3
+ import { Connection, PublicKey } from '@solana/web3.js';
5
4
  import { TriadProtocol } from './types/triad_protocol';
6
5
  import Ticker from './ticker';
7
6
  import Vault from './vault';
@@ -18,7 +17,7 @@ export default class TriadProtocolClient {
18
17
  ts: import("bn.js");
19
18
  name: string;
20
19
  bump: number;
21
- authority: import("@solana/web3.js").PublicKey;
20
+ authority: PublicKey;
22
21
  referrer: string;
23
22
  community: string;
24
23
  netDeposits: import("bn.js");
@@ -48,7 +47,7 @@ export default class TriadProtocolClient {
48
47
  ts: import("bn.js");
49
48
  name: string;
50
49
  bump: number;
51
- authority: import("@solana/web3.js").PublicKey;
50
+ authority: PublicKey;
52
51
  referrer: string;
53
52
  community: string;
54
53
  netDeposits: import("bn.js");
package/dist/ticker.js CHANGED
@@ -32,7 +32,7 @@ class Ticker {
32
32
  */
33
33
  createTicker({ name, protocolProgramId, tokenMint }) {
34
34
  return __awaiter(this, void 0, void 0, function* () {
35
- const TickerPDA = (0, helpers_1.getTickerAddressSync)(this.program.programId, protocolProgramId);
35
+ const TickerPDA = (0, helpers_1.getTickerAddressSync)(this.program.programId, name);
36
36
  const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, TickerPDA);
37
37
  const TokenAccountPDA = (0, helpers_1.getTokenVaultAddressSync)(this.program.programId, VaultPDA);
38
38
  return this.program.methods
@@ -1,6 +1,6 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
2
  import BN from 'bn.js';
3
- export declare const getTickerAddressSync: (programId: PublicKey, protocolProgramId: PublicKey) => PublicKey;
3
+ export declare const getTickerAddressSync: (programId: PublicKey, tickerName: string) => PublicKey;
4
4
  export declare const encodeString: (value: string) => number[];
5
5
  export declare const decodeString: (bytes: number[]) => string;
6
6
  export declare const getVaultAddressSync: (programId: PublicKey, tickerAddress: PublicKey) => PublicKey;
@@ -26,8 +26,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.formatNumber = exports.getUserAddressSync = exports.getTokenVaultAddressSync = exports.getVaultAddressSync = exports.decodeString = exports.encodeString = exports.getTickerAddressSync = void 0;
27
27
  const web3_js_1 = require("@solana/web3.js");
28
28
  const anchor = __importStar(require("@coral-xyz/anchor"));
29
- const getTickerAddressSync = (programId, protocolProgramId) => {
30
- const [TickerPDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('ticker'), protocolProgramId.toBuffer()], programId);
29
+ const getTickerAddressSync = (programId, tickerName) => {
30
+ const [TickerPDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('ticker'), Buffer.from(tickerName)], programId);
31
31
  return TickerPDA;
32
32
  };
33
33
  exports.getTickerAddressSync = getTickerAddressSync;
package/dist/vault.js CHANGED
@@ -51,50 +51,55 @@ class Vault {
51
51
  */
52
52
  openPosition({ tickerPDA, amount, position, mint }) {
53
53
  return __awaiter(this, void 0, void 0, function* () {
54
- const UserPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, this.provider.wallet.publicKey);
55
- const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, tickerPDA);
56
- const VaultTokenAccountPDA = (0, helpers_1.getTokenVaultAddressSync)(this.program.programId, VaultPDA);
57
- const userTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(mint, this.provider.wallet.publicKey);
58
- let hasUser = false;
59
54
  try {
60
- this.program.account.user.fetch(this.provider.wallet.publicKey);
61
- hasUser = true;
62
- }
63
- catch (_a) { }
64
- const instructions = [];
65
- if (!hasUser) {
55
+ const UserPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, this.provider.wallet.publicKey);
56
+ const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, tickerPDA);
57
+ const VaultTokenAccountPDA = (0, helpers_1.getTokenVaultAddressSync)(this.program.programId, VaultPDA);
58
+ const userTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(mint, this.provider.wallet.publicKey);
59
+ let hasUser = false;
60
+ try {
61
+ yield this.program.account.user.fetch(this.provider.wallet.publicKey);
62
+ hasUser = true;
63
+ }
64
+ catch (_a) { }
65
+ const instructions = [];
66
+ if (!hasUser) {
67
+ instructions.push(yield this.program.methods
68
+ .createUser({
69
+ name: `User ${Math.floor(Math.random() * 100)}`,
70
+ referrer: '',
71
+ community: ''
72
+ })
73
+ .accounts({
74
+ signer: this.provider.wallet.publicKey,
75
+ user: UserPDA
76
+ })
77
+ .instruction());
78
+ }
66
79
  instructions.push(yield this.program.methods
67
- .createUser({
68
- name: `User ${Math.floor(Math.random() * 100)}`,
69
- referrer: '',
70
- community: ''
80
+ .openPosition({
81
+ amount: new anchor_1.BN(amount),
82
+ isLong: position === 'Long'
71
83
  })
72
84
  .accounts({
73
- signer: this.provider.wallet.publicKey,
74
- user: UserPDA
85
+ user: UserPDA,
86
+ ticker: tickerPDA,
87
+ vault: VaultPDA,
88
+ vaultTokenAccount: VaultTokenAccountPDA,
89
+ userTokenAccount
75
90
  })
76
91
  .instruction());
92
+ const { blockhash } = yield this.provider.connection.getLatestBlockhash();
93
+ const message = new web3_js_1.TransactionMessage({
94
+ payerKey: this.provider.wallet.publicKey,
95
+ recentBlockhash: blockhash,
96
+ instructions
97
+ }).compileToV0Message();
98
+ return this.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(message));
99
+ }
100
+ catch (error) {
101
+ console.error(error);
77
102
  }
78
- instructions.push(yield this.program.methods
79
- .openPosition({
80
- amount: new anchor_1.BN(amount),
81
- isLong: position === 'Long'
82
- })
83
- .accounts({
84
- user: UserPDA,
85
- ticker: tickerPDA,
86
- vault: VaultPDA,
87
- vaultTokenAccount: VaultTokenAccountPDA,
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
- return this.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(message));
98
103
  });
99
104
  }
100
105
  /**
@@ -108,50 +113,55 @@ class Vault {
108
113
  */
109
114
  closePosition({ tickerPDA, amount, position, mint, positionPubkey }) {
110
115
  return __awaiter(this, void 0, void 0, function* () {
111
- const UserPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, this.provider.wallet.publicKey);
112
- const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, tickerPDA);
113
- const VaultTokenAccountPDA = (0, helpers_1.getTokenVaultAddressSync)(this.program.programId, VaultPDA);
114
- const userTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(mint, this.provider.wallet.publicKey);
115
- let hasUser = false;
116
116
  try {
117
- this.program.account.user.fetch(this.provider.wallet.publicKey);
118
- hasUser = true;
119
- }
120
- catch (_a) { }
121
- const instructions = [];
122
- if (!hasUser) {
117
+ const UserPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, this.provider.wallet.publicKey);
118
+ const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, tickerPDA);
119
+ const VaultTokenAccountPDA = (0, helpers_1.getTokenVaultAddressSync)(this.program.programId, VaultPDA);
120
+ const userTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(mint, this.provider.wallet.publicKey);
121
+ let hasUser = false;
122
+ try {
123
+ yield this.program.account.user.fetch(this.provider.wallet.publicKey);
124
+ hasUser = true;
125
+ }
126
+ catch (_a) { }
127
+ const instructions = [];
128
+ if (!hasUser) {
129
+ instructions.push(yield this.program.methods
130
+ .createUser({
131
+ name: `User ${Math.floor(Math.random() * 100)}`,
132
+ referrer: '',
133
+ community: ''
134
+ })
135
+ .accounts({
136
+ signer: this.provider.wallet.publicKey,
137
+ user: UserPDA
138
+ })
139
+ .instruction());
140
+ }
123
141
  instructions.push(yield this.program.methods
124
- .createUser({
125
- name: `User ${Math.floor(Math.random() * 100)}`,
126
- referrer: '',
127
- community: ''
142
+ .closePosition({
143
+ amount: new anchor_1.BN(amount),
144
+ isLong: position === 'Long',
145
+ pubkey: positionPubkey
128
146
  })
129
147
  .accounts({
130
- signer: this.provider.wallet.publicKey,
131
- user: UserPDA
148
+ user: UserPDA,
149
+ vault: VaultPDA,
150
+ vaultTokenAccount: VaultTokenAccountPDA,
151
+ userTokenAccount
132
152
  })
133
153
  .instruction());
154
+ const { blockhash } = yield this.provider.connection.getLatestBlockhash();
155
+ const message = new web3_js_1.TransactionMessage({
156
+ payerKey: this.provider.wallet.publicKey,
157
+ recentBlockhash: blockhash,
158
+ instructions
159
+ }).compileToV0Message();
160
+ return this.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(message));
161
+ }
162
+ catch (error) {
163
+ console.error(error);
134
164
  }
135
- instructions.push(yield this.program.methods
136
- .closePosition({
137
- amount: new anchor_1.BN(amount),
138
- isLong: position === 'Long',
139
- pubkey: positionPubkey
140
- })
141
- .accounts({
142
- user: UserPDA,
143
- vault: VaultPDA,
144
- vaultTokenAccount: VaultTokenAccountPDA,
145
- userTokenAccount
146
- })
147
- .instruction());
148
- const { blockhash } = yield this.provider.connection.getLatestBlockhash();
149
- const message = new web3_js_1.TransactionMessage({
150
- payerKey: this.provider.wallet.publicKey,
151
- recentBlockhash: blockhash,
152
- instructions
153
- }).compileToV0Message();
154
- return this.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(message));
155
165
  });
156
166
  }
157
167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "0.1.0-alpha.5",
3
+ "version": "0.1.0-alpha.6",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",