@triadxyz/triad-protocol 0.5.3-beta.devnet → 0.5.5-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.
- package/dist/index.d.ts +7 -9
- package/dist/index.js +58 -40
- package/dist/{test.js → local-test.js} +47 -9
- package/dist/stake.d.ts +19 -18
- package/dist/stake.js +59 -96
- package/dist/trade.d.ts +32 -0
- package/dist/trade.js +138 -0
- package/dist/types/idl_triad_protocol.json +385 -295
- package/dist/types/index.d.ts +1 -14
- package/dist/types/stake.d.ts +3 -7
- package/dist/types/trade.d.ts +44 -0
- package/dist/types/trade.js +2 -0
- package/dist/types/triad_protocol.d.ts +961 -399
- package/dist/utils/constants.d.ts +6 -3
- package/dist/utils/constants.js +7 -4
- package/dist/utils/helpers.d.ts +3 -4
- package/dist/utils/helpers.js +16 -51
- package/package.json +2 -3
- package/dist/ticker.d.ts +0 -33
- package/dist/ticker.js +0 -43
- package/dist/vault.d.ts +0 -48
- package/dist/vault.js +0 -44
- /package/dist/{test.d.ts → local-test.d.ts} +0 -0
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
2
|
export declare const STAKE_VAULT_NAME = "Triad Share 1";
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
3
|
+
export declare const TRD_DECIMALS = 6;
|
|
4
|
+
export declare const VERIFIER: PublicKey;
|
|
5
|
+
export declare const TRD_MINT: PublicKey;
|
|
6
|
+
export declare const TRIAD_ADMIN: PublicKey;
|
|
7
|
+
export declare const TRD_MINT_DEVNET: PublicKey;
|
package/dist/utils/constants.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.TRD_MINT_DEVNET = exports.TRIAD_ADMIN = exports.TRD_MINT = exports.VERIFIER = exports.TRD_DECIMALS = exports.STAKE_VAULT_NAME = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
exports.STAKE_VAULT_NAME = 'Triad Share 1';
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
6
|
+
exports.TRD_DECIMALS = 6;
|
|
7
|
+
exports.VERIFIER = new web3_js_1.PublicKey('42n6BHufivUKrb5Bi6tXbMZvM8NHovrDLX1Rt5w2a919');
|
|
8
|
+
exports.TRD_MINT = new web3_js_1.PublicKey('t3DohmswhKk94PPbPYwA6ZKACyY3y5kbcqeQerAJjmV');
|
|
9
|
+
exports.TRIAD_ADMIN = new web3_js_1.PublicKey('82ppCojm3yrEKgdpH8B5AmBJTU1r1uAWXFWhxvPs9UCR');
|
|
10
|
+
exports.TRD_MINT_DEVNET = new web3_js_1.PublicKey('9ti9L1a4ynpTj4gbGQLkYmZh7495nvLEgWtw5mtUkGQj');
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -2,11 +2,10 @@ import { COLLECTION_MUlTIPLIER, StakeResponse, StakeVaultResponse, UserResponse
|
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import BN from 'bn.js';
|
|
4
4
|
export declare const getTickerAddressSync: (programId: PublicKey, tickerName: string) => PublicKey;
|
|
5
|
-
export declare const encodeString: (value: string) => number[];
|
|
5
|
+
export declare const encodeString: (value: string, alloc?: number) => number[];
|
|
6
6
|
export declare const decodeString: (bytes: number[]) => string;
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare function getUserPositionAddressSync(programId: PublicKey, authority: PublicKey, ticker: PublicKey): PublicKey;
|
|
7
|
+
export declare const getMarketAddressSync: (programId: PublicKey, marketId: number) => PublicKey;
|
|
8
|
+
export declare const getFeeVaultAddressSync: (programId: PublicKey, market: PublicKey) => PublicKey;
|
|
10
9
|
export declare const getStakeVaultAddressSync: (programId: PublicKey, vaultName: string) => PublicKey;
|
|
11
10
|
export declare const getStakeAddressSync: (programId: PublicKey, wallet: PublicKey, name: string) => PublicKey;
|
|
12
11
|
export declare const getNFTRewardsAddressSync: (programId: PublicKey, stake: PublicKey) => PublicKey;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -1,40 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.calculateAPR = exports.calculateTotalMultiplier = exports.formatUser = exports.formatStake = exports.formatStakeVault = exports.formatNumber = exports.getUserAddressSync = exports.getATASync = exports.getNFTRewardsAddressSync = exports.getStakeAddressSync = exports.getStakeVaultAddressSync = exports.
|
|
6
|
+
exports.calculateAPR = exports.calculateTotalMultiplier = exports.formatUser = exports.formatStake = exports.formatStakeVault = exports.formatNumber = exports.getUserAddressSync = exports.getATASync = exports.getNFTRewardsAddressSync = exports.getStakeAddressSync = exports.getStakeVaultAddressSync = exports.getFeeVaultAddressSync = exports.getMarketAddressSync = exports.decodeString = exports.encodeString = exports.getTickerAddressSync = void 0;
|
|
27
7
|
const stake_1 = require("./../types/stake");
|
|
28
8
|
const web3_js_1 = require("@solana/web3.js");
|
|
29
|
-
const
|
|
9
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
30
10
|
const spl_token_1 = require("@solana/spl-token");
|
|
31
11
|
const getTickerAddressSync = (programId, tickerName) => {
|
|
32
12
|
const [TickerPDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('ticker'), Buffer.from(tickerName)], programId);
|
|
33
13
|
return TickerPDA;
|
|
34
14
|
};
|
|
35
15
|
exports.getTickerAddressSync = getTickerAddressSync;
|
|
36
|
-
const encodeString = (value) => {
|
|
37
|
-
const buffer = Buffer.alloc(
|
|
16
|
+
const encodeString = (value, alloc = 32) => {
|
|
17
|
+
const buffer = Buffer.alloc(alloc);
|
|
38
18
|
buffer.fill(value);
|
|
39
19
|
buffer.fill(' ', value.length);
|
|
40
20
|
return Array(...buffer);
|
|
@@ -45,31 +25,16 @@ const decodeString = (bytes) => {
|
|
|
45
25
|
return buffer.toString('utf8').trim();
|
|
46
26
|
};
|
|
47
27
|
exports.decodeString = decodeString;
|
|
48
|
-
const
|
|
49
|
-
const [
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('vault_token_account')),
|
|
59
|
-
vault.toBuffer()
|
|
60
|
-
], programId);
|
|
61
|
-
return VaultTokenPDA;
|
|
62
|
-
};
|
|
63
|
-
exports.getTokenVaultAddressSync = getTokenVaultAddressSync;
|
|
64
|
-
function getUserPositionAddressSync(programId, authority, ticker) {
|
|
65
|
-
const [UserPositionPDA] = web3_js_1.PublicKey.findProgramAddressSync([
|
|
66
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('user_position')),
|
|
67
|
-
authority.toBuffer(),
|
|
68
|
-
ticker.toBuffer()
|
|
69
|
-
], programId);
|
|
70
|
-
return UserPositionPDA;
|
|
71
|
-
}
|
|
72
|
-
exports.getUserPositionAddressSync = getUserPositionAddressSync;
|
|
28
|
+
const getMarketAddressSync = (programId, marketId) => {
|
|
29
|
+
const [MarketPDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('market'), new bn_js_1.default(marketId).toArrayLike(Buffer, 'le', 8)], programId);
|
|
30
|
+
return MarketPDA;
|
|
31
|
+
};
|
|
32
|
+
exports.getMarketAddressSync = getMarketAddressSync;
|
|
33
|
+
const getFeeVaultAddressSync = (programId, market) => {
|
|
34
|
+
const [FeeVaultPDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('fee_vault'), market.toBuffer()], programId);
|
|
35
|
+
return FeeVaultPDA;
|
|
36
|
+
};
|
|
37
|
+
exports.getFeeVaultAddressSync = getFeeVaultAddressSync;
|
|
73
38
|
const getStakeVaultAddressSync = (programId, vaultName) => {
|
|
74
39
|
const [StakeVaultPDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('stake_vault'), Buffer.from(vaultName)], programId);
|
|
75
40
|
return StakeVaultPDA;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@triadxyz/triad-protocol",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5-beta.devnet",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
"clean": "rimraf dist",
|
|
9
9
|
"build": "yarn run clean && tsc",
|
|
10
10
|
"prepublishOnly": "yarn build",
|
|
11
|
-
"
|
|
12
|
-
"test": "rimraf dist && tsc && node ./dist/test.js"
|
|
11
|
+
"test": "rimraf dist && tsc && node ./dist/local-test.js"
|
|
13
12
|
},
|
|
14
13
|
"publishConfig": {
|
|
15
14
|
"access": "public"
|
package/dist/ticker.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
|
-
import { AnchorProvider, Program } from '@coral-xyz/anchor';
|
|
3
|
-
import { PublicKey } from '@solana/web3.js';
|
|
4
|
-
import { TriadProtocol } from './types/triad_protocol';
|
|
5
|
-
export default class Ticker {
|
|
6
|
-
program: Program<TriadProtocol>;
|
|
7
|
-
provider: AnchorProvider;
|
|
8
|
-
constructor(program: Program<TriadProtocol>, provider: AnchorProvider);
|
|
9
|
-
/**
|
|
10
|
-
* Get all tickers
|
|
11
|
-
*/
|
|
12
|
-
getTickers(): Promise<import("@coral-xyz/anchor").ProgramAccount<{
|
|
13
|
-
initTs: import("bn.js");
|
|
14
|
-
updatedTs: import("bn.js");
|
|
15
|
-
bump: number;
|
|
16
|
-
authority: PublicKey;
|
|
17
|
-
name: string;
|
|
18
|
-
protocolProgramId: PublicKey;
|
|
19
|
-
price: import("bn.js");
|
|
20
|
-
vault: PublicKey;
|
|
21
|
-
}>[]>;
|
|
22
|
-
/**
|
|
23
|
-
* Create a new ticker
|
|
24
|
-
* @param name - The ticker's name
|
|
25
|
-
* @param token mint - Token mint for the ticker (e.g. USDC)
|
|
26
|
-
*
|
|
27
|
-
*/
|
|
28
|
-
createTicker({ name, tokenMint }: {
|
|
29
|
-
name: string;
|
|
30
|
-
protocolProgramId: PublicKey;
|
|
31
|
-
tokenMint: PublicKey;
|
|
32
|
-
}): Promise<string>;
|
|
33
|
-
}
|
package/dist/ticker.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
class Ticker {
|
|
13
|
-
constructor(program, provider) {
|
|
14
|
-
this.provider = provider;
|
|
15
|
-
this.program = program;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Get all tickers
|
|
19
|
-
*/
|
|
20
|
-
getTickers() {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
return this.program.account.ticker.all();
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Create a new ticker
|
|
27
|
-
* @param name - The ticker's name
|
|
28
|
-
* @param token mint - Token mint for the ticker (e.g. USDC)
|
|
29
|
-
*
|
|
30
|
-
*/
|
|
31
|
-
createTicker({ name, tokenMint }) {
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
return this.program.methods
|
|
34
|
-
.createTicker({ name })
|
|
35
|
-
.accounts({
|
|
36
|
-
signer: this.provider.wallet.publicKey,
|
|
37
|
-
payerTokenMint: tokenMint
|
|
38
|
-
})
|
|
39
|
-
.rpc();
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.default = Ticker;
|
package/dist/vault.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
|
-
import { AnchorProvider, BN, Program } from '@coral-xyz/anchor';
|
|
3
|
-
import { PublicKey } from '@solana/web3.js';
|
|
4
|
-
import { TriadProtocol } from './types/triad_protocol';
|
|
5
|
-
export default class Vault {
|
|
6
|
-
program: Program<TriadProtocol>;
|
|
7
|
-
provider: AnchorProvider;
|
|
8
|
-
constructor(program: Program<TriadProtocol>, provider: AnchorProvider);
|
|
9
|
-
/**
|
|
10
|
-
* Get all vaults
|
|
11
|
-
*/
|
|
12
|
-
getVaults(): Promise<import("@coral-xyz/anchor").ProgramAccount<{
|
|
13
|
-
bump: number;
|
|
14
|
-
authority: PublicKey;
|
|
15
|
-
name: string;
|
|
16
|
-
tokenAccount: PublicKey;
|
|
17
|
-
tickerAddress: PublicKey;
|
|
18
|
-
totalDeposited: BN;
|
|
19
|
-
totalWithdrawn: BN;
|
|
20
|
-
initTs: BN;
|
|
21
|
-
netDeposits: BN;
|
|
22
|
-
netWithdraws: BN;
|
|
23
|
-
longBalance: BN;
|
|
24
|
-
shortBalance: BN;
|
|
25
|
-
longPositionsOpened: BN;
|
|
26
|
-
shortPositionsOpened: BN;
|
|
27
|
-
}>[]>;
|
|
28
|
-
/**
|
|
29
|
-
* Get vault by ticker Address
|
|
30
|
-
*/
|
|
31
|
-
getVaultByTickerAddress(tickerAddress: PublicKey): Promise<{
|
|
32
|
-
tvl: number;
|
|
33
|
-
bump: number;
|
|
34
|
-
authority: PublicKey;
|
|
35
|
-
name: string;
|
|
36
|
-
tokenAccount: PublicKey;
|
|
37
|
-
tickerAddress: PublicKey;
|
|
38
|
-
totalDeposited: BN;
|
|
39
|
-
totalWithdrawn: BN;
|
|
40
|
-
initTs: BN;
|
|
41
|
-
netDeposits: BN;
|
|
42
|
-
netWithdraws: BN;
|
|
43
|
-
longBalance: BN;
|
|
44
|
-
shortBalance: BN;
|
|
45
|
-
longPositionsOpened: BN;
|
|
46
|
-
shortPositionsOpened: BN;
|
|
47
|
-
}>;
|
|
48
|
-
}
|
package/dist/vault.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const helpers_1 = require("./utils/helpers");
|
|
13
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
14
|
-
class Vault {
|
|
15
|
-
constructor(program, provider) {
|
|
16
|
-
this.provider = provider;
|
|
17
|
-
this.program = program;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Get all vaults
|
|
21
|
-
*/
|
|
22
|
-
getVaults() {
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
return this.program.account.vault.all();
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Get vault by ticker Address
|
|
29
|
-
*/
|
|
30
|
-
getVaultByTickerAddress(tickerAddress) {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, tickerAddress);
|
|
33
|
-
try {
|
|
34
|
-
const vault = yield this.program.account.vault.fetch(VaultPDA);
|
|
35
|
-
const tokenAcc = yield (0, spl_token_1.getAccount)(this.provider.connection, vault.tokenAccount);
|
|
36
|
-
return Object.assign(Object.assign({}, vault), { tvl: (0, helpers_1.formatNumber)(tokenAcc.amount) });
|
|
37
|
-
}
|
|
38
|
-
catch (e) {
|
|
39
|
-
throw new Error(e);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.default = Vault;
|
|
File without changes
|