@overcast-xyz/solana-program 0.1.1
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 +201 -0
- package/dist/idl.d.ts +52 -0
- package/dist/idl.js +58 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +29 -0
- package/dist/overcast_core.d.ts +4388 -0
- package/dist/overcast_core.js +2 -0
- package/dist/overcast_core.json +3630 -0
- package/dist/overcast_fee_hook.d.ts +533 -0
- package/dist/overcast_fee_hook.js +2 -0
- package/dist/overcast_fee_hook.json +447 -0
- package/dist/overcast_settlement_oracle_gated.d.ts +578 -0
- package/dist/overcast_settlement_oracle_gated.js +2 -0
- package/dist/overcast_settlement_oracle_gated.json +572 -0
- package/dist/overcast_settlement_physical.d.ts +414 -0
- package/dist/overcast_settlement_physical.js +2 -0
- package/dist/overcast_settlement_physical.json +393 -0
- package/dist/pda.d.ts +129 -0
- package/dist/pda.js +191 -0
- package/package.json +41 -0
package/dist/pda.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ORACLE_KIND = exports.USED_OPERATION_SEED = exports.SIGNING_KEY_SEED = exports.MINT_COLLATERAL_RETURN_SEED = exports.MINT_EXERCISE_SEED = exports.OPTION_SETTLEMENT_ESCROW_SEED = exports.OPTION_COLLATERAL_ESCROW_SEED = exports.OPTION_SEED = exports.STATIC_PROTOCOL_FEE_SEED = exports.SETTLEMENT_CONFIG_SEED = exports.OFFER_ESCROW_SEED = exports.OFFER_SEED = exports.PROTOCOL_ESCROW_SEED = exports.PROTOCOL_STATE_SEED = void 0;
|
|
4
|
+
exports.getProtocolStatePda = getProtocolStatePda;
|
|
5
|
+
exports.getProtocolEscrowAccountPda = getProtocolEscrowAccountPda;
|
|
6
|
+
exports.getSettlementConfigPda = getSettlementConfigPda;
|
|
7
|
+
exports.getProtocolFeePda = getProtocolFeePda;
|
|
8
|
+
exports.getOfferPda = getOfferPda;
|
|
9
|
+
exports.getOfferEscrowPda = getOfferEscrowPda;
|
|
10
|
+
exports.getOptionPda = getOptionPda;
|
|
11
|
+
exports.getOptionCollateralEscrowPda = getOptionCollateralEscrowPda;
|
|
12
|
+
exports.getOptionSettlementEscrowPda = getOptionSettlementEscrowPda;
|
|
13
|
+
exports.getMintExercisePda = getMintExercisePda;
|
|
14
|
+
exports.getMintCollateralReturnPda = getMintCollateralReturnPda;
|
|
15
|
+
exports.getSigningKeyDelegationPda = getSigningKeyDelegationPda;
|
|
16
|
+
exports.getUsedOperationPda = getUsedOperationPda;
|
|
17
|
+
exports.deriveOfferPdas = deriveOfferPdas;
|
|
18
|
+
exports.getOracleSettlementConfigPda = getOracleSettlementConfigPda;
|
|
19
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
20
|
+
/**
|
|
21
|
+
* Program Derived Address (PDA) helpers.
|
|
22
|
+
*
|
|
23
|
+
* Seeds are kept in one place so that callers stay in sync with the on-chain
|
|
24
|
+
* program (see `programs/overcast-core/src/constants.rs`). When a new PDA is
|
|
25
|
+
* added to the program, add its seed and a matching derivation helper here so
|
|
26
|
+
* every consumer derives addresses the same way.
|
|
27
|
+
*/
|
|
28
|
+
/** Seed for the singleton protocol state account. */
|
|
29
|
+
exports.PROTOCOL_STATE_SEED = Buffer.from("protocol-state");
|
|
30
|
+
exports.PROTOCOL_ESCROW_SEED = Buffer.from("protocol-escrow");
|
|
31
|
+
/**
|
|
32
|
+
* Single offer PDA seed. Collateral (maker) and settlement (taker) offers were
|
|
33
|
+
* merged into one content-addressed `Offer`, so both now share this seed; the
|
|
34
|
+
* offer's `id` (which folds in its `side`) is what keeps the two disjoint.
|
|
35
|
+
*/
|
|
36
|
+
exports.OFFER_SEED = Buffer.from("offer");
|
|
37
|
+
/** Per-offer escrow seed — holds the locked collateral (maker) or premium (taker). */
|
|
38
|
+
exports.OFFER_ESCROW_SEED = Buffer.from("offer-escrow");
|
|
39
|
+
/**
|
|
40
|
+
* Seed for the physical-settlement layer's config PDA. Lives in the separate
|
|
41
|
+
* `overcast_settlement_physical` program, so its `get*Pda` helper below takes
|
|
42
|
+
* that layer's program id rather than the core program id.
|
|
43
|
+
* Mirrors `SETTLEMENT_CONFIG_SEED` in the layer's `constants.rs`.
|
|
44
|
+
*/
|
|
45
|
+
exports.SETTLEMENT_CONFIG_SEED = Buffer.from("settlement-config");
|
|
46
|
+
/**
|
|
47
|
+
* Seed for the protocol-fee hook's config PDA. Lives in the separate
|
|
48
|
+
* `overcast_fee_hook` program, so its `get*Pda` helper below takes that
|
|
49
|
+
* program's id rather than the core program id. Mirrors `STATIC_PROTOCOL_FEE`
|
|
50
|
+
* in the hook's `constants.rs`.
|
|
51
|
+
*/
|
|
52
|
+
exports.STATIC_PROTOCOL_FEE_SEED = Buffer.from("static-protocol-fee");
|
|
53
|
+
exports.OPTION_SEED = Buffer.from("option");
|
|
54
|
+
exports.OPTION_COLLATERAL_ESCROW_SEED = Buffer.from("option-collateral-escrow");
|
|
55
|
+
/** Seed for the option's escrow that collects settlement paid on exercise. */
|
|
56
|
+
exports.OPTION_SETTLEMENT_ESCROW_SEED = Buffer.from("option-settlement-escrow");
|
|
57
|
+
exports.MINT_EXERCISE_SEED = Buffer.from("mint-exercise");
|
|
58
|
+
exports.MINT_COLLATERAL_RETURN_SEED = Buffer.from("mint-collateral-return");
|
|
59
|
+
/** Seed for the record binding a delegated signing key to its owner. */
|
|
60
|
+
exports.SIGNING_KEY_SEED = Buffer.from("signing-key");
|
|
61
|
+
/** Seed for the replay guard consumed when a signed operation executes. */
|
|
62
|
+
exports.USED_OPERATION_SEED = Buffer.from("used-operation");
|
|
63
|
+
/** Singleton protocol state PDA. Mirrors `seeds = [PROTOCOL_STATE_SEED]`. */
|
|
64
|
+
function getProtocolStatePda(programId) {
|
|
65
|
+
return web3_js_1.PublicKey.findProgramAddressSync([exports.PROTOCOL_STATE_SEED], programId);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Per-user, per-mint vault token account owned by the protocol — the
|
|
69
|
+
* `user_token_account` in deposit / withdraw.
|
|
70
|
+
*
|
|
71
|
+
* Mirrors: `seeds = [PROTOCOL_ESCROW_SEED, user, mint]`.
|
|
72
|
+
*/
|
|
73
|
+
function getProtocolEscrowAccountPda(programId, user, mint) {
|
|
74
|
+
return web3_js_1.PublicKey.findProgramAddressSync([exports.PROTOCOL_ESCROW_SEED, user.toBuffer(), mint.toBuffer()], programId);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Physical-settlement layer config PDA.
|
|
78
|
+
*
|
|
79
|
+
* Mirrors: `seeds = [SETTLEMENT_CONFIG_SEED, authority, salt]` in the layer.
|
|
80
|
+
* The derived address is what callers put into
|
|
81
|
+
* `option_details.settlement_layer`; the `physicalProgramId` is what they pass
|
|
82
|
+
* as `settlement_program` to `accept_offer` / `exercise_option`.
|
|
83
|
+
*/
|
|
84
|
+
function getSettlementConfigPda(physicalProgramId) {
|
|
85
|
+
return web3_js_1.PublicKey.findProgramAddressSync([exports.SETTLEMENT_CONFIG_SEED], physicalProgramId);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Protocol-fee hook config PDA.
|
|
89
|
+
*
|
|
90
|
+
* Mirrors: `seeds = [STATIC_PROTOCOL_FEE, config.salt]` in the hook. The
|
|
91
|
+
* derived address is the `ProtocolFee` account callers point
|
|
92
|
+
* `ProtocolState.option_creation_hook` at (and pass as `hook_config` to
|
|
93
|
+
* `accept_offer`); `feeHookProgramId` is what they pass as `hook_program`.
|
|
94
|
+
*/
|
|
95
|
+
function getProtocolFeePda(feeHookProgramId, salt) {
|
|
96
|
+
return web3_js_1.PublicKey.findProgramAddressSync([exports.STATIC_PROTOCOL_FEE_SEED, salt.toBuffer()], feeHookProgramId);
|
|
97
|
+
}
|
|
98
|
+
/* -------------------------------------------------------------------------- */
|
|
99
|
+
/* Content-addressed offer / option PDAs */
|
|
100
|
+
/* */
|
|
101
|
+
/* Offers are content-addressed: their PDA seed is a 32-byte `id` derived by */
|
|
102
|
+
/* hashing the offer's raw-byte serialization (the on-chain `HashId::id()` in */
|
|
103
|
+
/* `programs/overcast-core/src/utils/serialization.rs`). The helpers below */
|
|
104
|
+
/* take that pre-computed `id` so derivation stays a pure, synchronous mirror */
|
|
105
|
+
/* of the on-chain `seeds = [..]` clauses. */
|
|
106
|
+
/* -------------------------------------------------------------------------- */
|
|
107
|
+
/** Mirrors: `seeds = [OFFER_SEED, offer_id]` */
|
|
108
|
+
function getOfferPda(programId, id) {
|
|
109
|
+
return web3_js_1.PublicKey.findProgramAddressSync([exports.OFFER_SEED, id], programId);
|
|
110
|
+
}
|
|
111
|
+
/** Mirrors: `seeds = [OFFER_ESCROW_SEED, offer_id]` */
|
|
112
|
+
function getOfferEscrowPda(programId, id) {
|
|
113
|
+
return web3_js_1.PublicKey.findProgramAddressSync([exports.OFFER_ESCROW_SEED, id], programId);
|
|
114
|
+
}
|
|
115
|
+
/** Mirrors: `seeds = [OPTION_SEED, collateral_offer_id, settlement_offer_id]` */
|
|
116
|
+
function getOptionPda(programId, collateralOfferId, settlementOfferId) {
|
|
117
|
+
return web3_js_1.PublicKey.findProgramAddressSync([exports.OPTION_SEED, collateralOfferId, settlementOfferId], programId);
|
|
118
|
+
}
|
|
119
|
+
/** Mirrors: `seeds = [OPTION_COLLATERAL_ESCROW_SEED, collateral_offer_id, settlement_offer_id]` */
|
|
120
|
+
function getOptionCollateralEscrowPda(programId, collateralOfferId, settlementOfferId) {
|
|
121
|
+
return web3_js_1.PublicKey.findProgramAddressSync([exports.OPTION_COLLATERAL_ESCROW_SEED, collateralOfferId, settlementOfferId], programId);
|
|
122
|
+
}
|
|
123
|
+
/** Mirrors: `seeds = [OPTION_SETTLEMENT_ESCROW_SEED, collateral_offer_id, settlement_offer_id]` */
|
|
124
|
+
function getOptionSettlementEscrowPda(programId, collateralOfferId, settlementOfferId) {
|
|
125
|
+
return web3_js_1.PublicKey.findProgramAddressSync([exports.OPTION_SETTLEMENT_ESCROW_SEED, collateralOfferId, settlementOfferId], programId);
|
|
126
|
+
}
|
|
127
|
+
/** Mirrors: `seeds = [MINT_EXERCISE_SEED, collateral_offer_id, settlement_offer_id]` */
|
|
128
|
+
function getMintExercisePda(programId, collateralOfferId, settlementOfferId) {
|
|
129
|
+
return web3_js_1.PublicKey.findProgramAddressSync([exports.MINT_EXERCISE_SEED, collateralOfferId, settlementOfferId], programId);
|
|
130
|
+
}
|
|
131
|
+
/** Mirrors: `seeds = [MINT_COLLATERAL_RETURN_SEED, collateral_offer_id, settlement_offer_id]` */
|
|
132
|
+
function getMintCollateralReturnPda(programId, collateralOfferId, settlementOfferId) {
|
|
133
|
+
return web3_js_1.PublicKey.findProgramAddressSync([exports.MINT_COLLATERAL_RETURN_SEED, collateralOfferId, settlementOfferId], programId);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Record proving `owner` authorized `key` to sign operations on its behalf.
|
|
137
|
+
*
|
|
138
|
+
* Mirrors: `seeds = [SIGNING_KEY_SEED, owner, key]` in `add_signing_key.rs`.
|
|
139
|
+
*/
|
|
140
|
+
function getSigningKeyDelegationPda(programId, owner, key) {
|
|
141
|
+
return web3_js_1.PublicKey.findProgramAddressSync([exports.SIGNING_KEY_SEED, owner.toBuffer(), key.toBuffer()], programId);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Replay guard for a signed operation: created when the operation is consumed,
|
|
145
|
+
* so the same (signer, nonce) pair can never execute twice.
|
|
146
|
+
*
|
|
147
|
+
* Mirrors: `seeds = [USED_OPERATION_SEED, signer, nonce]` in `operation.rs`,
|
|
148
|
+
* where `signer` is the account the operation acts for (offer maker / option
|
|
149
|
+
* taker), not the transaction submitter.
|
|
150
|
+
*/
|
|
151
|
+
function getUsedOperationPda(programId, signer, nonce) {
|
|
152
|
+
return web3_js_1.PublicKey.findProgramAddressSync([exports.USED_OPERATION_SEED, signer.toBuffer(), Buffer.from(nonce)], programId);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Derives an offer's account and escrow PDAs from its pre-computed 32-byte
|
|
156
|
+
* content-addressed `id` (see `HashId::id()` on-chain). Works for both sides —
|
|
157
|
+
* the `side` is already baked into `id`.
|
|
158
|
+
*/
|
|
159
|
+
function deriveOfferPdas(program, id) {
|
|
160
|
+
const [offer] = getOfferPda(program.programId, id);
|
|
161
|
+
const [escrow] = getOfferEscrowPda(program.programId, id);
|
|
162
|
+
return { offer, escrow };
|
|
163
|
+
}
|
|
164
|
+
/** Mirrors `OracleKind` in the oracle-gated layer's `state.rs`. */
|
|
165
|
+
exports.ORACLE_KIND = {
|
|
166
|
+
Pyth: 0,
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Oracle-gated settlement layer config PDA.
|
|
170
|
+
*
|
|
171
|
+
* Mirrors: `seeds = [SETTLEMENT_CONFIG_SEED, coll_mint, sett_mint,
|
|
172
|
+
* coll_oracle_kind_byte, coll_oracle_id,
|
|
173
|
+
* sett_oracle_kind_byte, sett_oracle_id]`.
|
|
174
|
+
*
|
|
175
|
+
* The full binding is baked into the address, so the pubkey alone is enough
|
|
176
|
+
* to verify what (mints, oracles) this config covers.
|
|
177
|
+
*/
|
|
178
|
+
function getOracleSettlementConfigPda(oracleGatedProgramId, collMint, settMint, collOracleKind, collOracleId, settOracleKind, settOracleId) {
|
|
179
|
+
if (collOracleId.length !== 32 || settOracleId.length !== 32) {
|
|
180
|
+
throw new Error("oracle ids must be 32 bytes");
|
|
181
|
+
}
|
|
182
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
183
|
+
exports.SETTLEMENT_CONFIG_SEED,
|
|
184
|
+
collMint.toBuffer(),
|
|
185
|
+
settMint.toBuffer(),
|
|
186
|
+
Buffer.from([collOracleKind]),
|
|
187
|
+
Buffer.from(collOracleId),
|
|
188
|
+
Buffer.from([settOracleKind]),
|
|
189
|
+
Buffer.from(settOracleId),
|
|
190
|
+
], oracleGatedProgramId);
|
|
191
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@overcast-xyz/solana-program",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "TypeScript mirror of the Overcast Solana program: IDL types, PDA derivation, and offer content-addressing.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"solana",
|
|
7
|
+
"overcast"
|
|
8
|
+
],
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"author": "info@overcast.xyz",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"provenance": false
|
|
14
|
+
},
|
|
15
|
+
"type": "commonjs",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"types": "dist/index.d.ts",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@anchor-lang/core": "1.0.2",
|
|
29
|
+
"@solana/web3.js": "^1.98.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^20.0.0",
|
|
33
|
+
"typescript": "^5.7.3"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "pnpm run build:idl && pnpm run build:ts",
|
|
37
|
+
"build:idl": "cd ../.. && anchor build && cp target/types/overcast_core.ts packages/solana-program/src/overcast_core.ts && cp target/idl/overcast_core.json packages/solana-program/src/overcast_core.json && cp target/types/overcast_settlement_physical.ts packages/solana-program/src/overcast_settlement_physical.ts && cp target/idl/overcast_settlement_physical.json packages/solana-program/src/overcast_settlement_physical.json && cp target/types/overcast_settlement_oracle_gated.ts packages/solana-program/src/overcast_settlement_oracle_gated.ts && cp target/idl/overcast_settlement_oracle_gated.json packages/solana-program/src/overcast_settlement_oracle_gated.json && cp target/types/overcast_fee_hook.ts packages/solana-program/src/overcast_fee_hook.ts && cp target/idl/overcast_fee_hook.json packages/solana-program/src/overcast_fee_hook.json && pnpm exec prettier --write packages/solana-program/src/overcast_core.ts packages/solana-program/src/overcast_core.json packages/solana-program/src/overcast_settlement_physical.ts packages/solana-program/src/overcast_settlement_physical.json packages/solana-program/src/overcast_settlement_oracle_gated.ts packages/solana-program/src/overcast_settlement_oracle_gated.json packages/solana-program/src/overcast_fee_hook.ts packages/solana-program/src/overcast_fee_hook.json",
|
|
38
|
+
"build:ts": "tsc -p tsconfig.json && cp src/overcast_core.json dist/overcast_core.json && cp src/overcast_settlement_physical.json dist/overcast_settlement_physical.json && cp src/overcast_settlement_oracle_gated.json dist/overcast_settlement_oracle_gated.json && cp src/overcast_fee_hook.json dist/overcast_fee_hook.json",
|
|
39
|
+
"clean": "rm -rf dist"
|
|
40
|
+
}
|
|
41
|
+
}
|