hedge-web3 0.1.15 → 0.1.16
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/Constants.d.ts +1 -1
- package/declarations/HedgeDecimal.d.ts +2 -2
- package/declarations/index.d.ts +1 -0
- package/declarations/instructions/initHedgeFoundationTokens.d.ts +4 -0
- package/lib/Constants.js +1 -1
- package/lib/HedgeDecimal.js +2 -2
- package/lib/index.js +1 -0
- package/lib/instructions/initHedgeFoundationTokens.js +48 -0
- package/package.json +2 -2
- package/src/Constants.ts +1 -1
- package/src/HedgeDecimal.ts +2 -2
- package/src/index.ts +1 -0
- package/src/instructions/initHedgeFoundationTokens.ts +55 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
2
|
-
export declare const HEDGE_PROGRAM_ID = "
|
2
|
+
export declare const HEDGE_PROGRAM_ID = "h4sPyjiRvWLquKRULRND9jHCPKqRYZZukvrjMZn21Pz";
|
3
3
|
export declare const HEDGE_PROGRAM_PUBLICKEY: PublicKey;
|
4
4
|
export declare const CHAINLINK_SOL_USD_ID = "FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf";
|
5
5
|
export declare const CHAINLINK_SOL_USD_PUBLICKEY: PublicKey;
|
@@ -4,9 +4,9 @@ import Decimal from 'decimal.js';
|
|
4
4
|
*
|
5
5
|
* On chain, u128s are used to store Decimal numbers. These values
|
6
6
|
* are simply stored as u128 where the actual value is divided by
|
7
|
-
* 1.0e+
|
7
|
+
* 1.0e+18. This gives 24 digits of percision on decimal numbers.
|
8
8
|
*
|
9
|
-
* Example: the number 1.5 is stored as a u128: 1.5 * 10^
|
9
|
+
* Example: the number 1.5 is stored as a u128: 1.5 * 10^18
|
10
10
|
*
|
11
11
|
* @param value the value to be converted to Decimal
|
12
12
|
* @returns the converted value as a decimal.js object
|
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/Constants.js
CHANGED
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.findAssociatedTokenAddress = exports.findVaultAddress = exports.getVaultTypeAccountPublicKey = exports.getPoolPublicKeyForMint = exports.getHedgeMintPublicKey = exports.getVaultSystemStatePublicKey = exports.getUsdhMintPublicKey = exports.getLiquidationPoolUsdhAccountPublicKey = exports.getLiquidationPoolStatePublicKey = exports.CHAINLINK_SOL_USD_PUBLICKEY = exports.CHAINLINK_SOL_USD_ID = exports.HEDGE_PROGRAM_PUBLICKEY = exports.HEDGE_PROGRAM_ID = void 0;
|
13
13
|
const spl_token_1 = require("@solana/spl-token");
|
14
14
|
const web3_js_1 = require("@solana/web3.js");
|
15
|
-
exports.HEDGE_PROGRAM_ID = '
|
15
|
+
exports.HEDGE_PROGRAM_ID = 'h4sPyjiRvWLquKRULRND9jHCPKqRYZZukvrjMZn21Pz';
|
16
16
|
exports.HEDGE_PROGRAM_PUBLICKEY = new web3_js_1.PublicKey(exports.HEDGE_PROGRAM_ID);
|
17
17
|
exports.CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf';
|
18
18
|
exports.CHAINLINK_SOL_USD_PUBLICKEY = new web3_js_1.PublicKey(exports.CHAINLINK_SOL_USD_ID);
|
package/lib/HedgeDecimal.js
CHANGED
@@ -10,9 +10,9 @@ const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
10
10
|
*
|
11
11
|
* On chain, u128s are used to store Decimal numbers. These values
|
12
12
|
* are simply stored as u128 where the actual value is divided by
|
13
|
-
* 1.0e+
|
13
|
+
* 1.0e+18. This gives 24 digits of percision on decimal numbers.
|
14
14
|
*
|
15
|
-
* Example: the number 1.5 is stored as a u128: 1.5 * 10^
|
15
|
+
* Example: the number 1.5 is stored as a u128: 1.5 * 10^18
|
16
16
|
*
|
17
17
|
* @param value the value to be converted to Decimal
|
18
18
|
* @returns the converted value as a decimal.js object
|
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
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hedge-web3",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.16",
|
4
4
|
"description": "Hedge Javascript Web3 API",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"scripts": {
|
@@ -10,7 +10,7 @@
|
|
10
10
|
"docs": "set -ex; typedoc --includeVersion",
|
11
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
12
12
|
},
|
13
|
-
"author": "Chris Coudron <coudron@
|
13
|
+
"author": "Chris Coudron <coudron@hedge.so>",
|
14
14
|
"license": "ISC",
|
15
15
|
"devDependencies": {
|
16
16
|
"@rollup/plugin-typescript": "^8.3.0",
|
package/src/Constants.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
2
2
|
import { PublicKey } from '@solana/web3.js'
|
3
3
|
|
4
|
-
export const HEDGE_PROGRAM_ID = '
|
4
|
+
export const HEDGE_PROGRAM_ID = 'h4sPyjiRvWLquKRULRND9jHCPKqRYZZukvrjMZn21Pz'
|
5
5
|
export const HEDGE_PROGRAM_PUBLICKEY = new PublicKey(HEDGE_PROGRAM_ID)
|
6
6
|
|
7
7
|
export const CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'
|
package/src/HedgeDecimal.ts
CHANGED
@@ -5,9 +5,9 @@ import Decimal from 'decimal.js'
|
|
5
5
|
*
|
6
6
|
* On chain, u128s are used to store Decimal numbers. These values
|
7
7
|
* are simply stored as u128 where the actual value is divided by
|
8
|
-
* 1.0e+
|
8
|
+
* 1.0e+18. This gives 24 digits of percision on decimal numbers.
|
9
9
|
*
|
10
|
-
* Example: the number 1.5 is stored as a u128: 1.5 * 10^
|
10
|
+
* Example: the number 1.5 is stored as a u128: 1.5 * 10^18
|
11
11
|
*
|
12
12
|
* @param value the value to be converted to Decimal
|
13
13
|
* @returns the converted value as a decimal.js object
|
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
|
+
}
|