@exponent-labs/exponent-vaults-pda 0.9.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.
@@ -0,0 +1,108 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { web3 } from "@coral-xyz/anchor";
4
+ export type SeedId = ReadonlyArray<number> | Uint8Array | Buffer;
5
+ /**
6
+ * Helper class for deriving Program Derived Addresses (PDAs) for Exponent Vaults
7
+ */
8
+ export declare class ExponentVaultsPDA {
9
+ programId: web3.PublicKey;
10
+ constructor(programId?: web3.PublicKey);
11
+ private findProgramAddressSync;
12
+ /**
13
+ * Derive the vault PDA
14
+ * Seeds: ["vault", seed_id]
15
+ */
16
+ vault({ seedId }: {
17
+ seedId: SeedId;
18
+ }): [web3.PublicKey, number];
19
+ /**
20
+ * Derive the LP mint PDA for a vault
21
+ * Seeds: ["mint_lp", vault_address]
22
+ */
23
+ mintLp({ vault }: {
24
+ vault: web3.PublicKey;
25
+ }): [web3.PublicKey, number];
26
+ /**
27
+ * Derive the LP token escrow PDA for a vault
28
+ * Seeds: ["token_lp_escrow", vault_address]
29
+ */
30
+ tokenLpEscrow({ vault }: {
31
+ vault: web3.PublicKey;
32
+ }): [web3.PublicKey, number];
33
+ /**
34
+ * Derive the token entry escrow PDA for a vault
35
+ * Seeds: ["token_entry_escrow", vault_address, mint]
36
+ */
37
+ tokenEntryEscrow({ vault, mint }: {
38
+ vault: web3.PublicKey;
39
+ mint: web3.PublicKey;
40
+ }): [web3.PublicKey, number];
41
+ /**
42
+ * Derive the singleton ExponentPrices PDA
43
+ * Seeds: ["exponent_prices"]
44
+ */
45
+ exponentPrices(): [web3.PublicKey, number];
46
+ /**
47
+ * Derive the withdrawal account PDA
48
+ * Seeds: ["withdrawal", vault_address, owner, withdrawal_id]
49
+ */
50
+ withdrawal({ vault, owner, withdrawalId, }: {
51
+ vault: web3.PublicKey;
52
+ owner: web3.PublicKey;
53
+ withdrawalId: bigint;
54
+ }): [web3.PublicKey, number];
55
+ }
56
+ /**
57
+ * Squads Protocol PDA helper
58
+ * These are PDAs for the Squads smart account program
59
+ */
60
+ export declare class SquadsPDA {
61
+ programId: web3.PublicKey;
62
+ constructor(programId: web3.PublicKey);
63
+ private findProgramAddressSync;
64
+ /**
65
+ * Derive Squads transaction PDA
66
+ * Seeds: ["smart_account", settings, "transaction", transaction_index]
67
+ */
68
+ transaction({ settings, transactionIndex, }: {
69
+ settings: web3.PublicKey;
70
+ transactionIndex: bigint;
71
+ }): [web3.PublicKey, number];
72
+ /**
73
+ * Derive Squads proposal PDA
74
+ * Seeds: ["smart_account", settings, "transaction", transaction_index, "proposal"]
75
+ */
76
+ proposal({ settings, transactionIndex, }: {
77
+ settings: web3.PublicKey;
78
+ transactionIndex: bigint;
79
+ }): [web3.PublicKey, number];
80
+ /**
81
+ * Derive Squads policy PDA
82
+ * Seeds: ["smart_account", "policy", settings, policy_seed]
83
+ */
84
+ policy({ settings, policySeed }: {
85
+ settings: web3.PublicKey;
86
+ policySeed: bigint;
87
+ }): [web3.PublicKey, number];
88
+ /**
89
+ * Derive Squads settings PDA (smart account settings)
90
+ * Seeds: ["smart_account", "settings", settings_seed.to_le_bytes()] where settings_seed is u128
91
+ */
92
+ settings({ settingsSeed }: {
93
+ settingsSeed: bigint;
94
+ }): [web3.PublicKey, number];
95
+ /**
96
+ * Derive Squads smart account (vault) PDA
97
+ * Seeds: ["smart_account", settings_key, "smart_account", account_index_bytes]
98
+ */
99
+ smartAccount({ settings, accountIndex, }: {
100
+ settings: web3.PublicKey;
101
+ accountIndex: number;
102
+ }): [web3.PublicKey, number];
103
+ /**
104
+ * Derive Squads program config PDA
105
+ * Seeds: ["program_config"]
106
+ */
107
+ programConfig(): [web3.PublicKey, number];
108
+ }
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SquadsPDA = exports.ExponentVaultsPDA = void 0;
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
+ const exponent_vaults_idl_1 = require("@exponent-labs/exponent-vaults-idl");
6
+ function encodeBigIntLE(byteLength, value) {
7
+ const buffer = Buffer.alloc(byteLength);
8
+ let remaining = value;
9
+ for (let i = 0; i < byteLength; i += 1) {
10
+ buffer[i] = Number(remaining & 0xffn);
11
+ remaining >>= 8n;
12
+ }
13
+ return buffer;
14
+ }
15
+ /**
16
+ * Helper class for deriving Program Derived Addresses (PDAs) for Exponent Vaults
17
+ */
18
+ class ExponentVaultsPDA {
19
+ programId;
20
+ constructor(programId = new anchor_1.web3.PublicKey(exponent_vaults_idl_1.PROGRAM_ID)) {
21
+ this.programId = programId;
22
+ }
23
+ findProgramAddressSync(seeds) {
24
+ return anchor_1.web3.PublicKey.findProgramAddressSync(seeds, this.programId);
25
+ }
26
+ /**
27
+ * Derive the vault PDA
28
+ * Seeds: ["vault", seed_id]
29
+ */
30
+ vault({ seedId }) {
31
+ return this.findProgramAddressSync([Buffer.from("vault"), Buffer.from(seedId)]);
32
+ }
33
+ /**
34
+ * Derive the LP mint PDA for a vault
35
+ * Seeds: ["mint_lp", vault_address]
36
+ */
37
+ mintLp({ vault }) {
38
+ return this.findProgramAddressSync([Buffer.from("mint_lp"), vault.toBuffer()]);
39
+ }
40
+ /**
41
+ * Derive the LP token escrow PDA for a vault
42
+ * Seeds: ["token_lp_escrow", vault_address]
43
+ */
44
+ tokenLpEscrow({ vault }) {
45
+ return this.findProgramAddressSync([Buffer.from("token_lp_escrow"), vault.toBuffer()]);
46
+ }
47
+ /**
48
+ * Derive the token entry escrow PDA for a vault
49
+ * Seeds: ["token_entry_escrow", vault_address, mint]
50
+ */
51
+ tokenEntryEscrow({ vault, mint }) {
52
+ return this.findProgramAddressSync([Buffer.from("token_entry_escrow"), vault.toBuffer(), mint.toBuffer()]);
53
+ }
54
+ /**
55
+ * Derive the singleton ExponentPrices PDA
56
+ * Seeds: ["exponent_prices"]
57
+ */
58
+ exponentPrices() {
59
+ return this.findProgramAddressSync([Buffer.from("exponent_prices")]);
60
+ }
61
+ /**
62
+ * Derive the withdrawal account PDA
63
+ * Seeds: ["withdrawal", vault_address, owner, withdrawal_id]
64
+ */
65
+ withdrawal({ vault, owner, withdrawalId, }) {
66
+ const withdrawalIdBuffer = encodeBigIntLE(8, withdrawalId);
67
+ return this.findProgramAddressSync([
68
+ Buffer.from("withdrawal"),
69
+ vault.toBuffer(),
70
+ owner.toBuffer(),
71
+ withdrawalIdBuffer,
72
+ ]);
73
+ }
74
+ }
75
+ exports.ExponentVaultsPDA = ExponentVaultsPDA;
76
+ /**
77
+ * Squads Protocol PDA helper
78
+ * These are PDAs for the Squads smart account program
79
+ */
80
+ class SquadsPDA {
81
+ programId;
82
+ constructor(programId) {
83
+ this.programId = programId;
84
+ }
85
+ findProgramAddressSync(seeds) {
86
+ return anchor_1.web3.PublicKey.findProgramAddressSync(seeds, this.programId);
87
+ }
88
+ /**
89
+ * Derive Squads transaction PDA
90
+ * Seeds: ["smart_account", settings, "transaction", transaction_index]
91
+ */
92
+ transaction({ settings, transactionIndex, }) {
93
+ const indexBuffer = encodeBigIntLE(8, transactionIndex);
94
+ return this.findProgramAddressSync([
95
+ Buffer.from("smart_account"),
96
+ settings.toBuffer(),
97
+ Buffer.from("transaction"),
98
+ indexBuffer,
99
+ ]);
100
+ }
101
+ /**
102
+ * Derive Squads proposal PDA
103
+ * Seeds: ["smart_account", settings, "transaction", transaction_index, "proposal"]
104
+ */
105
+ proposal({ settings, transactionIndex, }) {
106
+ const indexBuffer = encodeBigIntLE(8, transactionIndex);
107
+ return this.findProgramAddressSync([
108
+ Buffer.from("smart_account"),
109
+ settings.toBuffer(),
110
+ Buffer.from("transaction"),
111
+ indexBuffer,
112
+ Buffer.from("proposal"),
113
+ ]);
114
+ }
115
+ /**
116
+ * Derive Squads policy PDA
117
+ * Seeds: ["smart_account", "policy", settings, policy_seed]
118
+ */
119
+ policy({ settings, policySeed }) {
120
+ const seedBuffer = encodeBigIntLE(8, policySeed);
121
+ return this.findProgramAddressSync([
122
+ Buffer.from("smart_account"),
123
+ Buffer.from("policy"),
124
+ settings.toBuffer(),
125
+ seedBuffer,
126
+ ]);
127
+ }
128
+ /**
129
+ * Derive Squads settings PDA (smart account settings)
130
+ * Seeds: ["smart_account", "settings", settings_seed.to_le_bytes()] where settings_seed is u128
131
+ */
132
+ settings({ settingsSeed }) {
133
+ const seedBuffer = encodeBigIntLE(16, settingsSeed);
134
+ return this.findProgramAddressSync([Buffer.from("smart_account"), Buffer.from("settings"), seedBuffer]);
135
+ }
136
+ /**
137
+ * Derive Squads smart account (vault) PDA
138
+ * Seeds: ["smart_account", settings_key, "smart_account", account_index_bytes]
139
+ */
140
+ smartAccount({ settings, accountIndex, }) {
141
+ return this.findProgramAddressSync([
142
+ Buffer.from("smart_account"),
143
+ settings.toBuffer(),
144
+ Buffer.from("smart_account"),
145
+ Buffer.from([accountIndex]),
146
+ ]);
147
+ }
148
+ /**
149
+ * Derive Squads program config PDA
150
+ * Seeds: ["program_config"]
151
+ */
152
+ programConfig() {
153
+ return this.findProgramAddressSync([Buffer.from("smart_account"), Buffer.from("program_config")]);
154
+ }
155
+ }
156
+ exports.SquadsPDA = SquadsPDA;
157
+ //# sourceMappingURL=exponent-vaults-pda.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exponent-vaults-pda.js","sourceRoot":"","sources":["../src/exponent-vaults-pda.ts"],"names":[],"mappings":";;;AAAA,8CAAwC;AAExC,4EAA+D;AAI/D,SAAS,cAAc,CAAC,UAAkB,EAAE,KAAa;IACvD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;IACvC,IAAI,SAAS,GAAG,KAAK,CAAA;IAErB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC,CAAA;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AjGD,8BAiGC"}
@@ -0,0 +1 @@
1
+ export * from "./exponent-vaults-pda";
package/build/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./exponent-vaults-pda"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAqC"}
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@exponent-labs/exponent-vaults-pda",
3
+ "version": "0.9.0",
4
+ "main": "build/index.js",
5
+ "types": "build/index.d.ts",
6
+ "license": "AGPL-3.0",
7
+ "scripts": {
8
+ "build": "tsc --build"
9
+ },
10
+ "dependencies": {
11
+ "@coral-xyz/anchor": "0.30.0",
12
+ "@exponent-labs/exponent-vaults-idl": "0.9.0"
13
+ },
14
+ "devDependencies": {
15
+ "typescript": "5.4.5"
16
+ }
17
+ }
@@ -0,0 +1,193 @@
1
+ import { web3 } from "@coral-xyz/anchor"
2
+
3
+ import { PROGRAM_ID } from "@exponent-labs/exponent-vaults-idl"
4
+
5
+ export type SeedId = ReadonlyArray<number> | Uint8Array | Buffer
6
+
7
+ function encodeBigIntLE(byteLength: number, value: bigint): Buffer {
8
+ const buffer = Buffer.alloc(byteLength)
9
+ let remaining = value
10
+
11
+ for (let i = 0; i < byteLength; i += 1) {
12
+ buffer[i] = Number(remaining & 0xffn)
13
+ remaining >>= 8n
14
+ }
15
+
16
+ return buffer
17
+ }
18
+
19
+ /**
20
+ * Helper class for deriving Program Derived Addresses (PDAs) for Exponent Vaults
21
+ */
22
+ export class ExponentVaultsPDA {
23
+ constructor(public programId: web3.PublicKey = new web3.PublicKey(PROGRAM_ID)) {}
24
+
25
+ private findProgramAddressSync(seeds: (Buffer | Uint8Array)[]): [web3.PublicKey, number] {
26
+ return web3.PublicKey.findProgramAddressSync(seeds, this.programId)
27
+ }
28
+
29
+ /**
30
+ * Derive the vault PDA
31
+ * Seeds: ["vault", seed_id]
32
+ */
33
+ vault({ seedId }: { seedId: SeedId }): [web3.PublicKey, number] {
34
+ return this.findProgramAddressSync([Buffer.from("vault"), Buffer.from(seedId)])
35
+ }
36
+
37
+ /**
38
+ * Derive the LP mint PDA for a vault
39
+ * Seeds: ["mint_lp", vault_address]
40
+ */
41
+ mintLp({ vault }: { vault: web3.PublicKey }): [web3.PublicKey, number] {
42
+ return this.findProgramAddressSync([Buffer.from("mint_lp"), vault.toBuffer()])
43
+ }
44
+
45
+ /**
46
+ * Derive the LP token escrow PDA for a vault
47
+ * Seeds: ["token_lp_escrow", vault_address]
48
+ */
49
+ tokenLpEscrow({ vault }: { vault: web3.PublicKey }): [web3.PublicKey, number] {
50
+ return this.findProgramAddressSync([Buffer.from("token_lp_escrow"), vault.toBuffer()])
51
+ }
52
+
53
+ /**
54
+ * Derive the token entry escrow PDA for a vault
55
+ * Seeds: ["token_entry_escrow", vault_address, mint]
56
+ */
57
+ tokenEntryEscrow({ vault, mint }: { vault: web3.PublicKey; mint: web3.PublicKey }): [web3.PublicKey, number] {
58
+ return this.findProgramAddressSync([Buffer.from("token_entry_escrow"), vault.toBuffer(), mint.toBuffer()])
59
+ }
60
+
61
+ /**
62
+ * Derive the singleton ExponentPrices PDA
63
+ * Seeds: ["exponent_prices"]
64
+ */
65
+ exponentPrices(): [web3.PublicKey, number] {
66
+ return this.findProgramAddressSync([Buffer.from("exponent_prices")])
67
+ }
68
+
69
+ /**
70
+ * Derive the withdrawal account PDA
71
+ * Seeds: ["withdrawal", vault_address, owner, withdrawal_id]
72
+ */
73
+ withdrawal({
74
+ vault,
75
+ owner,
76
+ withdrawalId,
77
+ }: {
78
+ vault: web3.PublicKey
79
+ owner: web3.PublicKey
80
+ withdrawalId: bigint
81
+ }): [web3.PublicKey, number] {
82
+ const withdrawalIdBuffer = encodeBigIntLE(8, withdrawalId)
83
+ return this.findProgramAddressSync([
84
+ Buffer.from("withdrawal"),
85
+ vault.toBuffer(),
86
+ owner.toBuffer(),
87
+ withdrawalIdBuffer,
88
+ ])
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Squads Protocol PDA helper
94
+ * These are PDAs for the Squads smart account program
95
+ */
96
+ export class SquadsPDA {
97
+ constructor(public programId: web3.PublicKey) {}
98
+
99
+ private findProgramAddressSync(seeds: (Buffer | Uint8Array)[]): [web3.PublicKey, number] {
100
+ return web3.PublicKey.findProgramAddressSync(seeds, this.programId)
101
+ }
102
+
103
+ /**
104
+ * Derive Squads transaction PDA
105
+ * Seeds: ["smart_account", settings, "transaction", transaction_index]
106
+ */
107
+ transaction({
108
+ settings,
109
+ transactionIndex,
110
+ }: {
111
+ settings: web3.PublicKey
112
+ transactionIndex: bigint
113
+ }): [web3.PublicKey, number] {
114
+ const indexBuffer = encodeBigIntLE(8, transactionIndex)
115
+ return this.findProgramAddressSync([
116
+ Buffer.from("smart_account"),
117
+ settings.toBuffer(),
118
+ Buffer.from("transaction"),
119
+ indexBuffer,
120
+ ])
121
+ }
122
+
123
+ /**
124
+ * Derive Squads proposal PDA
125
+ * Seeds: ["smart_account", settings, "transaction", transaction_index, "proposal"]
126
+ */
127
+ proposal({
128
+ settings,
129
+ transactionIndex,
130
+ }: {
131
+ settings: web3.PublicKey
132
+ transactionIndex: bigint
133
+ }): [web3.PublicKey, number] {
134
+ const indexBuffer = encodeBigIntLE(8, transactionIndex)
135
+ return this.findProgramAddressSync([
136
+ Buffer.from("smart_account"),
137
+ settings.toBuffer(),
138
+ Buffer.from("transaction"),
139
+ indexBuffer,
140
+ Buffer.from("proposal"),
141
+ ])
142
+ }
143
+
144
+ /**
145
+ * Derive Squads policy PDA
146
+ * Seeds: ["smart_account", "policy", settings, policy_seed]
147
+ */
148
+ policy({ settings, policySeed }: { settings: web3.PublicKey; policySeed: bigint }): [web3.PublicKey, number] {
149
+ const seedBuffer = encodeBigIntLE(8, policySeed)
150
+ return this.findProgramAddressSync([
151
+ Buffer.from("smart_account"),
152
+ Buffer.from("policy"),
153
+ settings.toBuffer(),
154
+ seedBuffer,
155
+ ])
156
+ }
157
+
158
+ /**
159
+ * Derive Squads settings PDA (smart account settings)
160
+ * Seeds: ["smart_account", "settings", settings_seed.to_le_bytes()] where settings_seed is u128
161
+ */
162
+ settings({ settingsSeed }: { settingsSeed: bigint }): [web3.PublicKey, number] {
163
+ const seedBuffer = encodeBigIntLE(16, settingsSeed)
164
+ return this.findProgramAddressSync([Buffer.from("smart_account"), Buffer.from("settings"), seedBuffer])
165
+ }
166
+
167
+ /**
168
+ * Derive Squads smart account (vault) PDA
169
+ * Seeds: ["smart_account", settings_key, "smart_account", account_index_bytes]
170
+ */
171
+ smartAccount({
172
+ settings,
173
+ accountIndex,
174
+ }: {
175
+ settings: web3.PublicKey
176
+ accountIndex: number
177
+ }): [web3.PublicKey, number] {
178
+ return this.findProgramAddressSync([
179
+ Buffer.from("smart_account"),
180
+ settings.toBuffer(),
181
+ Buffer.from("smart_account"),
182
+ Buffer.from([accountIndex]),
183
+ ])
184
+ }
185
+
186
+ /**
187
+ * Derive Squads program config PDA
188
+ * Seeds: ["program_config"]
189
+ */
190
+ programConfig(): [web3.PublicKey, number] {
191
+ return this.findProgramAddressSync([Buffer.from("smart_account"), Buffer.from("program_config")])
192
+ }
193
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./exponent-vaults-pda"
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "src",
4
+ "sourceMap": true,
5
+ "incremental": true,
6
+ "composite": true,
7
+ "target": "ESNext",
8
+ "module": "CommonJS",
9
+ "declaration": true,
10
+ "outDir": "./build",
11
+ "esModuleInterop": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "skipLibCheck": true
14
+ },
15
+ "include": ["src"],
16
+ "exclude": ["build"],
17
+ "references": [{ "path": "../exponent-vaults-idl" }]
18
+ }