torchsdk 1.0.0
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/LICENSE +21 -0
- package/dist/constants.d.ts +49 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +126 -0
- package/dist/constants.js.map +1 -0
- package/dist/gateway.d.ts +17 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +40 -0
- package/dist/gateway.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/program.d.ts +182 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +208 -0
- package/dist/program.js.map +1 -0
- package/dist/quotes.d.ts +16 -0
- package/dist/quotes.d.ts.map +1 -0
- package/dist/quotes.js +78 -0
- package/dist/quotes.js.map +1 -0
- package/dist/said.d.ts +27 -0
- package/dist/said.d.ts.map +1 -0
- package/dist/said.js +89 -0
- package/dist/said.js.map +1 -0
- package/dist/tokens.d.ts +44 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +537 -0
- package/dist/tokens.js.map +1 -0
- package/dist/torch_market.json +3172 -0
- package/dist/transactions.d.ts +93 -0
- package/dist/transactions.d.ts.map +1 -0
- package/dist/transactions.js +550 -0
- package/dist/transactions.js.map +1 -0
- package/dist/types.d.ts +194 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +34 -0
- package/readme.md +142 -0
package/dist/program.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getRaydiumMigrationAccounts = exports.getRaydiumObservationPda = exports.getRaydiumVaultPda = exports.getRaydiumLpMintPda = exports.getRaydiumPoolStatePda = exports.getRaydiumAuthorityPda = exports.orderTokensForRaydium = exports.calculateBondingProgress = exports.calculatePrice = exports.calculateSolOut = exports.calculateTokensOut = exports.getProgram = exports.getCollateralVaultPda = exports.getLoanPositionPda = exports.getStarRecordPda = exports.getUserStatsPda = exports.getProtocolTreasuryPda = exports.getPlatformTreasuryPda = exports.getTokenTreasuryPda = exports.getVoteRecordPda = exports.getUserPositionPda = exports.getTreasuryTokenAccount = exports.getBondingCurvePda = exports.getGlobalConfigPda = exports.decodeString = exports.PROGRAM_ID = void 0;
|
|
7
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
8
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
9
|
+
const constants_1 = require("./constants");
|
|
10
|
+
Object.defineProperty(exports, "PROGRAM_ID", { enumerable: true, get: function () { return constants_1.PROGRAM_ID; } });
|
|
11
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
12
|
+
const torch_market_json_1 = __importDefault(require("./torch_market.json"));
|
|
13
|
+
// Helper to decode byte arrays to strings
|
|
14
|
+
const decodeString = (bytes) => {
|
|
15
|
+
return Buffer.from(bytes).toString('utf8').replace(/\0/g, '');
|
|
16
|
+
};
|
|
17
|
+
exports.decodeString = decodeString;
|
|
18
|
+
// PDA derivation helpers
|
|
19
|
+
const getGlobalConfigPda = () => {
|
|
20
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.GLOBAL_CONFIG_SEED)], constants_1.PROGRAM_ID);
|
|
21
|
+
};
|
|
22
|
+
exports.getGlobalConfigPda = getGlobalConfigPda;
|
|
23
|
+
const getBondingCurvePda = (mint) => {
|
|
24
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.BONDING_CURVE_SEED), mint.toBuffer()], constants_1.PROGRAM_ID);
|
|
25
|
+
};
|
|
26
|
+
exports.getBondingCurvePda = getBondingCurvePda;
|
|
27
|
+
// [V13] Treasury's token account (ATA) - holds vote vault tokens during bonding
|
|
28
|
+
const getTreasuryTokenAccount = (mint, treasury) => {
|
|
29
|
+
return (0, spl_token_1.getAssociatedTokenAddressSync)(mint, treasury, true, // allowOwnerOffCurve (PDA)
|
|
30
|
+
constants_1.TOKEN_2022_PROGRAM_ID);
|
|
31
|
+
};
|
|
32
|
+
exports.getTreasuryTokenAccount = getTreasuryTokenAccount;
|
|
33
|
+
const getUserPositionPda = (bondingCurve, user) => {
|
|
34
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.USER_POSITION_SEED), bondingCurve.toBuffer(), user.toBuffer()], constants_1.PROGRAM_ID);
|
|
35
|
+
};
|
|
36
|
+
exports.getUserPositionPda = getUserPositionPda;
|
|
37
|
+
const getVoteRecordPda = (bondingCurve, voter) => {
|
|
38
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.VOTE_SEED), bondingCurve.toBuffer(), voter.toBuffer()], constants_1.PROGRAM_ID);
|
|
39
|
+
};
|
|
40
|
+
exports.getVoteRecordPda = getVoteRecordPda;
|
|
41
|
+
const getTokenTreasuryPda = (mint) => {
|
|
42
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.TREASURY_SEED), mint.toBuffer()], constants_1.PROGRAM_ID);
|
|
43
|
+
};
|
|
44
|
+
exports.getTokenTreasuryPda = getTokenTreasuryPda;
|
|
45
|
+
// V4: Platform treasury PDA
|
|
46
|
+
const getPlatformTreasuryPda = () => {
|
|
47
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.PLATFORM_TREASURY_SEED)], constants_1.PROGRAM_ID);
|
|
48
|
+
};
|
|
49
|
+
exports.getPlatformTreasuryPda = getPlatformTreasuryPda;
|
|
50
|
+
// V11: Protocol treasury PDA
|
|
51
|
+
const getProtocolTreasuryPda = () => {
|
|
52
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.PROTOCOL_TREASURY_SEED)], constants_1.PROGRAM_ID);
|
|
53
|
+
};
|
|
54
|
+
exports.getProtocolTreasuryPda = getProtocolTreasuryPda;
|
|
55
|
+
// V4: User stats PDA
|
|
56
|
+
const getUserStatsPda = (user) => {
|
|
57
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.USER_STATS_SEED), user.toBuffer()], constants_1.PROGRAM_ID);
|
|
58
|
+
};
|
|
59
|
+
exports.getUserStatsPda = getUserStatsPda;
|
|
60
|
+
// V10: Star record PDA (per user-token, not user-creator)
|
|
61
|
+
const getStarRecordPda = (user, mint) => {
|
|
62
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.STAR_RECORD_SEED), user.toBuffer(), mint.toBuffer()], constants_1.PROGRAM_ID);
|
|
63
|
+
};
|
|
64
|
+
exports.getStarRecordPda = getStarRecordPda;
|
|
65
|
+
// V2.4: Loan position PDA (per user-token)
|
|
66
|
+
const getLoanPositionPda = (mint, borrower) => {
|
|
67
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.LOAN_SEED), mint.toBuffer(), borrower.toBuffer()], constants_1.PROGRAM_ID);
|
|
68
|
+
};
|
|
69
|
+
exports.getLoanPositionPda = getLoanPositionPda;
|
|
70
|
+
// V2.4: Collateral vault PDA (per token)
|
|
71
|
+
const getCollateralVaultPda = (mint) => {
|
|
72
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.COLLATERAL_VAULT_SEED), mint.toBuffer()], constants_1.PROGRAM_ID);
|
|
73
|
+
};
|
|
74
|
+
exports.getCollateralVaultPda = getCollateralVaultPda;
|
|
75
|
+
// Get program instance
|
|
76
|
+
const getProgram = (provider) => {
|
|
77
|
+
return new anchor_1.Program(torch_market_json_1.default, provider);
|
|
78
|
+
};
|
|
79
|
+
exports.getProgram = getProgram;
|
|
80
|
+
// Calculate tokens out for a given SOL amount (V2.3: dynamic treasury rate 20%→5%)
|
|
81
|
+
const calculateTokensOut = (solAmount, virtualSolReserves, virtualTokenReserves, realSolReserves = BigInt(0), // V2.3: needed for dynamic rate calculation
|
|
82
|
+
protocolFeeBps = 100, // 1% protocol fee (75% protocol treasury, 25% dev)
|
|
83
|
+
treasuryFeeBps = 100) => {
|
|
84
|
+
// Calculate protocol fee (1%)
|
|
85
|
+
const protocolFee = (solAmount * BigInt(protocolFeeBps)) / BigInt(10000);
|
|
86
|
+
// Calculate treasury fee (1%)
|
|
87
|
+
const treasuryFee = (solAmount * BigInt(treasuryFeeBps)) / BigInt(10000);
|
|
88
|
+
const solAfterFees = solAmount - protocolFee - treasuryFee;
|
|
89
|
+
// V2.3: Dynamic treasury rate - decays from 20% to 5% as bonding progresses
|
|
90
|
+
const TREASURY_MAX_BPS = 2000; // 20%
|
|
91
|
+
const TREASURY_MIN_BPS = 500; // 5%
|
|
92
|
+
const BONDING_TARGET = BigInt('200000000000'); // 200 SOL in lamports
|
|
93
|
+
const rateRange = BigInt(TREASURY_MAX_BPS - TREASURY_MIN_BPS);
|
|
94
|
+
const decay = (realSolReserves * rateRange) / BONDING_TARGET;
|
|
95
|
+
const treasuryRateBps = Math.max(TREASURY_MAX_BPS - Number(decay), TREASURY_MIN_BPS);
|
|
96
|
+
// Split remaining SOL using dynamic rate
|
|
97
|
+
const solToTreasurySplit = (solAfterFees * BigInt(treasuryRateBps)) / BigInt(10000);
|
|
98
|
+
const solToCurve = solAfterFees - solToTreasurySplit;
|
|
99
|
+
// Total to treasury = flat fee + dynamic split
|
|
100
|
+
const solToTreasury = treasuryFee + solToTreasurySplit;
|
|
101
|
+
// Calculate tokens using constant product formula (based on SOL going to curve)
|
|
102
|
+
const tokensOut = (virtualTokenReserves * solToCurve) / (virtualSolReserves + solToCurve);
|
|
103
|
+
// Split tokens: 90% to user, 10% to community treasury
|
|
104
|
+
// No permanent burn during bonding - community votes on treasury tokens at migration
|
|
105
|
+
const tokensToUser = (tokensOut * BigInt(9000)) / BigInt(10000);
|
|
106
|
+
const tokensToCommunity = tokensOut - tokensToUser;
|
|
107
|
+
return {
|
|
108
|
+
tokensOut,
|
|
109
|
+
tokensToUser,
|
|
110
|
+
tokensToCommunity,
|
|
111
|
+
protocolFee,
|
|
112
|
+
treasuryFee,
|
|
113
|
+
solToCurve,
|
|
114
|
+
solToTreasury,
|
|
115
|
+
treasuryRateBps,
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
exports.calculateTokensOut = calculateTokensOut;
|
|
119
|
+
// Calculate SOL out for a given token amount (no sell fee)
|
|
120
|
+
const calculateSolOut = (tokenAmount, virtualSolReserves, virtualTokenReserves) => {
|
|
121
|
+
// Calculate SOL using inverse formula
|
|
122
|
+
const solOut = (virtualSolReserves * tokenAmount) / (virtualTokenReserves + tokenAmount);
|
|
123
|
+
// No fees on sells - user gets full amount
|
|
124
|
+
return { solOut, solToUser: solOut };
|
|
125
|
+
};
|
|
126
|
+
exports.calculateSolOut = calculateSolOut;
|
|
127
|
+
// Calculate current token price in SOL
|
|
128
|
+
const calculatePrice = (virtualSolReserves, virtualTokenReserves) => {
|
|
129
|
+
// Price = virtualSol / virtualTokens
|
|
130
|
+
return Number(virtualSolReserves) / Number(virtualTokenReserves);
|
|
131
|
+
};
|
|
132
|
+
exports.calculatePrice = calculatePrice;
|
|
133
|
+
// Calculate bonding progress percentage
|
|
134
|
+
const calculateBondingProgress = (realSolReserves) => {
|
|
135
|
+
const target = BigInt('200000000000'); // 200 SOL in lamports
|
|
136
|
+
if (realSolReserves >= target)
|
|
137
|
+
return 100;
|
|
138
|
+
return (Number(realSolReserves) / Number(target)) * 100;
|
|
139
|
+
};
|
|
140
|
+
exports.calculateBondingProgress = calculateBondingProgress;
|
|
141
|
+
// ============================================================================
|
|
142
|
+
// RAYDIUM CPMM PDA DERIVATION (V5)
|
|
143
|
+
// ============================================================================
|
|
144
|
+
// Order tokens for Raydium (token_0 < token_1 by pubkey bytes)
|
|
145
|
+
const orderTokensForRaydium = (tokenA, tokenB) => {
|
|
146
|
+
const aBytes = tokenA.toBuffer();
|
|
147
|
+
const bBytes = tokenB.toBuffer();
|
|
148
|
+
for (let i = 0; i < 32; i++) {
|
|
149
|
+
if (aBytes[i] < bBytes[i]) {
|
|
150
|
+
return { token0: tokenA, token1: tokenB, isToken0First: true };
|
|
151
|
+
}
|
|
152
|
+
else if (aBytes[i] > bBytes[i]) {
|
|
153
|
+
return { token0: tokenB, token1: tokenA, isToken0First: false };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Equal - shouldn't happen
|
|
157
|
+
return { token0: tokenA, token1: tokenB, isToken0First: true };
|
|
158
|
+
};
|
|
159
|
+
exports.orderTokensForRaydium = orderTokensForRaydium;
|
|
160
|
+
// Raydium authority PDA
|
|
161
|
+
const getRaydiumAuthorityPda = () => {
|
|
162
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('vault_and_lp_mint_auth_seed')], constants_1.RAYDIUM_CPMM_PROGRAM);
|
|
163
|
+
};
|
|
164
|
+
exports.getRaydiumAuthorityPda = getRaydiumAuthorityPda;
|
|
165
|
+
// Raydium pool state PDA
|
|
166
|
+
const getRaydiumPoolStatePda = (ammConfig, token0Mint, token1Mint) => {
|
|
167
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('pool'), ammConfig.toBuffer(), token0Mint.toBuffer(), token1Mint.toBuffer()], constants_1.RAYDIUM_CPMM_PROGRAM);
|
|
168
|
+
};
|
|
169
|
+
exports.getRaydiumPoolStatePda = getRaydiumPoolStatePda;
|
|
170
|
+
// Raydium LP mint PDA
|
|
171
|
+
const getRaydiumLpMintPda = (poolState) => {
|
|
172
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('pool_lp_mint'), poolState.toBuffer()], constants_1.RAYDIUM_CPMM_PROGRAM);
|
|
173
|
+
};
|
|
174
|
+
exports.getRaydiumLpMintPda = getRaydiumLpMintPda;
|
|
175
|
+
// Raydium pool vault PDA
|
|
176
|
+
const getRaydiumVaultPda = (poolState, tokenMint) => {
|
|
177
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('pool_vault'), poolState.toBuffer(), tokenMint.toBuffer()], constants_1.RAYDIUM_CPMM_PROGRAM);
|
|
178
|
+
};
|
|
179
|
+
exports.getRaydiumVaultPda = getRaydiumVaultPda;
|
|
180
|
+
// Raydium observation state PDA
|
|
181
|
+
const getRaydiumObservationPda = (poolState) => {
|
|
182
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('observation'), poolState.toBuffer()], constants_1.RAYDIUM_CPMM_PROGRAM);
|
|
183
|
+
};
|
|
184
|
+
exports.getRaydiumObservationPda = getRaydiumObservationPda;
|
|
185
|
+
// Get all Raydium accounts needed for migration
|
|
186
|
+
const getRaydiumMigrationAccounts = (tokenMint) => {
|
|
187
|
+
const { token0, token1, isToken0First } = (0, exports.orderTokensForRaydium)(constants_1.WSOL_MINT, tokenMint);
|
|
188
|
+
const isWsolToken0 = isToken0First;
|
|
189
|
+
const [raydiumAuthority] = (0, exports.getRaydiumAuthorityPda)();
|
|
190
|
+
const [poolState] = (0, exports.getRaydiumPoolStatePda)(constants_1.RAYDIUM_AMM_CONFIG, token0, token1);
|
|
191
|
+
const [lpMint] = (0, exports.getRaydiumLpMintPda)(poolState);
|
|
192
|
+
const [token0Vault] = (0, exports.getRaydiumVaultPda)(poolState, token0);
|
|
193
|
+
const [token1Vault] = (0, exports.getRaydiumVaultPda)(poolState, token1);
|
|
194
|
+
const [observationState] = (0, exports.getRaydiumObservationPda)(poolState);
|
|
195
|
+
return {
|
|
196
|
+
token0,
|
|
197
|
+
token1,
|
|
198
|
+
isWsolToken0,
|
|
199
|
+
raydiumAuthority,
|
|
200
|
+
poolState,
|
|
201
|
+
lpMint,
|
|
202
|
+
token0Vault,
|
|
203
|
+
token1Vault,
|
|
204
|
+
observationState,
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
exports.getRaydiumMigrationAccounts = getRaydiumMigrationAccounts;
|
|
208
|
+
//# sourceMappingURL=program.js.map
|
|
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MAAM,YAAY,GAAG,aAAa,CAAA;IAElC,MAAM,CAAC,gBAAgB,CAAC,GAAG,IAAA,8BAAsB,GAAE,CAAA;IACnD,MAAM,CAAC,SAAS,CAAC,GAAG,IAAA,8BAAsB,EAAC,8BAAkB,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9E,MAAM,CAAC,MAAM,CAAC,GAAG,IAAA,2BAAmB,EAAC,SAAS,CAAC,CAAA;IAC/C,MAAM,CAAC,WAAW,CAAC,GAAG,IAAA,0BAAkB,EAAC,SAAS,EAAE,MAAM,CAAC,CAAA;IAC3D,MAAM,CAAC,WAAW,CAAC,GAAG,IAAA,0BAAkB,EAAC,SAAS,EAAE,MAAM,CAAC,CAAA;IAC3D,MAAM,CAAC,gBAAgB,CAAC,GAAG,IAAA,gCAAwB,EAAC,SAAS,CAAC,CAAA;IAE9D,OAAO;QACL,MAAM;QACN,MAAM;QACN,YAAY;QACZ,gBAAgB;QAChB,SAAS;QACT,MAAM;QACN,WAAW;QACX,WAAW;QACX,gBAAgB;KACjB,CAAA;AACH,CAAC,CAAA;AAlCY,QAAA,2BAA2B,+BAkCvC"}
|
package/dist/quotes.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quote calculations
|
|
3
|
+
*
|
|
4
|
+
* Get expected output for buy/sell operations.
|
|
5
|
+
*/
|
|
6
|
+
import { Connection } from '@solana/web3.js';
|
|
7
|
+
import { BuyQuoteResult, SellQuoteResult } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Get a buy quote: how many tokens for a given SOL amount.
|
|
10
|
+
*/
|
|
11
|
+
export declare const getBuyQuote: (connection: Connection, mintStr: string, amountSolLamports: number) => Promise<BuyQuoteResult>;
|
|
12
|
+
/**
|
|
13
|
+
* Get a sell quote: how much SOL for a given token amount.
|
|
14
|
+
*/
|
|
15
|
+
export declare const getSellQuote: (connection: Connection, mintStr: string, amountTokens: number) => Promise<SellQuoteResult>;
|
|
16
|
+
//# sourceMappingURL=quotes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quotes.d.ts","sourceRoot":"","sources":["../src/quotes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAa,MAAM,iBAAiB,CAAA;AAIvD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAEzD;;GAEG;AACH,eAAO,MAAM,WAAW,GACtB,YAAY,UAAU,EACtB,SAAS,MAAM,EACf,mBAAmB,MAAM,KACxB,OAAO,CAAC,cAAc,CAuCxB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,GACvB,YAAY,UAAU,EACtB,SAAS,MAAM,EACf,cAAc,MAAM,KACnB,OAAO,CAAC,eAAe,CAiCzB,CAAA"}
|
package/dist/quotes.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Quote calculations
|
|
4
|
+
*
|
|
5
|
+
* Get expected output for buy/sell operations.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.getSellQuote = exports.getBuyQuote = void 0;
|
|
9
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
10
|
+
const program_1 = require("./program");
|
|
11
|
+
const constants_1 = require("./constants");
|
|
12
|
+
const tokens_1 = require("./tokens");
|
|
13
|
+
/**
|
|
14
|
+
* Get a buy quote: how many tokens for a given SOL amount.
|
|
15
|
+
*/
|
|
16
|
+
const getBuyQuote = async (connection, mintStr, amountSolLamports) => {
|
|
17
|
+
const mint = new web3_js_1.PublicKey(mintStr);
|
|
18
|
+
const tokenData = await (0, tokens_1.fetchTokenRaw)(connection, mint);
|
|
19
|
+
if (!tokenData) {
|
|
20
|
+
throw new Error(`Token not found: ${mintStr}`);
|
|
21
|
+
}
|
|
22
|
+
const { bondingCurve } = tokenData;
|
|
23
|
+
if (bondingCurve.bonding_complete) {
|
|
24
|
+
throw new Error('Bonding curve complete, trade on DEX');
|
|
25
|
+
}
|
|
26
|
+
const virtualSol = BigInt(bondingCurve.virtual_sol_reserves.toString());
|
|
27
|
+
const virtualTokens = BigInt(bondingCurve.virtual_token_reserves.toString());
|
|
28
|
+
const realSol = BigInt(bondingCurve.real_sol_reserves.toString());
|
|
29
|
+
const amountSol = BigInt(amountSolLamports);
|
|
30
|
+
const result = (0, program_1.calculateTokensOut)(amountSol, virtualSol, virtualTokens, realSol);
|
|
31
|
+
const priceBefore = (0, program_1.calculatePrice)(virtualSol, virtualTokens);
|
|
32
|
+
const priceAfter = (0, program_1.calculatePrice)(virtualSol + result.solToCurve, virtualTokens - result.tokensOut);
|
|
33
|
+
const priceImpact = ((priceAfter - priceBefore) / priceBefore) * 100;
|
|
34
|
+
const minOutput = (result.tokensToUser * BigInt(99)) / BigInt(100);
|
|
35
|
+
return {
|
|
36
|
+
input_sol: Number(amountSol),
|
|
37
|
+
output_tokens: Number(result.tokensOut),
|
|
38
|
+
tokens_to_user: Number(result.tokensToUser),
|
|
39
|
+
tokens_to_treasury: Number(result.tokensToCommunity),
|
|
40
|
+
protocol_fee_sol: Number(result.protocolFee),
|
|
41
|
+
price_per_token_sol: (priceBefore * constants_1.TOKEN_MULTIPLIER) / constants_1.LAMPORTS_PER_SOL,
|
|
42
|
+
price_impact_percent: priceImpact,
|
|
43
|
+
min_output_tokens: Number(minOutput),
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
exports.getBuyQuote = getBuyQuote;
|
|
47
|
+
/**
|
|
48
|
+
* Get a sell quote: how much SOL for a given token amount.
|
|
49
|
+
*/
|
|
50
|
+
const getSellQuote = async (connection, mintStr, amountTokens) => {
|
|
51
|
+
const mint = new web3_js_1.PublicKey(mintStr);
|
|
52
|
+
const tokenData = await (0, tokens_1.fetchTokenRaw)(connection, mint);
|
|
53
|
+
if (!tokenData) {
|
|
54
|
+
throw new Error(`Token not found: ${mintStr}`);
|
|
55
|
+
}
|
|
56
|
+
const { bondingCurve } = tokenData;
|
|
57
|
+
if (bondingCurve.bonding_complete) {
|
|
58
|
+
throw new Error('Bonding curve complete, trade on DEX');
|
|
59
|
+
}
|
|
60
|
+
const virtualSol = BigInt(bondingCurve.virtual_sol_reserves.toString());
|
|
61
|
+
const virtualTokens = BigInt(bondingCurve.virtual_token_reserves.toString());
|
|
62
|
+
const tokenAmount = BigInt(amountTokens);
|
|
63
|
+
const result = (0, program_1.calculateSolOut)(tokenAmount, virtualSol, virtualTokens);
|
|
64
|
+
const priceBefore = (0, program_1.calculatePrice)(virtualSol, virtualTokens);
|
|
65
|
+
const priceAfter = (0, program_1.calculatePrice)(virtualSol - result.solOut, virtualTokens + tokenAmount);
|
|
66
|
+
const priceImpact = ((priceBefore - priceAfter) / priceBefore) * 100;
|
|
67
|
+
const minOutput = (result.solToUser * BigInt(99)) / BigInt(100);
|
|
68
|
+
return {
|
|
69
|
+
input_tokens: Number(tokenAmount),
|
|
70
|
+
output_sol: Number(result.solToUser),
|
|
71
|
+
protocol_fee_sol: 0,
|
|
72
|
+
price_per_token_sol: (priceBefore * constants_1.TOKEN_MULTIPLIER) / constants_1.LAMPORTS_PER_SOL,
|
|
73
|
+
price_impact_percent: priceImpact,
|
|
74
|
+
min_output_sol: Number(minOutput),
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
exports.getSellQuote = getSellQuote;
|
|
78
|
+
//# sourceMappingURL=quotes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quotes.js","sourceRoot":"","sources":["../src/quotes.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,6CAAuD;AACvD,uCAA+E;AAC/E,2CAAgE;AAChE,qCAAwC;AAGxC;;GAEG;AACI,MAAM,WAAW,GAAG,KAAK,EAC9B,UAAsB,EACtB,OAAe,EACf,iBAAyB,EACA,EAAE;IAC3B,MAAM,IAAI,GAAG,IAAI,mBAAS,CAAC,OAAO,CA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CAAC,CAAA;IAEtE,MAAM,WAAW,GAAG,IAAA,wBAAc,EAAC,UAAU,EAAE,aAAa,CAAC,CAAA;IAC7D,MAAM,UAAU,GAAG,IAAA,wBAAc,EAAC,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC,CAAA;IAC1F,MAAM,WAAW,GAAG,CAAC,CAAC,WAAW,GAAG,UAAU,CAAC,GAAG,WAAW,CAAC,GAAG,GAAG,CAAA;IACpE,MAAM,SAAS,GAAG,CAAC,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;IAE/D,OAAO;QACL,YAAY,EAAE,MAAM,CAAC,WAAW,CAAC;QACjC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;QACpC,gBAAgB,EAAE,CAAC;QACnB,mBAAmB,EAAE,CAAC,WAAW,GAAG,4BAAgB,CAAC,GAAG,4BAAgB;QACxE,oBAAoB,EAAE,WAAW;QACjC,cAAc,EAAE,MAAM,CAAC,SAAS,CAAC;KAClC,CAAA;AACH,CAAC,CAAA;AArCY,QAAA,YAAY,gBAqCxB"}
|
package/dist/said.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SAID Protocol integration
|
|
3
|
+
*
|
|
4
|
+
* Verify wallet reputation and confirm transactions for SAID feedback.
|
|
5
|
+
*/
|
|
6
|
+
import { Connection } from '@solana/web3.js';
|
|
7
|
+
import { SaidVerification, ConfirmResult } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Check SAID verification status for a wallet.
|
|
10
|
+
*
|
|
11
|
+
* @param wallet - Wallet address to verify
|
|
12
|
+
* @returns Verification status including trust tier
|
|
13
|
+
*/
|
|
14
|
+
export declare const verifySaid: (wallet: string) => Promise<SaidVerification>;
|
|
15
|
+
/**
|
|
16
|
+
* Confirm a transaction on-chain and determine event type.
|
|
17
|
+
*
|
|
18
|
+
* After an agent submits a transaction, call this to verify it succeeded
|
|
19
|
+
* and determine the event type for reputation tracking.
|
|
20
|
+
*
|
|
21
|
+
* @param connection - Solana RPC connection
|
|
22
|
+
* @param signature - Transaction signature to confirm
|
|
23
|
+
* @param wallet - Wallet address that signed the transaction
|
|
24
|
+
* @returns Confirmation result with event type
|
|
25
|
+
*/
|
|
26
|
+
export declare const confirmTransaction: (connection: Connection, signature: string, wallet: string) => Promise<ConfirmResult>;
|
|
27
|
+
//# sourceMappingURL=said.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"said.d.ts","sourceRoot":"","sources":["../src/said.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAa,MAAM,iBAAiB,CAAA;AAEvD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAQzD;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAU,QAAQ,MAAM,KAAG,OAAO,CAAC,gBAAgB,CAgBzE,CAAA;AAMD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,GAC7B,YAAY,UAAU,EACtB,WAAW,MAAM,EACjB,QAAQ,MAAM,KACb,OAAO,CAAC,aAAa,CAkDvB,CAAA"}
|
package/dist/said.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SAID Protocol integration
|
|
4
|
+
*
|
|
5
|
+
* Verify wallet reputation and confirm transactions for SAID feedback.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.confirmTransaction = exports.verifySaid = void 0;
|
|
9
|
+
const constants_1 = require("./constants");
|
|
10
|
+
const SAID_API_URL = 'https://api.saidprotocol.com/api';
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// Verify
|
|
13
|
+
// ============================================================================
|
|
14
|
+
/**
|
|
15
|
+
* Check SAID verification status for a wallet.
|
|
16
|
+
*
|
|
17
|
+
* @param wallet - Wallet address to verify
|
|
18
|
+
* @returns Verification status including trust tier
|
|
19
|
+
*/
|
|
20
|
+
const verifySaid = async (wallet) => {
|
|
21
|
+
try {
|
|
22
|
+
const res = await fetch(`${SAID_API_URL}/verify/${wallet}`);
|
|
23
|
+
const data = (await res.json());
|
|
24
|
+
return {
|
|
25
|
+
verified: data.verified ?? false,
|
|
26
|
+
trustTier: data.trustTier ?? null,
|
|
27
|
+
name: data.name,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return { verified: false, trustTier: null };
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.verifySaid = verifySaid;
|
|
35
|
+
// ============================================================================
|
|
36
|
+
// Confirm
|
|
37
|
+
// ============================================================================
|
|
38
|
+
/**
|
|
39
|
+
* Confirm a transaction on-chain and determine event type.
|
|
40
|
+
*
|
|
41
|
+
* After an agent submits a transaction, call this to verify it succeeded
|
|
42
|
+
* and determine the event type for reputation tracking.
|
|
43
|
+
*
|
|
44
|
+
* @param connection - Solana RPC connection
|
|
45
|
+
* @param signature - Transaction signature to confirm
|
|
46
|
+
* @param wallet - Wallet address that signed the transaction
|
|
47
|
+
* @returns Confirmation result with event type
|
|
48
|
+
*/
|
|
49
|
+
const confirmTransaction = async (connection, signature, wallet) => {
|
|
50
|
+
const tx = await connection.getParsedTransaction(signature, {
|
|
51
|
+
maxSupportedTransactionVersion: 0,
|
|
52
|
+
commitment: 'confirmed',
|
|
53
|
+
});
|
|
54
|
+
if (!tx)
|
|
55
|
+
throw new Error('Transaction not found or not confirmed');
|
|
56
|
+
if (tx.meta?.err)
|
|
57
|
+
throw new Error('Transaction failed on-chain');
|
|
58
|
+
// Verify wallet was a signer
|
|
59
|
+
const signers = tx.transaction.message.accountKeys
|
|
60
|
+
.filter((key) => key.signer)
|
|
61
|
+
.map((key) => key.pubkey.toString());
|
|
62
|
+
if (!signers.includes(wallet)) {
|
|
63
|
+
throw new Error('Wallet was not a signer on this transaction');
|
|
64
|
+
}
|
|
65
|
+
// Find Torch Market instructions
|
|
66
|
+
const torchInstructions = tx.transaction.message.instructions.filter((ix) => {
|
|
67
|
+
const programId = 'programId' in ix ? ix.programId.toString() : '';
|
|
68
|
+
return programId === constants_1.PROGRAM_ID.toString();
|
|
69
|
+
});
|
|
70
|
+
if (torchInstructions.length === 0) {
|
|
71
|
+
throw new Error('Transaction does not involve Torch Market');
|
|
72
|
+
}
|
|
73
|
+
// Determine event type from logs
|
|
74
|
+
const logs = tx.meta?.logMessages || [];
|
|
75
|
+
const isCreateToken = logs.some((log) => log.includes('Instruction: CreateToken') || log.includes('create_token'));
|
|
76
|
+
const isBuy = logs.some((log) => log.includes('Instruction: Buy') || log.includes('Program log: Buy'));
|
|
77
|
+
const isSell = logs.some((log) => log.includes('Instruction: Sell') || log.includes('Program log: Sell'));
|
|
78
|
+
const isVote = logs.some((log) => log.includes('Instruction: Vote') || log.includes('Program log: Vote'));
|
|
79
|
+
let event_type = 'unknown';
|
|
80
|
+
if (isCreateToken)
|
|
81
|
+
event_type = 'token_launch';
|
|
82
|
+
else if (isBuy || isSell)
|
|
83
|
+
event_type = 'trade_complete';
|
|
84
|
+
else if (isVote)
|
|
85
|
+
event_type = 'governance_vote';
|
|
86
|
+
return { confirmed: true, event_type };
|
|
87
|
+
};
|
|
88
|
+
exports.confirmTransaction = confirmTransaction;
|
|
89
|
+
//# sourceMappingURL=said.js.map
|
package/dist/said.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"said.js","sourceRoot":"","sources":["../src/said.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAGH,2CAAwC;AAGxC,MAAM,YAAY,GAAG,kCAAkC,CAAA;AAEvD,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E;;;;;GAKG;AACI,MAAM,UAAU,GAAG,KAAK,EAAE,MAAc,EAA6B,EAAE;IAC5E,IA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GAAG,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAChF,CAAA;IAED,IAAI,UAAU,GAAgC,SAAS,CAAA;IACvD,IAAI,aAAa;QAAE,UAAU,GAAG,cAAc,CAAA;SACzC,IAAI,KAAK,IAAI,MAAM;QAAE,UAAU,GAAG,gBAAgB,CAAA;SAClD,IAAI,MAAM;QAAE,UAAU,GAAG,iBAAiB,CAAA;IAE/C,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,CAAA;AACxC,CAAC,CAAA;AAtDY,QAAA,kBAAkB,sBAsD9B"}
|
package/dist/tokens.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token data fetching
|
|
3
|
+
*
|
|
4
|
+
* Read-only functions for querying token state from Solana.
|
|
5
|
+
*/
|
|
6
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
7
|
+
import { BondingCurve, Treasury } from './program';
|
|
8
|
+
import { TokenDetail, TokenListParams, TokenListResult, HoldersResult, MessagesResult, LendingInfo, LoanPositionInfo } from './types';
|
|
9
|
+
declare const fetchTokenRaw: (connection: Connection, mint: PublicKey) => Promise<{
|
|
10
|
+
bondingCurve: BondingCurve;
|
|
11
|
+
treasury: Treasury | null;
|
|
12
|
+
} | null>;
|
|
13
|
+
/**
|
|
14
|
+
* List tokens with optional filtering and sorting.
|
|
15
|
+
*/
|
|
16
|
+
export declare const getTokens: (connection: Connection, params?: TokenListParams) => Promise<TokenListResult>;
|
|
17
|
+
/**
|
|
18
|
+
* Get detailed info for a single token.
|
|
19
|
+
*/
|
|
20
|
+
export declare const getToken: (connection: Connection, mintStr: string) => Promise<TokenDetail>;
|
|
21
|
+
/**
|
|
22
|
+
* Get top holders for a token.
|
|
23
|
+
*/
|
|
24
|
+
export declare const getHolders: (connection: Connection, mintStr: string, limit?: number) => Promise<HoldersResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Get messages (memos) for a token.
|
|
27
|
+
*/
|
|
28
|
+
export declare const getMessages: (connection: Connection, mintStr: string, limit?: number) => Promise<MessagesResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Get lending info for a migrated token.
|
|
31
|
+
*
|
|
32
|
+
* Returns interest rates, LTV limits, and active loan statistics.
|
|
33
|
+
* Lending is available on all migrated tokens with treasury SOL.
|
|
34
|
+
*/
|
|
35
|
+
export declare const getLendingInfo: (connection: Connection, mintStr: string) => Promise<LendingInfo>;
|
|
36
|
+
/**
|
|
37
|
+
* Get loan position for a wallet on a specific token.
|
|
38
|
+
*
|
|
39
|
+
* Returns collateral locked, SOL owed, health status, etc.
|
|
40
|
+
* Returns health="none" if no active loan exists.
|
|
41
|
+
*/
|
|
42
|
+
export declare const getLoanPosition: (connection: Connection, mintStr: string, walletStr: string) => Promise<LoanPositionInfo>;
|
|
43
|
+
export { fetchTokenRaw };
|
|
44
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAGvD,OAAO,EACL,YAAY,EACZ,QAAQ,EAUT,MAAM,WAAW,CAAA;AAalB,OAAO,EAEL,WAAW,EAEX,eAAe,EACf,eAAe,EAEf,aAAa,EAEb,cAAc,EAEd,WAAW,EACX,gBAAgB,EACjB,MAAM,SAAS,CAAA;AAqLhB,QAAA,MAAM,aAAa,GACjB,YAAY,UAAU,EACtB,MAAM,SAAS,KACd,OAAO,CAAC;IAAE,YAAY,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAA;CAAE,GAAG,IAAI,CAwB1E,CAAA;AAMD;;GAEG;AACH,eAAO,MAAM,SAAS,GACpB,YAAY,UAAU,EACtB,SAAQ,eAAo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