@exponent-labs/marginfi-sy-pda 0.0.3
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/CHANGELOG.md +16 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +18 -0
- package/build/index.js.map +1 -0
- package/build/marginfiSyPda.d.ts +50 -0
- package/build/marginfiSyPda.js +59 -0
- package/build/marginfiSyPda.js.map +1 -0
- package/package.json +19 -0
- package/src/index.ts +1 -0
- package/src/marginfiSyPda.ts +69 -0
- package/tsconfig.json +18 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [0.0.3](https://github.com/exponent-finance/exponent-core/compare/@exponent-labs/marginfi-sy-pda@0.0.2...@exponent-labs/marginfi-sy-pda@0.0.3) (2025-03-03)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @exponent-labs/marginfi-sy-pda
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.0.2](https://github.com/exponent-finance/exponent-core/compare/@exponent-labs/marginfi-sy-pda@0.0.1...@exponent-labs/marginfi-sy-pda@0.0.2) (2025-03-03)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @exponent-labs/marginfi-sy-pda
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./marginfiSyPda";
|
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("./marginfiSyPda"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { web3 } from "@coral-xyz/anchor";
|
|
2
|
+
export declare class MarginfiSyPda {
|
|
3
|
+
programId: web3.PublicKey;
|
|
4
|
+
constructor(programId?: web3.PublicKey);
|
|
5
|
+
private findProgramAddressSync;
|
|
6
|
+
/**
|
|
7
|
+
* Return the SY emission tracker account
|
|
8
|
+
* `bank` is the address of the Marginfi Bank
|
|
9
|
+
*/
|
|
10
|
+
emissionTracker({ bank }: {
|
|
11
|
+
bank: web3.PublicKey;
|
|
12
|
+
}): web3.PublicKey;
|
|
13
|
+
/**
|
|
14
|
+
* DEPRECATED: but preserved for backwards compatibility
|
|
15
|
+
* The syMeta PDA is the account authority over the marginfi program
|
|
16
|
+
*/
|
|
17
|
+
accountAuthority({ bank }: {
|
|
18
|
+
bank: web3.PublicKey;
|
|
19
|
+
}): web3.PublicKey;
|
|
20
|
+
/**
|
|
21
|
+
* Return the mint of the SY token
|
|
22
|
+
* `bank` is the address of the Marginfi Bank
|
|
23
|
+
*/
|
|
24
|
+
mintSy({ bank }: {
|
|
25
|
+
bank: web3.PublicKey;
|
|
26
|
+
}): web3.PublicKey;
|
|
27
|
+
/** The robot account with the Marginfi program, which owns the deposits */
|
|
28
|
+
marginfiAccount({ bank }: {
|
|
29
|
+
bank: web3.PublicKey;
|
|
30
|
+
}): web3.PublicKey;
|
|
31
|
+
/** Personal SY position (deposit balance, emission trackers) */
|
|
32
|
+
position({ signer, bank }: {
|
|
33
|
+
signer: web3.PublicKey;
|
|
34
|
+
bank: web3.PublicKey;
|
|
35
|
+
}): web3.PublicKey;
|
|
36
|
+
/** The escrow account that holds deposited SY tokens */
|
|
37
|
+
syEscrow({ bank }: {
|
|
38
|
+
bank: web3.PublicKey;
|
|
39
|
+
}): web3.PublicKey;
|
|
40
|
+
/** Master metadata account for an SY binding */
|
|
41
|
+
syMeta({ bank }: {
|
|
42
|
+
bank: web3.PublicKey;
|
|
43
|
+
}): web3.PublicKey;
|
|
44
|
+
/** Token account for holding underlying tokens - used as an interchange between the end-user and the Marginfi Program */
|
|
45
|
+
underlyingEscrow({ bank, mintUnderlying, tokenProgramUnderlying, }: {
|
|
46
|
+
bank: web3.PublicKey;
|
|
47
|
+
mintUnderlying: web3.PublicKey;
|
|
48
|
+
tokenProgramUnderlying: web3.PublicKey;
|
|
49
|
+
}): web3.PublicKey;
|
|
50
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MarginfiSyPda = void 0;
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
+
const marginfi_sy_idl_1 = require("@exponent-labs/marginfi-sy-idl");
|
|
6
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
7
|
+
class MarginfiSyPda {
|
|
8
|
+
programId;
|
|
9
|
+
constructor(programId = new anchor_1.web3.PublicKey(marginfi_sy_idl_1.IDL.address)) {
|
|
10
|
+
this.programId = programId;
|
|
11
|
+
}
|
|
12
|
+
findProgramAddressSync(seeds) {
|
|
13
|
+
return anchor_1.web3.PublicKey.findProgramAddressSync(seeds, this.programId)[0];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Return the SY emission tracker account
|
|
17
|
+
* `bank` is the address of the Marginfi Bank
|
|
18
|
+
*/
|
|
19
|
+
emissionTracker({ bank }) {
|
|
20
|
+
return this.findProgramAddressSync([Buffer.from("emission_tracker"), bank.toBuffer()]);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* DEPRECATED: but preserved for backwards compatibility
|
|
24
|
+
* The syMeta PDA is the account authority over the marginfi program
|
|
25
|
+
*/
|
|
26
|
+
accountAuthority({ bank }) {
|
|
27
|
+
return this.syMeta({ bank });
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Return the mint of the SY token
|
|
31
|
+
* `bank` is the address of the Marginfi Bank
|
|
32
|
+
*/
|
|
33
|
+
mintSy({ bank }) {
|
|
34
|
+
return this.findProgramAddressSync([Buffer.from("marginfi_standard_token"), bank.toBuffer()]);
|
|
35
|
+
}
|
|
36
|
+
/** The robot account with the Marginfi program, which owns the deposits */
|
|
37
|
+
marginfiAccount({ bank }) {
|
|
38
|
+
return this.findProgramAddressSync([Buffer.from("marginfi_account"), bank.toBuffer()]);
|
|
39
|
+
}
|
|
40
|
+
/** Personal SY position (deposit balance, emission trackers) */
|
|
41
|
+
position({ signer, bank }) {
|
|
42
|
+
return this.findProgramAddressSync([Buffer.from("position"), bank.toBuffer(), signer.toBuffer()]);
|
|
43
|
+
}
|
|
44
|
+
/** The escrow account that holds deposited SY tokens */
|
|
45
|
+
syEscrow({ bank }) {
|
|
46
|
+
return this.findProgramAddressSync([Buffer.from("sy_escrow"), bank.toBuffer()]);
|
|
47
|
+
}
|
|
48
|
+
/** Master metadata account for an SY binding */
|
|
49
|
+
syMeta({ bank }) {
|
|
50
|
+
return this.findProgramAddressSync([Buffer.from("sy_meta"), bank.toBuffer()]);
|
|
51
|
+
}
|
|
52
|
+
/** Token account for holding underlying tokens - used as an interchange between the end-user and the Marginfi Program */
|
|
53
|
+
underlyingEscrow({ bank, mintUnderlying, tokenProgramUnderlying, }) {
|
|
54
|
+
const owner = this.syMeta({ bank });
|
|
55
|
+
return (0, spl_token_1.getAssociatedTokenAddressSync)(mintUnderlying, owner, true, tokenProgramUnderlying);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.MarginfiSyPda = MarginfiSyPda;
|
|
59
|
+
//# sourceMappingURL=marginfiSyPda.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marginfiSyPda.js","sourceRoot":"","sources":["../src/marginfiSyPda.ts"],"names":[],"mappings":";;;AAAA,8CAAwC;AACxC,oEAAoD;AACpD,iDAAiE;AAEjE,MAAa,aAAa;IACL;IAAnB,YAAmB,YAA4B,IAAI,aAAI,CAAC,SAAS,CAAC,qBAAG,CAAC,OAAO,CAAC;QAA3D,cAAS,GAAT,SAAS,CAAkD;IAAG,CAAC;IAE1E,sBAAsB,CAAC,KAAe;QAC5C,OAAO,aAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;IACxE,CAAC;IAED;;;OAGG;IACH,eAAe,CAAC,EAAE,IAAI,EAA4B;QAChD,OAAO,IAAI,CAAC,sBAAsB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;IACxF,CAAC;IAED;;;OAGG;IACH,gBAAgB,CAAC,EAAE,IAAI,EAA4B;QACjD,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;IAC9B,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,EAAE,IAAI,EAA4B;QACvC,OAAO,IAAI,CAAC,sBAAsB,CA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0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@exponent-labs/marginfi-sy-pda",
|
|
3
|
+
"version": "0.0.3",
|
|
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/marginfi-sy-idl": "^0.0.3",
|
|
13
|
+
"@solana/spl-token": "0.4.6"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"typescript": "5.4.5"
|
|
17
|
+
},
|
|
18
|
+
"gitHead": "209b8847e9a0fadb5b5ec96b9b47f0ace4a3bf9d"
|
|
19
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./marginfiSyPda"
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { web3 } from "@coral-xyz/anchor"
|
|
2
|
+
import { IDL } from "@exponent-labs/marginfi-sy-idl"
|
|
3
|
+
import { getAssociatedTokenAddressSync } from "@solana/spl-token"
|
|
4
|
+
|
|
5
|
+
export class MarginfiSyPda {
|
|
6
|
+
constructor(public programId: web3.PublicKey = new web3.PublicKey(IDL.address)) {}
|
|
7
|
+
|
|
8
|
+
private findProgramAddressSync(seeds: Buffer[]) {
|
|
9
|
+
return web3.PublicKey.findProgramAddressSync(seeds, this.programId)[0]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Return the SY emission tracker account
|
|
14
|
+
* `bank` is the address of the Marginfi Bank
|
|
15
|
+
*/
|
|
16
|
+
emissionTracker({ bank }: { bank: web3.PublicKey }) {
|
|
17
|
+
return this.findProgramAddressSync([Buffer.from("emission_tracker"), bank.toBuffer()])
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* DEPRECATED: but preserved for backwards compatibility
|
|
22
|
+
* The syMeta PDA is the account authority over the marginfi program
|
|
23
|
+
*/
|
|
24
|
+
accountAuthority({ bank }: { bank: web3.PublicKey }) {
|
|
25
|
+
return this.syMeta({ bank })
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Return the mint of the SY token
|
|
30
|
+
* `bank` is the address of the Marginfi Bank
|
|
31
|
+
*/
|
|
32
|
+
mintSy({ bank }: { bank: web3.PublicKey }) {
|
|
33
|
+
return this.findProgramAddressSync([Buffer.from("marginfi_standard_token"), bank.toBuffer()])
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The robot account with the Marginfi program, which owns the deposits */
|
|
37
|
+
marginfiAccount({ bank }: { bank: web3.PublicKey }) {
|
|
38
|
+
return this.findProgramAddressSync([Buffer.from("marginfi_account"), bank.toBuffer()])
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Personal SY position (deposit balance, emission trackers) */
|
|
42
|
+
position({ signer, bank }: { signer: web3.PublicKey; bank: web3.PublicKey }) {
|
|
43
|
+
return this.findProgramAddressSync([Buffer.from("position"), bank.toBuffer(), signer.toBuffer()])
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The escrow account that holds deposited SY tokens */
|
|
47
|
+
syEscrow({ bank }: { bank: web3.PublicKey }) {
|
|
48
|
+
return this.findProgramAddressSync([Buffer.from("sy_escrow"), bank.toBuffer()])
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Master metadata account for an SY binding */
|
|
52
|
+
syMeta({ bank }: { bank: web3.PublicKey }) {
|
|
53
|
+
return this.findProgramAddressSync([Buffer.from("sy_meta"), bank.toBuffer()])
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Token account for holding underlying tokens - used as an interchange between the end-user and the Marginfi Program */
|
|
57
|
+
underlyingEscrow({
|
|
58
|
+
bank,
|
|
59
|
+
mintUnderlying,
|
|
60
|
+
tokenProgramUnderlying,
|
|
61
|
+
}: {
|
|
62
|
+
bank: web3.PublicKey
|
|
63
|
+
mintUnderlying: web3.PublicKey
|
|
64
|
+
tokenProgramUnderlying: web3.PublicKey
|
|
65
|
+
}) {
|
|
66
|
+
const owner = this.syMeta({ bank })
|
|
67
|
+
return getAssociatedTokenAddressSync(mintUnderlying, owner, true, tokenProgramUnderlying)
|
|
68
|
+
}
|
|
69
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"rootDir": "src",
|
|
4
|
+
"sourceMap": true,
|
|
5
|
+
"incremental": true /* Save .tsbuildinfo files to allow for incremental compilation of projects. */,
|
|
6
|
+
"composite": true /* Enable constraints that allow a TypeScript project to be used with project references. */,
|
|
7
|
+
"target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
8
|
+
"module": "CommonJS" /* Specify what module code is generated. */,
|
|
9
|
+
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
|
|
10
|
+
"outDir": "./build" /* Specify an output folder for all emitted files. */,
|
|
11
|
+
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
12
|
+
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
13
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
14
|
+
},
|
|
15
|
+
"include": ["src"],
|
|
16
|
+
"exclude": ["build"],
|
|
17
|
+
"references": [{ "path": "../marginfi-sy-idl" }]
|
|
18
|
+
}
|