hedge-web3 0.1.17 → 0.1.18
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/declarations/index.d.ts +1 -0
- package/declarations/instructions/initHedgeFoundationTokens.d.ts +4 -0
- package/lib/index.js +1 -0
- package/lib/instructions/initHedgeFoundationTokens.js +48 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/instructions/initHedgeFoundationTokens.ts +55 -0
package/declarations/index.d.ts
CHANGED
@@ -13,6 +13,7 @@ export * from './instructions/redeemVault';
|
|
13
13
|
export * from './instructions/liquidateVault';
|
14
14
|
export * from './instructions/refreshOraclePrice';
|
15
15
|
export * from './instructions/initHedgeFoundation';
|
16
|
+
export * from './instructions/initHedgeFoundationTokens';
|
16
17
|
export * from './instructions/setHalted';
|
17
18
|
export * from './HedgeDecimal';
|
18
19
|
export * from './Constants';
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { Program, Provider } from '@project-serum/anchor';
|
2
|
+
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
|
+
export declare function initHedgeFoundationTokens(program: Program, provider: Provider, payer: Signer): Promise<PublicKey>;
|
4
|
+
export declare function initHedgeFoundationTokensInstruction(program: Program, payerPublicKey: PublicKey): Promise<TransactionInstruction>;
|
package/lib/index.js
CHANGED
@@ -25,6 +25,7 @@ __exportStar(require("./instructions/redeemVault"), exports);
|
|
25
25
|
__exportStar(require("./instructions/liquidateVault"), exports);
|
26
26
|
__exportStar(require("./instructions/refreshOraclePrice"), exports);
|
27
27
|
__exportStar(require("./instructions/initHedgeFoundation"), exports);
|
28
|
+
__exportStar(require("./instructions/initHedgeFoundationTokens"), exports);
|
28
29
|
__exportStar(require("./instructions/setHalted"), exports);
|
29
30
|
__exportStar(require("./HedgeDecimal"), exports);
|
30
31
|
__exportStar(require("./Constants"), exports);
|
@@ -0,0 +1,48 @@
|
|
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
|
+
exports.initHedgeFoundationTokensInstruction = exports.initHedgeFoundationTokens = void 0;
|
13
|
+
const spl_token_1 = require("@solana/spl-token");
|
14
|
+
const web3_js_1 = require("@solana/web3.js");
|
15
|
+
const Errors_1 = require("../utils/Errors");
|
16
|
+
const Constants_1 = require("../Constants");
|
17
|
+
function initHedgeFoundationTokens(program, provider, payer) {
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
19
|
+
const poolEra = web3_js_1.Keypair.generate();
|
20
|
+
const transaction = new web3_js_1.Transaction().add(yield initHedgeFoundationTokensInstruction(program, payer.publicKey));
|
21
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer], provider.opts).catch(Errors_1.parseAnchorErrors);
|
22
|
+
return payer.publicKey;
|
23
|
+
});
|
24
|
+
}
|
25
|
+
exports.initHedgeFoundationTokens = initHedgeFoundationTokens;
|
26
|
+
function initHedgeFoundationTokensInstruction(program, payerPublicKey) {
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
28
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
29
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
30
|
+
const founderHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, hedgeMintPublickey);
|
31
|
+
const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultSystemStatePublicKey, hedgeMintPublickey);
|
32
|
+
return program.instruction.initHedgeFoundationTokens({
|
33
|
+
accounts: {
|
34
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
35
|
+
founder: payerPublicKey,
|
36
|
+
hedgeMint: hedgeMintPublickey,
|
37
|
+
founderAssociatedHedgeTokenAccount: founderHedgeTokenAccount,
|
38
|
+
communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
|
39
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
40
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
41
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
42
|
+
systemProgram: web3_js_1.SystemProgram.programId
|
43
|
+
},
|
44
|
+
signers: []
|
45
|
+
});
|
46
|
+
});
|
47
|
+
}
|
48
|
+
exports.initHedgeFoundationTokensInstruction = initHedgeFoundationTokensInstruction;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
@@ -14,6 +14,7 @@ export * from './instructions/redeemVault'
|
|
14
14
|
export * from './instructions/liquidateVault'
|
15
15
|
export * from './instructions/refreshOraclePrice'
|
16
16
|
export * from './instructions/initHedgeFoundation'
|
17
|
+
export * from './instructions/initHedgeFoundationTokens'
|
17
18
|
export * from './instructions/setHalted'
|
18
19
|
|
19
20
|
export * from './HedgeDecimal'
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { Program, Provider } from '@project-serum/anchor'
|
2
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
+
import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
+
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
+
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUsdhAccountPublicKey, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
6
|
+
|
7
|
+
export async function initHedgeFoundationTokens(
|
8
|
+
program: Program,
|
9
|
+
provider: Provider,
|
10
|
+
payer: Signer
|
11
|
+
): Promise<PublicKey> {
|
12
|
+
|
13
|
+
const poolEra = Keypair.generate()
|
14
|
+
const transaction = new Transaction().add(
|
15
|
+
await initHedgeFoundationTokensInstruction(
|
16
|
+
program,
|
17
|
+
payer.publicKey,
|
18
|
+
)
|
19
|
+
)
|
20
|
+
|
21
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts).catch(parseAnchorErrors)
|
22
|
+
return payer.publicKey
|
23
|
+
}
|
24
|
+
|
25
|
+
export async function initHedgeFoundationTokensInstruction (
|
26
|
+
program: Program,
|
27
|
+
payerPublicKey: PublicKey,
|
28
|
+
): Promise<TransactionInstruction> {
|
29
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
30
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
31
|
+
const founderHedgeTokenAccount = await findAssociatedTokenAddress(
|
32
|
+
payerPublicKey,
|
33
|
+
hedgeMintPublickey
|
34
|
+
)
|
35
|
+
const communityHedgeTokenAccount = await findAssociatedTokenAddress(
|
36
|
+
vaultSystemStatePublicKey,
|
37
|
+
hedgeMintPublickey
|
38
|
+
)
|
39
|
+
|
40
|
+
return program.instruction.initHedgeFoundationTokens(
|
41
|
+
{
|
42
|
+
accounts: {
|
43
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
44
|
+
founder: payerPublicKey,
|
45
|
+
hedgeMint: hedgeMintPublickey,
|
46
|
+
founderAssociatedHedgeTokenAccount: founderHedgeTokenAccount,
|
47
|
+
communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
|
48
|
+
rent: SYSVAR_RENT_PUBKEY,
|
49
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
50
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
51
|
+
systemProgram: SystemProgram.programId
|
52
|
+
},
|
53
|
+
signers: []
|
54
|
+
})
|
55
|
+
}
|