@exponent-labs/perena-sy-sdk 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 +62 -0
- package/build/index.js +234 -0
- package/build/index.js.map +1 -0
- package/build/tryit.d.ts +1 -0
- package/build/tryit.js +20 -0
- package/build/tryit.js.map +1 -0
- package/package.json +24 -0
- package/src/index.ts +319 -0
- package/src/tryit.ts +21 -0
- package/tsconfig.json +25 -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/perena-sy-sdk@0.0.2...@exponent-labs/perena-sy-sdk@0.0.3) (2025-03-03)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @exponent-labs/perena-sy-sdk
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.0.2](https://github.com/exponent-finance/exponent-core/compare/@exponent-labs/perena-sy-sdk@0.0.1...@exponent-labs/perena-sy-sdk@0.0.2) (2025-03-03)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @exponent-labs/perena-sy-sdk
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import { BN, Wallet, web3 } from "@coral-xyz/anchor";
|
|
3
|
+
import { PerenaSyPda } from "@exponent-labs/perena-sy-pda";
|
|
4
|
+
import { PerenaSyState } from "@exponent-labs/exponent-types";
|
|
5
|
+
export declare class MyWallet implements Wallet {
|
|
6
|
+
readonly payer: web3.Keypair;
|
|
7
|
+
constructor(payer: web3.Keypair);
|
|
8
|
+
signTransaction<T extends web3.Transaction | web3.VersionedTransaction>(tx: T): Promise<T>;
|
|
9
|
+
signAllTransactions<T extends web3.Transaction | web3.VersionedTransaction>(txs: T[]): Promise<T[]>;
|
|
10
|
+
get publicKey(): web3.PublicKey;
|
|
11
|
+
}
|
|
12
|
+
export declare class PerenaSySdk {
|
|
13
|
+
state: PerenaSyState;
|
|
14
|
+
/** Private program for building instructions */
|
|
15
|
+
private program;
|
|
16
|
+
syPda: PerenaSyPda;
|
|
17
|
+
constructor(state: PerenaSyState, programId?: web3.PublicKey);
|
|
18
|
+
/** Load an instance of SyMeta */
|
|
19
|
+
static load({ cnx, perenaStablePool, perenaSyProgramId, }: {
|
|
20
|
+
cnx: web3.Connection;
|
|
21
|
+
perenaStablePool: web3.PublicKey;
|
|
22
|
+
perenaSyProgramId: web3.PublicKey;
|
|
23
|
+
}): Promise<PerenaSySdk>;
|
|
24
|
+
/** Reload the state of the account */
|
|
25
|
+
reload(cnx: web3.Connection): Promise<void>;
|
|
26
|
+
get account(): import("@exponent-labs/exponent-types").PerenaSyMetaAccount;
|
|
27
|
+
get mintSy(): web3.PublicKey;
|
|
28
|
+
get maxSySupply(): BN;
|
|
29
|
+
get emissions(): import("@exponent-labs/exponent-types").SyEmissionRaw[];
|
|
30
|
+
get minMintSize(): BN;
|
|
31
|
+
get minRedeemSize(): BN;
|
|
32
|
+
get mintBase(): web3.PublicKey;
|
|
33
|
+
get selfAddress(): web3.PublicKey;
|
|
34
|
+
get tokenProgramBase(): web3.PublicKey;
|
|
35
|
+
get tokenLpMintEscrow(): web3.PublicKey;
|
|
36
|
+
get tokenSyEscrow(): web3.PublicKey;
|
|
37
|
+
get adminState(): web3.PublicKey;
|
|
38
|
+
get remainingAccounts(): {
|
|
39
|
+
pubkey: web3.PublicKey;
|
|
40
|
+
isSigner: boolean;
|
|
41
|
+
isWritable: boolean;
|
|
42
|
+
}[];
|
|
43
|
+
ixMintSy({ depositor, amountBase, baseSrc, syDst, }: {
|
|
44
|
+
depositor: web3.PublicKey;
|
|
45
|
+
amountBase: string;
|
|
46
|
+
baseSrc?: web3.PublicKey;
|
|
47
|
+
syDst?: web3.PublicKey;
|
|
48
|
+
}): Promise<web3.TransactionInstruction>;
|
|
49
|
+
ixRedeemSy({ redeemer, amountSy, baseDst, sySrc, }: {
|
|
50
|
+
redeemer: web3.PublicKey;
|
|
51
|
+
amountSy: string;
|
|
52
|
+
baseDst?: web3.PublicKey;
|
|
53
|
+
sySrc?: web3.PublicKey;
|
|
54
|
+
}): Promise<web3.TransactionInstruction>;
|
|
55
|
+
getSyState(): Promise<web3.TransactionInstruction>;
|
|
56
|
+
ixAddEmission({ signer, emissionMint, emissionTokenAccount, }: {
|
|
57
|
+
signer: web3.PublicKey;
|
|
58
|
+
emissionMint: web3.PublicKey;
|
|
59
|
+
emissionTokenAccount: web3.PublicKey;
|
|
60
|
+
}): Promise<web3.TransactionInstruction>;
|
|
61
|
+
}
|
|
62
|
+
export declare function initSy(signer: web3.PublicKey, perenaStablePool: web3.PublicKey, interfaceAccounts: web3.PublicKey[], lpMint: web3.PublicKey): Promise<web3.TransactionInstruction>;
|
package/build/index.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initSy = exports.PerenaSySdk = exports.MyWallet = void 0;
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
+
const perena_sy_idl_1 = require("@exponent-labs/perena-sy-idl");
|
|
6
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
7
|
+
const perena_sy_pda_1 = require("@exponent-labs/perena-sy-pda");
|
|
8
|
+
const exponent_fetcher_1 = require("@exponent-labs/exponent-fetcher");
|
|
9
|
+
const exponent_admin_pda_1 = require("@exponent-labs/exponent-admin-pda");
|
|
10
|
+
async function loadAccountState(cnx, perenaStablePool, perenaSyProgramId) {
|
|
11
|
+
const pda = new perena_sy_pda_1.PerenaSyPda(perenaSyProgramId);
|
|
12
|
+
const fetcher = new exponent_fetcher_1.ExponentFetcher({ connection: cnx, perenaSyProgramId });
|
|
13
|
+
const syMetaAddress = pda.syMeta({ perenaStablePool });
|
|
14
|
+
const data = await fetcher.fetchPerenaSyMeta(syMetaAddress);
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
class MyWallet {
|
|
18
|
+
payer;
|
|
19
|
+
constructor(payer) {
|
|
20
|
+
this.payer = payer;
|
|
21
|
+
this.payer = payer;
|
|
22
|
+
}
|
|
23
|
+
async signTransaction(tx) {
|
|
24
|
+
if (tx instanceof anchor_1.web3.Transaction) {
|
|
25
|
+
tx.partialSign(this.payer);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
tx.sign([this.payer]);
|
|
29
|
+
}
|
|
30
|
+
return tx;
|
|
31
|
+
}
|
|
32
|
+
async signAllTransactions(txs) {
|
|
33
|
+
return txs.map((t) => {
|
|
34
|
+
if (t instanceof anchor_1.web3.Transaction) {
|
|
35
|
+
t.partialSign(this.payer);
|
|
36
|
+
}
|
|
37
|
+
else if (t instanceof anchor_1.web3.VersionedTransaction) {
|
|
38
|
+
t.sign([this.payer]);
|
|
39
|
+
}
|
|
40
|
+
return t;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
get publicKey() {
|
|
44
|
+
return this.payer.publicKey;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.MyWallet = MyWallet;
|
|
48
|
+
class PerenaSySdk {
|
|
49
|
+
state;
|
|
50
|
+
/** Private program for building instructions */
|
|
51
|
+
program;
|
|
52
|
+
syPda;
|
|
53
|
+
constructor(state, programId = new anchor_1.web3.PublicKey(perena_sy_idl_1.PROGRAM_ID)) {
|
|
54
|
+
this.state = state;
|
|
55
|
+
// create a fake AnchorProvider -- which is unused
|
|
56
|
+
this.program = new anchor_1.Program(perena_sy_idl_1.IDL, new anchor_1.AnchorProvider(new anchor_1.web3.Connection("https://api.devnet.solana.com"), new MyWallet(anchor_1.web3.Keypair.generate())));
|
|
57
|
+
this.syPda = new perena_sy_pda_1.PerenaSyPda(programId);
|
|
58
|
+
}
|
|
59
|
+
/** Load an instance of SyMeta */
|
|
60
|
+
static async load({ cnx, perenaStablePool, perenaSyProgramId, }) {
|
|
61
|
+
const account = await loadAccountState(cnx, perenaStablePool, perenaSyProgramId);
|
|
62
|
+
const b = await (0, exponent_fetcher_1.fetchPerenaStablePoolData)({ connection: cnx, perenaStablePool });
|
|
63
|
+
// const baseMintAi = await cnx.getAccountInfo(b.)
|
|
64
|
+
const tokenProgramBase = spl_token_1.TOKEN_PROGRAM_ID;
|
|
65
|
+
const selfAddress = new perena_sy_pda_1.PerenaSyPda(perenaSyProgramId).syMeta({ perenaStablePool });
|
|
66
|
+
const state = {
|
|
67
|
+
selfAddress,
|
|
68
|
+
account,
|
|
69
|
+
syRate: b.exchangeRate,
|
|
70
|
+
tokenProgramBase,
|
|
71
|
+
lpMint: b.lpMint,
|
|
72
|
+
};
|
|
73
|
+
return new PerenaSySdk(state, perenaSyProgramId);
|
|
74
|
+
}
|
|
75
|
+
/** Reload the state of the account */
|
|
76
|
+
async reload(cnx) {
|
|
77
|
+
const b = await (0, exponent_fetcher_1.fetchPerenaStablePoolData)({
|
|
78
|
+
connection: cnx,
|
|
79
|
+
perenaStablePool: this.state.account.perenaStablePool,
|
|
80
|
+
});
|
|
81
|
+
const account = await loadAccountState(cnx, this.state.account.perenaStablePool, this.program.programId);
|
|
82
|
+
this.state.account = account;
|
|
83
|
+
this.state.syRate = b.exchangeRate;
|
|
84
|
+
}
|
|
85
|
+
get account() {
|
|
86
|
+
return this.state.account;
|
|
87
|
+
}
|
|
88
|
+
get mintSy() {
|
|
89
|
+
return this.account.mintSy;
|
|
90
|
+
}
|
|
91
|
+
get maxSySupply() {
|
|
92
|
+
return this.account.maxSySupply;
|
|
93
|
+
}
|
|
94
|
+
get emissions() {
|
|
95
|
+
return this.account.emissions;
|
|
96
|
+
}
|
|
97
|
+
get minMintSize() {
|
|
98
|
+
return this.account.minMintSize;
|
|
99
|
+
}
|
|
100
|
+
get minRedeemSize() {
|
|
101
|
+
return this.account.minRedeemSize;
|
|
102
|
+
}
|
|
103
|
+
get mintBase() {
|
|
104
|
+
return this.state.lpMint;
|
|
105
|
+
}
|
|
106
|
+
get selfAddress() {
|
|
107
|
+
return this.state.selfAddress;
|
|
108
|
+
}
|
|
109
|
+
get tokenProgramBase() {
|
|
110
|
+
return this.state.tokenProgramBase;
|
|
111
|
+
}
|
|
112
|
+
get tokenLpMintEscrow() {
|
|
113
|
+
return (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintBase, this.selfAddress, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
114
|
+
}
|
|
115
|
+
get tokenSyEscrow() {
|
|
116
|
+
return this.state.account.tokenSyEscrow;
|
|
117
|
+
}
|
|
118
|
+
get adminState() {
|
|
119
|
+
return new exponent_admin_pda_1.ExponentAdminPda(exponent_admin_pda_1.EXPONENT_ADMIN_PROGRAM_ID).exponentAdmin();
|
|
120
|
+
}
|
|
121
|
+
get remainingAccounts() {
|
|
122
|
+
return this.account.interfaceAccounts
|
|
123
|
+
.map((a) => ({
|
|
124
|
+
pubkey: a,
|
|
125
|
+
isSigner: false,
|
|
126
|
+
isWritable: true,
|
|
127
|
+
}))
|
|
128
|
+
.concat(this.emissions.map((e) => ({ pubkey: e.escrowAccount, isSigner: false, isWritable: false })));
|
|
129
|
+
}
|
|
130
|
+
ixMintSy({ depositor, amountBase, baseSrc, syDst, }) {
|
|
131
|
+
console.log("baseSrc mint base", this.mintBase.toBase58());
|
|
132
|
+
baseSrc = baseSrc || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintBase, depositor, true, this.state.tokenProgramBase);
|
|
133
|
+
console.log("baseSrc", baseSrc.toBase58());
|
|
134
|
+
console.log("depositor", depositor.toBase58());
|
|
135
|
+
syDst = syDst || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
136
|
+
console.log("syDst in mint sy", syDst.toBase58());
|
|
137
|
+
console.log("amount base bn ", new anchor_1.BN(amountBase).toString());
|
|
138
|
+
return this.program.methods
|
|
139
|
+
.mint(new anchor_1.BN(amountBase))
|
|
140
|
+
.accountsStrict({
|
|
141
|
+
meta: this.selfAddress,
|
|
142
|
+
perenaStablePool: this.account.perenaStablePool,
|
|
143
|
+
baseTokenProgram: this.tokenProgramBase,
|
|
144
|
+
depositor,
|
|
145
|
+
mintSy: this.mintSy,
|
|
146
|
+
tokenBaseDepositor: baseSrc,
|
|
147
|
+
tokenSyDepositor: syDst,
|
|
148
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
149
|
+
tokenLpMintEscrow: this.tokenLpMintEscrow,
|
|
150
|
+
})
|
|
151
|
+
.remainingAccounts(this.remainingAccounts)
|
|
152
|
+
.instruction();
|
|
153
|
+
}
|
|
154
|
+
ixRedeemSy({ redeemer, amountSy, baseDst, sySrc, }) {
|
|
155
|
+
baseDst = baseDst || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintBase, redeemer, true, this.tokenProgramBase);
|
|
156
|
+
sySrc = sySrc || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, redeemer, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
157
|
+
return this.program.methods
|
|
158
|
+
.redeem(new anchor_1.BN(amountSy))
|
|
159
|
+
.accountsStrict({
|
|
160
|
+
meta: this.selfAddress,
|
|
161
|
+
mintSy: this.mintSy,
|
|
162
|
+
tokenSySigner: sySrc,
|
|
163
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
164
|
+
signer: redeemer,
|
|
165
|
+
perenaStablePool: this.account.perenaStablePool,
|
|
166
|
+
tokenBaseDst: baseDst,
|
|
167
|
+
tokenBaseProgram: this.tokenProgramBase,
|
|
168
|
+
tokenLpMintEscrow: this.tokenLpMintEscrow,
|
|
169
|
+
})
|
|
170
|
+
.remainingAccounts(this.remainingAccounts)
|
|
171
|
+
.instruction();
|
|
172
|
+
}
|
|
173
|
+
getSyState() {
|
|
174
|
+
return this.program.methods
|
|
175
|
+
.getState()
|
|
176
|
+
.accountsStrict({
|
|
177
|
+
meta: this.selfAddress,
|
|
178
|
+
perenaStablePool: this.account.perenaStablePool,
|
|
179
|
+
mintSy: this.mintSy,
|
|
180
|
+
tokenSyEscrow: this.tokenSyEscrow,
|
|
181
|
+
})
|
|
182
|
+
.remainingAccounts(this.remainingAccounts)
|
|
183
|
+
.instruction();
|
|
184
|
+
}
|
|
185
|
+
ixAddEmission({ signer, emissionMint, emissionTokenAccount, }) {
|
|
186
|
+
return this.program.methods
|
|
187
|
+
.addEmission()
|
|
188
|
+
.accountsStrict({
|
|
189
|
+
meta: this.selfAddress,
|
|
190
|
+
signer,
|
|
191
|
+
feePayer: signer,
|
|
192
|
+
tokenEmission: emissionTokenAccount,
|
|
193
|
+
mintEmission: emissionMint,
|
|
194
|
+
systemProgram: anchor_1.web3.SystemProgram.programId,
|
|
195
|
+
adminState: this.adminState,
|
|
196
|
+
})
|
|
197
|
+
.instruction();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
exports.PerenaSySdk = PerenaSySdk;
|
|
201
|
+
function initSy(signer, perenaStablePool, interfaceAccounts, lpMint) {
|
|
202
|
+
const program = new anchor_1.Program(perena_sy_idl_1.IDL, new anchor_1.AnchorProvider(new anchor_1.web3.Connection("https://api.devnet.solana.com"), new MyWallet(anchor_1.web3.Keypair.generate())));
|
|
203
|
+
const pda = new perena_sy_pda_1.PerenaSyPda(program.programId);
|
|
204
|
+
const syMetaAddress = pda.syMeta({ perenaStablePool });
|
|
205
|
+
const mintSy = pda.mintSy({ perenaStablePool });
|
|
206
|
+
console.log("mintSy in sdk", mintSy.toBase58());
|
|
207
|
+
const exponentAdminPda = new exponent_admin_pda_1.ExponentAdminPda(exponent_admin_pda_1.EXPONENT_ADMIN_PROGRAM_ID);
|
|
208
|
+
const metaplexMetadataProgram = new anchor_1.web3.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
|
|
209
|
+
const mintSyMetaplexMetadataPda = anchor_1.web3.PublicKey.findProgramAddressSync([Buffer.from("metadata"), metaplexMetadataProgram.toBuffer(), mintSy.toBuffer()], metaplexMetadataProgram)[0];
|
|
210
|
+
const tokenLpMintEscrow = (0, spl_token_1.getAssociatedTokenAddressSync)(lpMint, syMetaAddress, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
211
|
+
console.log("admin state key", exponentAdminPda.exponentAdmin().toBase58());
|
|
212
|
+
const ix = program.methods
|
|
213
|
+
.initSy(new anchor_1.BN(0), new anchor_1.BN(0), "Exponent Wrapped USD*", "wUSD*", "https://exponent.fi", interfaceAccounts)
|
|
214
|
+
.accountsStrict({
|
|
215
|
+
syMeta: syMetaAddress,
|
|
216
|
+
perenaStablePool,
|
|
217
|
+
mintSy: mintSy,
|
|
218
|
+
adminState: exponentAdminPda.exponentAdmin(),
|
|
219
|
+
admin: signer,
|
|
220
|
+
interfaceProgram: anchor_1.web3.PublicKey.default,
|
|
221
|
+
lpMint,
|
|
222
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
223
|
+
tokenSyEscrow: pda.syEscrow({ perenaStablePool }),
|
|
224
|
+
systemProgram: anchor_1.web3.SystemProgram.programId,
|
|
225
|
+
metadata: mintSyMetaplexMetadataPda,
|
|
226
|
+
tokenMetadataProgram: metaplexMetadataProgram,
|
|
227
|
+
rent: anchor_1.web3.SYSVAR_RENT_PUBKEY,
|
|
228
|
+
tokenLpMintEscrow,
|
|
229
|
+
})
|
|
230
|
+
.instruction();
|
|
231
|
+
return ix;
|
|
232
|
+
}
|
|
233
|
+
exports.initSy = initSy;
|
|
234
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAA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AE,CAAC,CAAA;IAE3E,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO;SACvB,MAAM,CAAC,IAAI,WAAE,CAAC,CAAC,CAAC,EAAE,IAAI,WAAE,CAAC,CAAC,CAAC,EAAE,uBAAuB,EAAE,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,CAAC;SACxG,cAAc,CAAC;QACd,MAAM,EAAE,aAAa;QACrB,gBAAgB;QAChB,MAAM,EAAE,MAAM;QACd,UAAU,EAAE,gBAAgB,CAAC,aAAa,EAAE;QAC5C,KAAK,EAAE,MAAM;QACb,gBAAgB,EAAE,aAAI,CAAC,SAAS,CAAC,OAAO;QACxC,MAAM;QACN,YAAY,EAAE,4BAAgB;QAC9B,aAAa,EAAE,GAAG,CAAC,QAAQ,CAAC,EAAE,gBAAgB,EAAE,CAAC;QACjD,aAAa,EAAE,aAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,QAAQ,EAAE,yBAAyB;QACnC,oBAAoB,EAAE,uBAAuB;QAC7C,IAAI,EAAE,aAAI,CAAC,kBAAkB;QAC7B,iBAAiB;KAClB,CAAC;SACD,WAAW,EAAE,CAAA;IAEhB,OAAO,EAAE,CAAA;AACX,CAAC;AAhDD,wBAgDC"}
|
package/build/tryit.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/build/tryit.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
async function main() {
|
|
6
|
+
const cnx = new anchor_1.web3.Connection("https://api.mainnet-beta.solana.com");
|
|
7
|
+
const perenaStablePool = new anchor_1.web3.PublicKey("Perenastandard111111111111111111111111111111111");
|
|
8
|
+
const perenaSyProgramId = new anchor_1.web3.PublicKey("Perenastandard111111111111111111111111111111111");
|
|
9
|
+
const recentBlockhash = "1";
|
|
10
|
+
const sdk = await _1.PerenaSySdk.load({
|
|
11
|
+
cnx,
|
|
12
|
+
perenaStablePool,
|
|
13
|
+
perenaSyProgramId,
|
|
14
|
+
});
|
|
15
|
+
console.log(sdk);
|
|
16
|
+
}
|
|
17
|
+
main()
|
|
18
|
+
.then(() => console.log("done"))
|
|
19
|
+
.catch((err) => console.error(err));
|
|
20
|
+
//# sourceMappingURL=tryit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tryit.js","sourceRoot":"","sources":["../src/tryit.ts"],"names":[],"mappings":";;AAAA,8CAAwC;AACxC,wBAA+B;AAE/B,KAAK,UAAU,IAAI;IACjB,MAAM,GAAG,GAAG,IAAI,aAAI,CAAC,UAAU,CAAC,qCAAqC,CAAC,CAAA;IACtE,MAAM,gBAAgB,GAAG,IAAI,aAAI,CAAC,SAAS,CAAC,iDAAiD,CAAC,CAAA;IAC9F,MAAM,iBAAiB,GAAG,IAAI,aAAI,CAAC,SAAS,CAAC,iDAAiD,CAAC,CAAA;IAC/F,MAAM,eAAe,GAAG,GAAG,CAAA;IAE3B,MAAM,GAAG,GAAG,MAAM,cAAW,CAAC,IAAI,CAAC;QACjC,GAAG;QACH,gBAAgB;QAChB,iBAAiB;KAClB,CAAC,CAAA;IAEF,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAClB,CAAC;AAED,IAAI,EAAE;KACH,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;KAC/B,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@exponent-labs/perena-sy-sdk",
|
|
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
|
+
"tryit": "ts-node src/tryit.ts"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@coral-xyz/anchor": "^0.30.1",
|
|
13
|
+
"@exponent-labs/exponent-admin-pda": "^0.0.3",
|
|
14
|
+
"@exponent-labs/exponent-fetcher": "^0.0.3",
|
|
15
|
+
"@exponent-labs/exponent-types": "^0.0.3",
|
|
16
|
+
"@exponent-labs/perena-sy-idl": "^0.0.3",
|
|
17
|
+
"@exponent-labs/perena-sy-pda": "^0.0.3",
|
|
18
|
+
"@solana/spl-token": "^0.4.6"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"typescript": "^5.4.5"
|
|
22
|
+
},
|
|
23
|
+
"gitHead": "209b8847e9a0fadb5b5ec96b9b47f0ace4a3bf9d"
|
|
24
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { AnchorProvider, BN, BorshCoder, Program, Wallet, web3 } from "@coral-xyz/anchor"
|
|
2
|
+
import { IDL, PerenaStandard, PROGRAM_ID } from "@exponent-labs/perena-sy-idl"
|
|
3
|
+
import { getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from "@solana/spl-token"
|
|
4
|
+
import { PerenaSyPda } from "@exponent-labs/perena-sy-pda"
|
|
5
|
+
|
|
6
|
+
import { PerenaSyState } from "@exponent-labs/exponent-types"
|
|
7
|
+
import { ExponentFetcher, fetchPerenaStablePoolData } from "@exponent-labs/exponent-fetcher"
|
|
8
|
+
import { EXPONENT_ADMIN_PROGRAM_ID, ExponentAdminPda } from "@exponent-labs/exponent-admin-pda"
|
|
9
|
+
|
|
10
|
+
async function loadAccountState(
|
|
11
|
+
cnx: web3.Connection,
|
|
12
|
+
perenaStablePool: web3.PublicKey,
|
|
13
|
+
perenaSyProgramId: web3.PublicKey,
|
|
14
|
+
) {
|
|
15
|
+
const pda = new PerenaSyPda(perenaSyProgramId)
|
|
16
|
+
const fetcher = new ExponentFetcher({ connection: cnx, perenaSyProgramId })
|
|
17
|
+
const syMetaAddress = pda.syMeta({ perenaStablePool })
|
|
18
|
+
const data = await fetcher.fetchPerenaSyMeta(syMetaAddress)
|
|
19
|
+
return data
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class MyWallet implements Wallet {
|
|
23
|
+
constructor(readonly payer: web3.Keypair) {
|
|
24
|
+
this.payer = payer
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async signTransaction<T extends web3.Transaction | web3.VersionedTransaction>(tx: T): Promise<T> {
|
|
28
|
+
if (tx instanceof web3.Transaction) {
|
|
29
|
+
tx.partialSign(this.payer)
|
|
30
|
+
} else {
|
|
31
|
+
tx.sign([this.payer])
|
|
32
|
+
}
|
|
33
|
+
return tx
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async signAllTransactions<T extends web3.Transaction | web3.VersionedTransaction>(txs: T[]): Promise<T[]> {
|
|
37
|
+
return txs.map((t) => {
|
|
38
|
+
if (t instanceof web3.Transaction) {
|
|
39
|
+
t.partialSign(this.payer)
|
|
40
|
+
} else if (t instanceof web3.VersionedTransaction) {
|
|
41
|
+
t.sign([this.payer])
|
|
42
|
+
}
|
|
43
|
+
return t
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get publicKey(): web3.PublicKey {
|
|
48
|
+
return this.payer.publicKey
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class PerenaSySdk {
|
|
53
|
+
/** Private program for building instructions */
|
|
54
|
+
private program: Program<PerenaStandard>
|
|
55
|
+
|
|
56
|
+
syPda: PerenaSyPda
|
|
57
|
+
|
|
58
|
+
constructor(public state: PerenaSyState, programId: web3.PublicKey = new web3.PublicKey(PROGRAM_ID)) {
|
|
59
|
+
// create a fake AnchorProvider -- which is unused
|
|
60
|
+
this.program = new Program<PerenaStandard>(
|
|
61
|
+
IDL as PerenaStandard,
|
|
62
|
+
new AnchorProvider(new web3.Connection("https://api.devnet.solana.com"), new MyWallet(web3.Keypair.generate())),
|
|
63
|
+
)
|
|
64
|
+
this.syPda = new PerenaSyPda(programId)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Load an instance of SyMeta */
|
|
68
|
+
static async load({
|
|
69
|
+
cnx,
|
|
70
|
+
perenaStablePool,
|
|
71
|
+
perenaSyProgramId,
|
|
72
|
+
}: {
|
|
73
|
+
cnx: web3.Connection
|
|
74
|
+
perenaStablePool: web3.PublicKey
|
|
75
|
+
perenaSyProgramId: web3.PublicKey
|
|
76
|
+
}) {
|
|
77
|
+
const account = await loadAccountState(cnx, perenaStablePool, perenaSyProgramId)
|
|
78
|
+
const b = await fetchPerenaStablePoolData({ connection: cnx, perenaStablePool })
|
|
79
|
+
|
|
80
|
+
// const baseMintAi = await cnx.getAccountInfo(b.)
|
|
81
|
+
const tokenProgramBase = TOKEN_PROGRAM_ID
|
|
82
|
+
const selfAddress = new PerenaSyPda(perenaSyProgramId).syMeta({ perenaStablePool })
|
|
83
|
+
|
|
84
|
+
const state = {
|
|
85
|
+
selfAddress,
|
|
86
|
+
account,
|
|
87
|
+
syRate: b.exchangeRate,
|
|
88
|
+
tokenProgramBase,
|
|
89
|
+
lpMint: b.lpMint,
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return new PerenaSySdk(state, perenaSyProgramId)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Reload the state of the account */
|
|
96
|
+
async reload(cnx: web3.Connection) {
|
|
97
|
+
const b = await fetchPerenaStablePoolData({
|
|
98
|
+
connection: cnx,
|
|
99
|
+
perenaStablePool: this.state.account.perenaStablePool,
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const account = await loadAccountState(cnx, this.state.account.perenaStablePool, this.program.programId)
|
|
103
|
+
this.state.account = account
|
|
104
|
+
this.state.syRate = b.exchangeRate
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
get account() {
|
|
108
|
+
return this.state.account
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
get mintSy() {
|
|
112
|
+
return this.account.mintSy
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
get maxSySupply() {
|
|
116
|
+
return this.account.maxSySupply
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
get emissions() {
|
|
120
|
+
return this.account.emissions
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
get minMintSize() {
|
|
124
|
+
return this.account.minMintSize
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
get minRedeemSize() {
|
|
128
|
+
return this.account.minRedeemSize
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
get mintBase() {
|
|
132
|
+
return this.state.lpMint
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
get selfAddress() {
|
|
136
|
+
return this.state.selfAddress
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
get tokenProgramBase() {
|
|
140
|
+
return this.state.tokenProgramBase
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
get tokenLpMintEscrow() {
|
|
144
|
+
return getAssociatedTokenAddressSync(this.mintBase, this.selfAddress, true, TOKEN_PROGRAM_ID)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
get tokenSyEscrow() {
|
|
148
|
+
return this.state.account.tokenSyEscrow
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
get adminState() {
|
|
152
|
+
return new ExponentAdminPda(EXPONENT_ADMIN_PROGRAM_ID).exponentAdmin()
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
get remainingAccounts() {
|
|
156
|
+
return this.account.interfaceAccounts
|
|
157
|
+
.map((a) => ({
|
|
158
|
+
pubkey: a,
|
|
159
|
+
isSigner: false,
|
|
160
|
+
isWritable: true,
|
|
161
|
+
}))
|
|
162
|
+
.concat(this.emissions.map((e) => ({ pubkey: e.escrowAccount, isSigner: false, isWritable: false })))
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
ixMintSy({
|
|
166
|
+
depositor,
|
|
167
|
+
amountBase,
|
|
168
|
+
baseSrc,
|
|
169
|
+
syDst,
|
|
170
|
+
}: {
|
|
171
|
+
depositor: web3.PublicKey
|
|
172
|
+
amountBase: string
|
|
173
|
+
baseSrc?: web3.PublicKey
|
|
174
|
+
syDst?: web3.PublicKey
|
|
175
|
+
}) {
|
|
176
|
+
console.log("baseSrc mint base", this.mintBase.toBase58())
|
|
177
|
+
baseSrc = baseSrc || getAssociatedTokenAddressSync(this.mintBase, depositor, true, this.state.tokenProgramBase)
|
|
178
|
+
console.log("baseSrc", baseSrc.toBase58())
|
|
179
|
+
console.log("depositor", depositor.toBase58())
|
|
180
|
+
syDst = syDst || getAssociatedTokenAddressSync(this.mintSy, depositor, true, TOKEN_PROGRAM_ID)
|
|
181
|
+
|
|
182
|
+
console.log("syDst in mint sy", syDst.toBase58())
|
|
183
|
+
|
|
184
|
+
console.log("amount base bn ", new BN(amountBase).toString())
|
|
185
|
+
|
|
186
|
+
return this.program.methods
|
|
187
|
+
.mint(new BN(amountBase))
|
|
188
|
+
.accountsStrict({
|
|
189
|
+
meta: this.selfAddress,
|
|
190
|
+
perenaStablePool: this.account.perenaStablePool,
|
|
191
|
+
baseTokenProgram: this.tokenProgramBase,
|
|
192
|
+
depositor,
|
|
193
|
+
mintSy: this.mintSy,
|
|
194
|
+
tokenBaseDepositor: baseSrc,
|
|
195
|
+
tokenSyDepositor: syDst,
|
|
196
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
197
|
+
tokenLpMintEscrow: this.tokenLpMintEscrow,
|
|
198
|
+
})
|
|
199
|
+
.remainingAccounts(this.remainingAccounts)
|
|
200
|
+
.instruction()
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
ixRedeemSy({
|
|
204
|
+
redeemer,
|
|
205
|
+
amountSy,
|
|
206
|
+
baseDst,
|
|
207
|
+
sySrc,
|
|
208
|
+
}: {
|
|
209
|
+
redeemer: web3.PublicKey
|
|
210
|
+
amountSy: string
|
|
211
|
+
baseDst?: web3.PublicKey
|
|
212
|
+
sySrc?: web3.PublicKey
|
|
213
|
+
}) {
|
|
214
|
+
baseDst = baseDst || getAssociatedTokenAddressSync(this.mintBase, redeemer, true, this.tokenProgramBase)
|
|
215
|
+
sySrc = sySrc || getAssociatedTokenAddressSync(this.mintSy, redeemer, true, TOKEN_PROGRAM_ID)
|
|
216
|
+
|
|
217
|
+
return this.program.methods
|
|
218
|
+
.redeem(new BN(amountSy))
|
|
219
|
+
.accountsStrict({
|
|
220
|
+
meta: this.selfAddress,
|
|
221
|
+
mintSy: this.mintSy,
|
|
222
|
+
tokenSySigner: sySrc,
|
|
223
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
224
|
+
signer: redeemer,
|
|
225
|
+
perenaStablePool: this.account.perenaStablePool,
|
|
226
|
+
tokenBaseDst: baseDst,
|
|
227
|
+
tokenBaseProgram: this.tokenProgramBase,
|
|
228
|
+
tokenLpMintEscrow: this.tokenLpMintEscrow,
|
|
229
|
+
})
|
|
230
|
+
.remainingAccounts(this.remainingAccounts)
|
|
231
|
+
.instruction()
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
getSyState() {
|
|
235
|
+
return this.program.methods
|
|
236
|
+
.getState()
|
|
237
|
+
.accountsStrict({
|
|
238
|
+
meta: this.selfAddress,
|
|
239
|
+
perenaStablePool: this.account.perenaStablePool,
|
|
240
|
+
mintSy: this.mintSy,
|
|
241
|
+
tokenSyEscrow: this.tokenSyEscrow,
|
|
242
|
+
})
|
|
243
|
+
.remainingAccounts(this.remainingAccounts)
|
|
244
|
+
.instruction()
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
ixAddEmission({
|
|
248
|
+
signer,
|
|
249
|
+
emissionMint,
|
|
250
|
+
emissionTokenAccount,
|
|
251
|
+
}: {
|
|
252
|
+
signer: web3.PublicKey
|
|
253
|
+
emissionMint: web3.PublicKey
|
|
254
|
+
emissionTokenAccount: web3.PublicKey
|
|
255
|
+
}) {
|
|
256
|
+
return this.program.methods
|
|
257
|
+
.addEmission()
|
|
258
|
+
.accountsStrict({
|
|
259
|
+
meta: this.selfAddress,
|
|
260
|
+
signer,
|
|
261
|
+
feePayer: signer,
|
|
262
|
+
tokenEmission: emissionTokenAccount,
|
|
263
|
+
mintEmission: emissionMint,
|
|
264
|
+
systemProgram: web3.SystemProgram.programId,
|
|
265
|
+
adminState: this.adminState,
|
|
266
|
+
})
|
|
267
|
+
.instruction()
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function initSy(
|
|
272
|
+
signer: web3.PublicKey,
|
|
273
|
+
perenaStablePool: web3.PublicKey,
|
|
274
|
+
interfaceAccounts: web3.PublicKey[],
|
|
275
|
+
lpMint: web3.PublicKey,
|
|
276
|
+
) {
|
|
277
|
+
const program = new Program<PerenaStandard>(
|
|
278
|
+
IDL as PerenaStandard,
|
|
279
|
+
new AnchorProvider(new web3.Connection("https://api.devnet.solana.com"), new MyWallet(web3.Keypair.generate())),
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
const pda = new PerenaSyPda(program.programId)
|
|
283
|
+
const syMetaAddress = pda.syMeta({ perenaStablePool })
|
|
284
|
+
const mintSy = pda.mintSy({ perenaStablePool })
|
|
285
|
+
console.log("mintSy in sdk", mintSy.toBase58())
|
|
286
|
+
const exponentAdminPda = new ExponentAdminPda(EXPONENT_ADMIN_PROGRAM_ID)
|
|
287
|
+
|
|
288
|
+
const metaplexMetadataProgram = new web3.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s")
|
|
289
|
+
const mintSyMetaplexMetadataPda = web3.PublicKey.findProgramAddressSync(
|
|
290
|
+
[Buffer.from("metadata"), metaplexMetadataProgram.toBuffer(), mintSy.toBuffer()],
|
|
291
|
+
metaplexMetadataProgram,
|
|
292
|
+
)[0]
|
|
293
|
+
|
|
294
|
+
const tokenLpMintEscrow = getAssociatedTokenAddressSync(lpMint, syMetaAddress, true, TOKEN_PROGRAM_ID)
|
|
295
|
+
|
|
296
|
+
console.log("admin state key", exponentAdminPda.exponentAdmin().toBase58())
|
|
297
|
+
|
|
298
|
+
const ix = program.methods
|
|
299
|
+
.initSy(new BN(0), new BN(0), "Exponent Wrapped USD*", "wUSD*", "https://exponent.fi", interfaceAccounts)
|
|
300
|
+
.accountsStrict({
|
|
301
|
+
syMeta: syMetaAddress,
|
|
302
|
+
perenaStablePool,
|
|
303
|
+
mintSy: mintSy,
|
|
304
|
+
adminState: exponentAdminPda.exponentAdmin(),
|
|
305
|
+
admin: signer,
|
|
306
|
+
interfaceProgram: web3.PublicKey.default,
|
|
307
|
+
lpMint,
|
|
308
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
309
|
+
tokenSyEscrow: pda.syEscrow({ perenaStablePool }),
|
|
310
|
+
systemProgram: web3.SystemProgram.programId,
|
|
311
|
+
metadata: mintSyMetaplexMetadataPda,
|
|
312
|
+
tokenMetadataProgram: metaplexMetadataProgram,
|
|
313
|
+
rent: web3.SYSVAR_RENT_PUBKEY,
|
|
314
|
+
tokenLpMintEscrow,
|
|
315
|
+
})
|
|
316
|
+
.instruction()
|
|
317
|
+
|
|
318
|
+
return ix
|
|
319
|
+
}
|
package/src/tryit.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { web3 } from "@coral-xyz/anchor"
|
|
2
|
+
import { PerenaSySdk } from "."
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
const cnx = new web3.Connection("https://api.mainnet-beta.solana.com")
|
|
6
|
+
const perenaStablePool = new web3.PublicKey("Perenastandard111111111111111111111111111111111")
|
|
7
|
+
const perenaSyProgramId = new web3.PublicKey("Perenastandard111111111111111111111111111111111")
|
|
8
|
+
const recentBlockhash = "1"
|
|
9
|
+
|
|
10
|
+
const sdk = await PerenaSySdk.load({
|
|
11
|
+
cnx,
|
|
12
|
+
perenaStablePool,
|
|
13
|
+
perenaSyProgramId,
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
console.log(sdk)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
main()
|
|
20
|
+
.then(() => console.log("done"))
|
|
21
|
+
.catch((err) => console.error(err))
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
"resolveJsonModule": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src/**/*.ts", "src/**/*.json"],
|
|
17
|
+
"exclude": ["node_modules", "build"],
|
|
18
|
+
"references": [
|
|
19
|
+
{ "path": "../perena-sy-idl" },
|
|
20
|
+
{ "path": "../exponent-types" },
|
|
21
|
+
{ "path": "../exponent-fetcher" },
|
|
22
|
+
{ "path": "../perena-sy-pda" },
|
|
23
|
+
{ "path": "../exponent-admin-pda" }
|
|
24
|
+
]
|
|
25
|
+
}
|