@triadxyz/triad-protocol 0.1.0-alpha.7 → 0.1.0-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/vault.d.ts CHANGED
@@ -15,8 +15,8 @@ export default class Vault {
15
15
  name: string;
16
16
  tokenAccount: PublicKey;
17
17
  tickerAddress: PublicKey;
18
- totalDeposits: BN;
19
- totalWithdraws: BN;
18
+ totalDeposited: BN;
19
+ totalWithdrawn: BN;
20
20
  initTs: BN;
21
21
  netDeposits: BN;
22
22
  netWithdraws: BN;
@@ -24,7 +24,6 @@ export default class Vault {
24
24
  shortBalance: BN;
25
25
  longPositionsOpened: BN;
26
26
  shortPositionsOpened: BN;
27
- ticker: PublicKey;
28
27
  }>[]>;
29
28
  /**
30
29
  * Get vault by ticker Address
@@ -36,8 +35,8 @@ export default class Vault {
36
35
  name: string;
37
36
  tokenAccount: PublicKey;
38
37
  tickerAddress: PublicKey;
39
- totalDeposits: BN;
40
- totalWithdraws: BN;
38
+ totalDeposited: BN;
39
+ totalWithdrawn: BN;
41
40
  initTs: BN;
42
41
  netDeposits: BN;
43
42
  netWithdraws: BN;
@@ -45,7 +44,6 @@ export default class Vault {
45
44
  shortBalance: BN;
46
45
  longPositionsOpened: BN;
47
46
  shortPositionsOpened: BN;
48
- ticker: PublicKey;
49
47
  }>;
50
48
  /**
51
49
  * Open Position
@@ -59,6 +57,8 @@ export default class Vault {
59
57
  amount: string;
60
58
  position: 'Long' | 'Short';
61
59
  mint: PublicKey;
60
+ }, options?: {
61
+ priorityFee: number;
62
62
  }): Promise<string>;
63
63
  /**
64
64
  * Withdraw from a vault
@@ -69,11 +69,11 @@ export default class Vault {
69
69
  * @param positionPubkey - The position public key
70
70
  *
71
71
  */
72
- closePosition({ tickerPDA, amount, position, mint, positionPubkey }: {
72
+ closePosition({ tickerPDA, mint, positionIndex }: {
73
73
  tickerPDA: PublicKey;
74
- amount: string;
75
- position: 'Long' | 'Short';
76
74
  mint: PublicKey;
77
- positionPubkey: PublicKey;
75
+ positionIndex: number;
76
+ }, options?: {
77
+ priorityFee: number;
78
78
  }): Promise<string>;
79
79
  }
package/dist/vault.js CHANGED
@@ -49,30 +49,30 @@ class Vault {
49
49
  * @param position - Long or Short
50
50
  * @param mint - Token mint for the vault (e.g. USDC)
51
51
  */
52
- openPosition({ tickerPDA, amount, position, mint }) {
52
+ openPosition({ tickerPDA, amount, position, mint }, options) {
53
53
  return __awaiter(this, void 0, void 0, function* () {
54
54
  try {
55
- const UserPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, this.provider.wallet.publicKey);
55
+ const UserPositionPDA = (0, helpers_1.getUserPositionAddressSync)(this.program.programId, this.provider.wallet.publicKey, tickerPDA);
56
56
  const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, tickerPDA);
57
- const VaultTokenAccountPDA = (0, helpers_1.getTokenVaultAddressSync)(this.program.programId, VaultPDA);
58
57
  const userTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(mint, this.provider.wallet.publicKey);
59
- let hasUser = false;
58
+ let hasUserPosition = false;
60
59
  try {
61
- yield this.program.account.user.fetch(UserPDA);
62
- hasUser = true;
60
+ yield this.program.account.userPosition.fetch(UserPositionPDA);
61
+ hasUserPosition = true;
63
62
  }
64
63
  catch (_a) { }
65
64
  const instructions = [];
66
- if (!hasUser) {
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) {
67
71
  instructions.push(yield this.program.methods
68
- .createUser({
69
- name: `User ${Math.floor(Math.random() * 100)}`,
70
- referrer: '',
71
- community: ''
72
- })
72
+ .createUserPosition()
73
73
  .accounts({
74
74
  signer: this.provider.wallet.publicKey,
75
- user: UserPDA
75
+ ticker: tickerPDA
76
76
  })
77
77
  .instruction());
78
78
  }
@@ -82,10 +82,9 @@ class Vault {
82
82
  isLong: position === 'Long'
83
83
  })
84
84
  .accounts({
85
- user: UserPDA,
85
+ userPosition: UserPositionPDA,
86
86
  ticker: tickerPDA,
87
87
  vault: VaultPDA,
88
- vaultTokenAccount: VaultTokenAccountPDA,
89
88
  userTokenAccount
90
89
  })
91
90
  .instruction());
@@ -95,7 +94,17 @@ class Vault {
95
94
  recentBlockhash: blockhash,
96
95
  instructions
97
96
  }).compileToV0Message();
98
- return this.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(message));
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;
99
108
  }
100
109
  catch (error) {
101
110
  console.error(error);
@@ -111,45 +120,41 @@ class Vault {
111
120
  * @param positionPubkey - The position public key
112
121
  *
113
122
  */
114
- closePosition({ tickerPDA, amount, position, mint, positionPubkey }) {
123
+ closePosition({ tickerPDA, mint, positionIndex }, options) {
115
124
  return __awaiter(this, void 0, void 0, function* () {
116
125
  try {
117
- const UserPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, this.provider.wallet.publicKey);
126
+ const UserPositionPDA = (0, helpers_1.getUserPositionAddressSync)(this.program.programId, this.provider.wallet.publicKey, tickerPDA);
118
127
  const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, tickerPDA);
119
128
  const VaultTokenAccountPDA = (0, helpers_1.getTokenVaultAddressSync)(this.program.programId, VaultPDA);
120
129
  const userTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(mint, this.provider.wallet.publicKey);
121
130
  let hasUser = false;
122
131
  try {
123
- yield this.program.account.user.fetch(UserPDA);
124
- console.log('User exists');
132
+ yield this.program.account.userPosition.fetch(UserPositionPDA);
125
133
  hasUser = true;
126
134
  }
127
135
  catch (e) {
128
- console.log('User does not exist');
129
136
  console.log(e);
130
137
  }
131
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
+ }
132
144
  if (!hasUser) {
133
145
  instructions.push(yield this.program.methods
134
- .createUser({
135
- name: `User ${Math.floor(Math.random() * 100)}`,
136
- referrer: '',
137
- community: ''
138
- })
146
+ .createUserPosition()
139
147
  .accounts({
140
148
  signer: this.provider.wallet.publicKey,
141
- user: UserPDA
149
+ ticker: tickerPDA
142
150
  })
143
151
  .instruction());
144
152
  }
145
153
  instructions.push(yield this.program.methods
146
- .closePosition({
147
- amount: new anchor_1.BN(amount),
148
- isLong: position === 'Long',
149
- pubkey: positionPubkey
150
- })
154
+ .closePosition({ positionIndex })
151
155
  .accounts({
152
- user: UserPDA,
156
+ userPosition: UserPositionPDA,
157
+ ticker: tickerPDA,
153
158
  vault: VaultPDA,
154
159
  vaultTokenAccount: VaultTokenAccountPDA,
155
160
  userTokenAccount
@@ -161,7 +166,17 @@ class Vault {
161
166
  recentBlockhash: blockhash,
162
167
  instructions
163
168
  }).compileToV0Message();
164
- return this.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(message));
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;
165
180
  }
166
181
  catch (error) {
167
182
  console.error(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "0.1.0-alpha.7",
3
+ "version": "0.1.0-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -8,7 +8,8 @@
8
8
  "clean": "rimraf dist",
9
9
  "build": "yarn run clean && tsc",
10
10
  "prepublishOnly": "yarn build",
11
- "start": "yarn build && node ./dist/index.js"
11
+ "start": "yarn build && node ./dist/test.js",
12
+ "test": "rimraf dist && tsc && node ./dist/test.js"
12
13
  },
13
14
  "publishConfig": {
14
15
  "access": "public"
@@ -24,18 +25,18 @@
24
25
  "blockchain",
25
26
  "protocol",
26
27
  "triad",
27
- "trading protocols"
28
+ "trading protocols",
29
+ "dex",
30
+ "SPL 404"
28
31
  ],
29
32
  "author": "Triad Labs",
30
33
  "license": "ISC",
31
34
  "dependencies": {
32
- "@coral-xyz/anchor": "0.28.0",
33
- "@firethreexyz/firethree-protocol": "^0.19.1",
34
- "@pythnetwork/client": "^2.19.0",
35
- "@shadow-drive/sdk": "5.0.0",
36
- "@solana/spl-token": "^0.3.11",
35
+ "@coral-xyz/anchor": "0.30.0",
36
+ "@solana/spl-token": "0.4.6",
37
37
  "@solana/web3.js": "1.89.1",
38
38
  "axios": "^1.5.1",
39
+ "bn.js": "^5.2.1",
39
40
  "bs58": "5.0.0",
40
41
  "uuid": "^9.0.1"
41
42
  },