@ember-finance/sdk 2.37.0 → 2.39.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.
- package/dist/src/api/apis/vaults-api.d.ts +0 -68
- package/dist/src/api/apis/vaults-api.js +1 -143
- package/dist/src/api/models/index.d.ts +0 -2
- package/dist/src/api/models/index.js +0 -2
- package/dist/src/common/constants.d.ts +1 -1
- package/dist/src/ember-vaults.d.ts +76 -4
- package/dist/src/ember-vaults.js +127 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/solana-vaults/index.d.ts +3 -0
- package/dist/src/solana-vaults/index.js +3 -0
- package/dist/src/solana-vaults/interfaces/index.d.ts +260 -0
- package/dist/src/solana-vaults/interfaces/index.js +37 -0
- package/dist/src/solana-vaults/on-chain-calls/index.d.ts +1 -0
- package/dist/src/solana-vaults/on-chain-calls/index.js +1 -0
- package/dist/src/solana-vaults/on-chain-calls/vault-reader.d.ts +190 -0
- package/dist/src/solana-vaults/on-chain-calls/vault-reader.js +432 -0
- package/dist/src/solana-vaults/utils/borsh.d.ts +65 -0
- package/dist/src/solana-vaults/utils/borsh.js +237 -0
- package/dist/src/solana-vaults/utils/deployment-parser.d.ts +94 -0
- package/dist/src/solana-vaults/utils/deployment-parser.js +174 -0
- package/dist/src/solana-vaults/utils/index.d.ts +3 -0
- package/dist/src/solana-vaults/utils/index.js +3 -0
- package/dist/src/solana-vaults/utils/math.d.ts +77 -0
- package/dist/src/solana-vaults/utils/math.js +111 -0
- package/dist/src/solana-vaults/utils/pdas.d.ts +54 -0
- package/dist/src/solana-vaults/utils/pdas.js +93 -0
- package/dist/src/sui-vaults/on-chain-calls/vault.d.ts +0 -35
- package/dist/src/sui-vaults/on-chain-calls/vault.js +0 -25
- package/package.json +10 -4
- package/dist/src/api/models/strategy.d.ts +0 -60
- package/dist/src/api/models/strategy.js +0 -14
- package/dist/src/api/models/update-vault-strategies.d.ts +0 -61
- package/dist/src/api/models/update-vault-strategies.js +0 -14
- package/dist/src/sui-vaults/interfaces/bcs.d.ts +0 -26
- package/dist/src/sui-vaults/interfaces/bcs.js +0 -17
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The program's fixed-point arithmetic, mirrored exactly.
|
|
3
|
+
*
|
|
4
|
+
* Every quote the reader answers locally has an on-chain counterpart in
|
|
5
|
+
* `quote.rs`, and the two must agree to the unit: a preview that rounds the
|
|
6
|
+
* other way sends a user into a transaction the program then rejects. So
|
|
7
|
+
* these are transcribed from `math.rs` rather than reimplemented, including
|
|
8
|
+
* which operations floor and which ceil.
|
|
9
|
+
*
|
|
10
|
+
* `bigint` throughout. The program works in u128 internally and casts back to
|
|
11
|
+
* u64, so doing this in `number` would lose precision above 2^53 — a vault
|
|
12
|
+
* holding more than ~9 million tokens at 9 decimals.
|
|
13
|
+
*/
|
|
14
|
+
/** `math::BASE`: 1.0 in the program's fixed point. */
|
|
15
|
+
export const BASE = 1000000000n;
|
|
16
|
+
const U64_MAX = 18446744073709551615n;
|
|
17
|
+
/** `math::safely_cast_to_u64`. */
|
|
18
|
+
function castToU64(value, op) {
|
|
19
|
+
if (value > U64_MAX) {
|
|
20
|
+
throw new Error(`${op} overflowed a u64: ${value}`);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
/** `math::mul`: `a * b / BASE`, flooring. */
|
|
25
|
+
export function mul(a, b) {
|
|
26
|
+
return castToU64((a * b) / BASE, "mul");
|
|
27
|
+
}
|
|
28
|
+
/** `math::mul_ceil`. */
|
|
29
|
+
export function mulCeil(a, b) {
|
|
30
|
+
return castToU64((a * b + BASE - 1n) / BASE, "mul_ceil");
|
|
31
|
+
}
|
|
32
|
+
/** `math::div`: `a * BASE / b`, flooring. */
|
|
33
|
+
export function div(a, b) {
|
|
34
|
+
if (b <= 0n)
|
|
35
|
+
throw new Error("division by zero");
|
|
36
|
+
return castToU64((a * BASE) / b, "div");
|
|
37
|
+
}
|
|
38
|
+
/** `math::div_ceil`. */
|
|
39
|
+
export function divCeil(a, b) {
|
|
40
|
+
if (b <= 0n)
|
|
41
|
+
throw new Error("division by zero");
|
|
42
|
+
return castToU64((a * BASE + b - 1n) / b, "div_ceil");
|
|
43
|
+
}
|
|
44
|
+
// --- the vault's derived quantities, from state.rs ---------------------------------
|
|
45
|
+
/** `Vault::get_vault_tvl`. */
|
|
46
|
+
export const vaultTvl = (totalShares, rate) => div(totalShares, rate);
|
|
47
|
+
/** `Vault::calculate_shares_from_amount`. */
|
|
48
|
+
export const sharesFromAmount = (amount, rate) => mul(amount, rate);
|
|
49
|
+
/** `Vault::calculate_shares_from_amount_ceil`. */
|
|
50
|
+
export const sharesFromAmountCeil = (amount, rate) => mulCeil(amount, rate);
|
|
51
|
+
/** `Vault::calculate_amount_from_shares_floor`: what settlement actually pays. */
|
|
52
|
+
export const amountFromSharesFloor = (shares, rate) => div(shares, rate);
|
|
53
|
+
/** `Vault::calculate_amount_from_shares`: ceil, what minting costs. */
|
|
54
|
+
export const amountFromShares = (shares, rate) => divCeil(shares, rate);
|
|
55
|
+
/**
|
|
56
|
+
* `Vault::max_mint_shares`: shares still issuable under `maxTvl`.
|
|
57
|
+
*
|
|
58
|
+
* Saturating, not checked: a vault already over its cap (because the cap was
|
|
59
|
+
* lowered, or the rate moved) reports 0 rather than erroring.
|
|
60
|
+
*/
|
|
61
|
+
export function maxMintShares(totalShares, rate, maxTvl) {
|
|
62
|
+
const maxSupply = (maxTvl * rate) / BASE;
|
|
63
|
+
const capped = maxSupply > U64_MAX ? U64_MAX : maxSupply;
|
|
64
|
+
return capped > totalShares ? capped - totalShares : 0n;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* `Vault::max_deposit_amount`: collateral still depositable under `maxTvl`.
|
|
68
|
+
*
|
|
69
|
+
* The `+1 ... -1` is the program's, not a transcription slip: it is the
|
|
70
|
+
* largest amount whose floored share conversion still fits the headroom, so
|
|
71
|
+
* depositing exactly this much lands on the cap rather than one unit over.
|
|
72
|
+
*/
|
|
73
|
+
export function maxDepositAmount(totalShares, rate, maxTvl) {
|
|
74
|
+
if (rate <= 0n)
|
|
75
|
+
throw new Error("division by zero");
|
|
76
|
+
const headroom = maxMintShares(totalShares, rate, maxTvl);
|
|
77
|
+
if (headroom === 0n)
|
|
78
|
+
return 0n;
|
|
79
|
+
const maxAmount = ((headroom + 1n) * BASE - 1n) / rate;
|
|
80
|
+
return maxAmount > U64_MAX ? U64_MAX : maxAmount;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The fee settlement deducts, for one holder redeeming `gross`.
|
|
84
|
+
*
|
|
85
|
+
* Both fees are taken off the gross amount and stay in the vault, so they
|
|
86
|
+
* accrue to the remaining holders rather than leaving. A fee-exempt owner
|
|
87
|
+
* pays neither.
|
|
88
|
+
*
|
|
89
|
+
* The time-based fee is charged while the holder is still *inside*
|
|
90
|
+
* `threshold` of their last deposit — it penalises leaving early, so it
|
|
91
|
+
* applies to recent depositors, not long-standing ones. A holder with no
|
|
92
|
+
* recorded deposit at all (`lastDepositTs === 0`, which is how shares received
|
|
93
|
+
* by transfer look) is treated as inside the window and pays it.
|
|
94
|
+
*/
|
|
95
|
+
export function withdrawalFee(gross, fee, options) {
|
|
96
|
+
if (options.exempt) {
|
|
97
|
+
return { permanent: 0n, timeBased: 0n, net: gross };
|
|
98
|
+
}
|
|
99
|
+
const permanent = fee.permanentFeePercentage > 0n ? mul(gross, fee.permanentFeePercentage) : 0n;
|
|
100
|
+
let timeBased = 0n;
|
|
101
|
+
if (fee.timeBasedFeePercentage > 0n && fee.timeBasedFeeThreshold > 0n) {
|
|
102
|
+
// Written as the program writes it, to avoid overflowing
|
|
103
|
+
// lastDepositTs + threshold.
|
|
104
|
+
const inWindow = options.lastDepositTs === 0n ||
|
|
105
|
+
options.nowMs < options.lastDepositTs ||
|
|
106
|
+
fee.timeBasedFeeThreshold > options.nowMs - options.lastDepositTs;
|
|
107
|
+
if (inWindow)
|
|
108
|
+
timeBased = mul(gross, fee.timeBasedFeePercentage);
|
|
109
|
+
}
|
|
110
|
+
return { permanent, timeBased, net: gross - permanent - timeBased };
|
|
111
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { type ISolanaVaultPdas } from "../interfaces/index.js";
|
|
3
|
+
/** Little-endian u64, for the nonce and sequence-number seeds. */
|
|
4
|
+
export declare function u64le(v: bigint | number): Buffer;
|
|
5
|
+
/** The protocol-wide config. One per program id, and it can never be closed. */
|
|
6
|
+
export declare const deriveProtocolConfig: (programId: PublicKey) => PublicKey;
|
|
7
|
+
/**
|
|
8
|
+
* The vault PDA and the three accounts hanging off it.
|
|
9
|
+
*
|
|
10
|
+
* `["vault", share_mint]` is the only seed pair, which is what makes the share
|
|
11
|
+
* mint the vault's identity: one mint is one vault, enforced on chain because
|
|
12
|
+
* a second `create_vault` on the same mint hits an already-initialised
|
|
13
|
+
* account.
|
|
14
|
+
*/
|
|
15
|
+
export declare function deriveVaultPdas(programId: PublicKey, shareMint: PublicKey): ISolanaVaultPdas;
|
|
16
|
+
/** An owner's per-vault account: their deposit clock and pending requests. */
|
|
17
|
+
export declare const deriveVaultAccount: (programId: PublicKey, vault: PublicKey, owner: PublicKey) => PublicKey;
|
|
18
|
+
/**
|
|
19
|
+
* A withdrawal request's account.
|
|
20
|
+
*
|
|
21
|
+
* Seeded by the owner's `next_request_nonce` *at the time of the request*, so
|
|
22
|
+
* a caller must read the owner's `VaultAccount` first. A fresh owner starts at
|
|
23
|
+
* nonce 0.
|
|
24
|
+
*/
|
|
25
|
+
export declare const deriveWithdrawalRequest: (programId: PublicKey, vault: PublicKey, owner: PublicKey, nonce: bigint) => PublicKey;
|
|
26
|
+
/**
|
|
27
|
+
* The event authority `emit_cpi!` signs with. Anchor requires it and the
|
|
28
|
+
* program id as the last two accounts of every instruction that emits.
|
|
29
|
+
*/
|
|
30
|
+
export declare const deriveEventAuthority: (programId: PublicKey) => PublicKey;
|
|
31
|
+
/** Those last two accounts, ready to append to an instruction's keys. */
|
|
32
|
+
export declare const eventCpiAccounts: (programId: PublicKey) => {
|
|
33
|
+
pubkey: PublicKey;
|
|
34
|
+
isSigner: boolean;
|
|
35
|
+
isWritable: boolean;
|
|
36
|
+
}[];
|
|
37
|
+
/** `sha256("global:<name>")[..8]`, the first eight bytes of an instruction. */
|
|
38
|
+
export declare const instructionDiscriminator: (name: string) => Buffer;
|
|
39
|
+
/** `sha256("account:<Name>")[..8]`, the first eight bytes of an account. */
|
|
40
|
+
export declare const accountDiscriminator: (name: string) => Buffer;
|
|
41
|
+
export declare const TOKEN_PROGRAM_ID: PublicKey;
|
|
42
|
+
export declare const TOKEN_2022_PROGRAM_ID: PublicKey;
|
|
43
|
+
export declare const ASSOCIATED_TOKEN_PROGRAM_ID: PublicKey;
|
|
44
|
+
export declare const TOKEN_METADATA_PROGRAM_ID: PublicKey;
|
|
45
|
+
/**
|
|
46
|
+
* An associated token account.
|
|
47
|
+
*
|
|
48
|
+
* `tokenProgram` matters: the same owner and mint give different addresses
|
|
49
|
+
* under SPL Token and Token-2022, and a vault's collateral and share mints may
|
|
50
|
+
* live under different programs.
|
|
51
|
+
*/
|
|
52
|
+
export declare const associatedTokenAddress: (owner: PublicKey, mint: PublicKey, tokenProgram?: PublicKey) => PublicKey;
|
|
53
|
+
/** The Metaplex metadata account carrying a mint's name and symbol. */
|
|
54
|
+
export declare const metadataAddress: (mint: PublicKey) => PublicKey;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
// Not node:crypto. This module is reachable from the SDK root through
|
|
3
|
+
// EmberVaults, so a Node-only import would break browser builds for every
|
|
4
|
+
// consumer, Sui and EVM included - not just Solana ones.
|
|
5
|
+
import { sha256 } from "@noble/hashes/sha2";
|
|
6
|
+
import { SOLANA_SEEDS } from "../interfaces/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* PDA derivation for `ember_vaults`.
|
|
9
|
+
*
|
|
10
|
+
* Every address below is a pure function of the program id and, where it
|
|
11
|
+
* applies, the share mint. Nothing here touches the network, and the results
|
|
12
|
+
* are stable across redeploys: upgrading a program leaves its id unchanged,
|
|
13
|
+
* so its PDAs and the accounts at them survive. Only a new program id moves
|
|
14
|
+
* them.
|
|
15
|
+
*/
|
|
16
|
+
const seed = (s) => Buffer.from(s, "utf8");
|
|
17
|
+
/** Little-endian u64, for the nonce and sequence-number seeds. */
|
|
18
|
+
export function u64le(v) {
|
|
19
|
+
const b = Buffer.alloc(8);
|
|
20
|
+
b.writeBigUInt64LE(BigInt(v));
|
|
21
|
+
return b;
|
|
22
|
+
}
|
|
23
|
+
/** The protocol-wide config. One per program id, and it can never be closed. */
|
|
24
|
+
export const deriveProtocolConfig = (programId) => PublicKey.findProgramAddressSync([seed(SOLANA_SEEDS.protocolConfig)], programId)[0];
|
|
25
|
+
/**
|
|
26
|
+
* The vault PDA and the three accounts hanging off it.
|
|
27
|
+
*
|
|
28
|
+
* `["vault", share_mint]` is the only seed pair, which is what makes the share
|
|
29
|
+
* mint the vault's identity: one mint is one vault, enforced on chain because
|
|
30
|
+
* a second `create_vault` on the same mint hits an already-initialised
|
|
31
|
+
* account.
|
|
32
|
+
*/
|
|
33
|
+
export function deriveVaultPdas(programId, shareMint) {
|
|
34
|
+
const pda = (...seeds) => PublicKey.findProgramAddressSync(seeds, programId)[0];
|
|
35
|
+
const vault = pda(seed(SOLANA_SEEDS.vault), shareMint.toBuffer());
|
|
36
|
+
return {
|
|
37
|
+
vault,
|
|
38
|
+
vaultCollateral: pda(seed(SOLANA_SEEDS.vaultCollateral), vault.toBuffer()),
|
|
39
|
+
vaultPendingShares: pda(seed(SOLANA_SEEDS.vaultPendingShares), vault.toBuffer()),
|
|
40
|
+
withdrawalQueue: pda(seed(SOLANA_SEEDS.withdrawalQueue), vault.toBuffer())
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** An owner's per-vault account: their deposit clock and pending requests. */
|
|
44
|
+
export const deriveVaultAccount = (programId, vault, owner) => PublicKey.findProgramAddressSync([seed(SOLANA_SEEDS.account), vault.toBuffer(), owner.toBuffer()], programId)[0];
|
|
45
|
+
/**
|
|
46
|
+
* A withdrawal request's account.
|
|
47
|
+
*
|
|
48
|
+
* Seeded by the owner's `next_request_nonce` *at the time of the request*, so
|
|
49
|
+
* a caller must read the owner's `VaultAccount` first. A fresh owner starts at
|
|
50
|
+
* nonce 0.
|
|
51
|
+
*/
|
|
52
|
+
export const deriveWithdrawalRequest = (programId, vault, owner, nonce) => PublicKey.findProgramAddressSync([
|
|
53
|
+
seed(SOLANA_SEEDS.withdrawalRequest),
|
|
54
|
+
vault.toBuffer(),
|
|
55
|
+
owner.toBuffer(),
|
|
56
|
+
u64le(nonce)
|
|
57
|
+
], programId)[0];
|
|
58
|
+
// The parking lot's PDAs - the lot, its escrow and a deposit request - are
|
|
59
|
+
// derived in the phase that adds decoders for DepositParkingLot and
|
|
60
|
+
// DepositRequest. Deriving an address nothing can read is a surface that
|
|
61
|
+
// looks usable and is not. Note for then: a request's seed is the lot's
|
|
62
|
+
// sequence_number + 1, the slot the next park will take.
|
|
63
|
+
/**
|
|
64
|
+
* The event authority `emit_cpi!` signs with. Anchor requires it and the
|
|
65
|
+
* program id as the last two accounts of every instruction that emits.
|
|
66
|
+
*/
|
|
67
|
+
export const deriveEventAuthority = (programId) => PublicKey.findProgramAddressSync([seed("__event_authority")], programId)[0];
|
|
68
|
+
/** Those last two accounts, ready to append to an instruction's keys. */
|
|
69
|
+
export const eventCpiAccounts = (programId) => [
|
|
70
|
+
{ pubkey: deriveEventAuthority(programId), isSigner: false, isWritable: false },
|
|
71
|
+
{ pubkey: programId, isSigner: false, isWritable: false }
|
|
72
|
+
];
|
|
73
|
+
// --- Anchor discriminators --------------------------------------------------------
|
|
74
|
+
const digest8 = (preimage) => Buffer.from(sha256(new TextEncoder().encode(preimage))).subarray(0, 8);
|
|
75
|
+
/** `sha256("global:<name>")[..8]`, the first eight bytes of an instruction. */
|
|
76
|
+
export const instructionDiscriminator = (name) => digest8(`global:${name}`);
|
|
77
|
+
/** `sha256("account:<Name>")[..8]`, the first eight bytes of an account. */
|
|
78
|
+
export const accountDiscriminator = (name) => digest8(`account:${name}`);
|
|
79
|
+
// --- SPL addresses ----------------------------------------------------------------
|
|
80
|
+
export const TOKEN_PROGRAM_ID = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
|
|
81
|
+
export const TOKEN_2022_PROGRAM_ID = new PublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
|
|
82
|
+
export const ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
|
|
83
|
+
export const TOKEN_METADATA_PROGRAM_ID = new PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
|
|
84
|
+
/**
|
|
85
|
+
* An associated token account.
|
|
86
|
+
*
|
|
87
|
+
* `tokenProgram` matters: the same owner and mint give different addresses
|
|
88
|
+
* under SPL Token and Token-2022, and a vault's collateral and share mints may
|
|
89
|
+
* live under different programs.
|
|
90
|
+
*/
|
|
91
|
+
export const associatedTokenAddress = (owner, mint, tokenProgram = TOKEN_PROGRAM_ID) => PublicKey.findProgramAddressSync([owner.toBuffer(), tokenProgram.toBuffer(), mint.toBuffer()], ASSOCIATED_TOKEN_PROGRAM_ID)[0];
|
|
92
|
+
/** The Metaplex metadata account carrying a mint's name and symbol. */
|
|
93
|
+
export const metadataAddress = (mint) => PublicKey.findProgramAddressSync([Buffer.from("metadata"), TOKEN_METADATA_PROGRAM_ID.toBuffer(), mint.toBuffer()], TOKEN_METADATA_PROGRAM_ID)[0];
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BaseClient as SuiClient } from "@mysten/sui/client";
|
|
2
|
-
import { Signer } from "@firefly-exchange/library-sui";
|
|
3
2
|
import { IVault, IVaultAccount } from "../interfaces/index.js";
|
|
4
3
|
export declare class Vault {
|
|
5
4
|
/**
|
|
@@ -11,38 +10,4 @@ export declare class Vault {
|
|
|
11
10
|
static getVaultRate(suiClient: SuiClient, vaultId: string): Promise<number>;
|
|
12
11
|
static getVault(suiClient: SuiClient, vaultId: string): Promise<IVault>;
|
|
13
12
|
static getPendingWithdrawalRequests(suiClient: SuiClient, vaultId: string, walletAddress: string): Promise<IVaultAccount>;
|
|
14
|
-
static signUpdateVaultStrategyRequest(payload: {
|
|
15
|
-
vaultId: string;
|
|
16
|
-
strategies: {
|
|
17
|
-
platformName: string;
|
|
18
|
-
strategistAddress: string;
|
|
19
|
-
strategyType: string;
|
|
20
|
-
allocationE9: string;
|
|
21
|
-
apyE9: string;
|
|
22
|
-
pointsApyE9: string;
|
|
23
|
-
snapshotAt: number;
|
|
24
|
-
}[];
|
|
25
|
-
targetApyE9: string;
|
|
26
|
-
supplyApyE9: string;
|
|
27
|
-
reportedApyE9: string;
|
|
28
|
-
}, signer: Signer): Promise<{
|
|
29
|
-
bcsPayload: string;
|
|
30
|
-
requestBody: {
|
|
31
|
-
vaultId: string;
|
|
32
|
-
strategies: {
|
|
33
|
-
platformName: string;
|
|
34
|
-
strategistAddress: string;
|
|
35
|
-
strategyType: string;
|
|
36
|
-
allocationE9: string;
|
|
37
|
-
apyE9: string;
|
|
38
|
-
pointsApyE9: string;
|
|
39
|
-
snapshotAt: number;
|
|
40
|
-
}[];
|
|
41
|
-
targetApyE9: string;
|
|
42
|
-
supplyApyE9: string;
|
|
43
|
-
reportedApyE9: string;
|
|
44
|
-
signedAt: number;
|
|
45
|
-
signature: string;
|
|
46
|
-
};
|
|
47
|
-
}>;
|
|
48
13
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { bcs } from "@mysten/sui/bcs";
|
|
2
|
-
import { BcsUpdateVaultStrategyRequest } from "../interfaces/bcs.js";
|
|
3
2
|
import { tableIdOf, unwrapMoveFields } from "../utils/common.js";
|
|
4
3
|
export class Vault {
|
|
5
4
|
/**
|
|
@@ -101,28 +100,4 @@ export class Vault {
|
|
|
101
100
|
};
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
|
-
static async signUpdateVaultStrategyRequest(payload, signer) {
|
|
105
|
-
const now = Date.now();
|
|
106
|
-
const bcsPayload = BcsUpdateVaultStrategyRequest.serialize({
|
|
107
|
-
vaultId: payload.vaultId,
|
|
108
|
-
strategies: payload.strategies,
|
|
109
|
-
targetApyE9: payload.targetApyE9,
|
|
110
|
-
supplyApyE9: payload.supplyApyE9,
|
|
111
|
-
reportedApyE9: payload.reportedApyE9,
|
|
112
|
-
signedAt: now
|
|
113
|
-
}).toBytes();
|
|
114
|
-
const { signature, bytes } = await signer.signPersonalMessage(bcsPayload);
|
|
115
|
-
return {
|
|
116
|
-
bcsPayload: bytes,
|
|
117
|
-
requestBody: {
|
|
118
|
-
vaultId: payload.vaultId,
|
|
119
|
-
strategies: payload.strategies,
|
|
120
|
-
signedAt: now,
|
|
121
|
-
targetApyE9: payload.targetApyE9,
|
|
122
|
-
supplyApyE9: payload.supplyApyE9,
|
|
123
|
-
reportedApyE9: payload.reportedApyE9,
|
|
124
|
-
signature: signature
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
103
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-finance/sdk",
|
|
3
3
|
"description": "Ember Protocol SDK",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.39.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -85,15 +85,16 @@
|
|
|
85
85
|
"dependencies": {
|
|
86
86
|
"@aws-sdk/client-kms": "^3.1044.0",
|
|
87
87
|
"@noble/curves": "^2.2.0",
|
|
88
|
+
"@noble/hashes": "^1.8.0",
|
|
88
89
|
"asn1.js": "^5.4.1",
|
|
89
90
|
"axios": "1.13.6",
|
|
90
91
|
"yarn": "^1.22.19"
|
|
91
92
|
},
|
|
92
93
|
"devDependencies": {
|
|
93
94
|
"@firefly-exchange/library-sui": "^3.0.0",
|
|
94
|
-
"@mysten/bcs": "^2.0.3",
|
|
95
95
|
"@mysten/sui": "^2.0.0",
|
|
96
96
|
"@openapitools/openapi-generator-cli": "^2.41.0",
|
|
97
|
+
"@solana/web3.js": "^1.95.0",
|
|
97
98
|
"@types/chai": "^4.3.3",
|
|
98
99
|
"@types/chai-as-promised": "^7.1.5",
|
|
99
100
|
"@types/dotenv-parse-variables": "^2.0.1",
|
|
@@ -118,8 +119,8 @@
|
|
|
118
119
|
},
|
|
119
120
|
"peerDependencies": {
|
|
120
121
|
"@firefly-exchange/library-sui": "^3.0.0",
|
|
121
|
-
"@mysten/bcs": "^2.0.3",
|
|
122
122
|
"@mysten/sui": "^2.0.0",
|
|
123
|
+
"@solana/web3.js": "^1.95.0",
|
|
123
124
|
"ethers": "^6.13.4"
|
|
124
125
|
},
|
|
125
126
|
"repository": {
|
|
@@ -145,5 +146,10 @@
|
|
|
145
146
|
"shell-quote": "^1.10.0",
|
|
146
147
|
"tar": "^7.5.19"
|
|
147
148
|
},
|
|
148
|
-
"packageManager": "yarn@4.14.1"
|
|
149
|
+
"packageManager": "yarn@4.14.1",
|
|
150
|
+
"peerDependenciesMeta": {
|
|
151
|
+
"@solana/web3.js": {
|
|
152
|
+
"optional": true
|
|
153
|
+
}
|
|
154
|
+
}
|
|
149
155
|
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ember Protocol Vaults API
|
|
3
|
-
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
4
|
-
*
|
|
5
|
-
* The version of the OpenAPI document: 1.0.0
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
9
|
-
* https://openapi-generator.tech
|
|
10
|
-
* Do not edit the class manually.
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @export
|
|
15
|
-
* @interface Strategy
|
|
16
|
-
*/
|
|
17
|
-
export interface Strategy {
|
|
18
|
-
/**
|
|
19
|
-
* The name of the platform
|
|
20
|
-
* @type {string}
|
|
21
|
-
* @memberof Strategy
|
|
22
|
-
*/
|
|
23
|
-
platformName: string;
|
|
24
|
-
/**
|
|
25
|
-
* The address of the strategist
|
|
26
|
-
* @type {string}
|
|
27
|
-
* @memberof Strategy
|
|
28
|
-
*/
|
|
29
|
-
strategistAddress: string;
|
|
30
|
-
/**
|
|
31
|
-
* The type of the strategy
|
|
32
|
-
* @type {string}
|
|
33
|
-
* @memberof Strategy
|
|
34
|
-
*/
|
|
35
|
-
strategyType: string;
|
|
36
|
-
/**
|
|
37
|
-
* The allocation of the strategy
|
|
38
|
-
* @type {string}
|
|
39
|
-
* @memberof Strategy
|
|
40
|
-
*/
|
|
41
|
-
allocationE9: string;
|
|
42
|
-
/**
|
|
43
|
-
* The apy of the strategy
|
|
44
|
-
* @type {string}
|
|
45
|
-
* @memberof Strategy
|
|
46
|
-
*/
|
|
47
|
-
apyE9: string;
|
|
48
|
-
/**
|
|
49
|
-
* The points apy of the strategy
|
|
50
|
-
* @type {string}
|
|
51
|
-
* @memberof Strategy
|
|
52
|
-
*/
|
|
53
|
-
pointsApyE9: string;
|
|
54
|
-
/**
|
|
55
|
-
* The timestamp of the snapshot
|
|
56
|
-
* @type {number}
|
|
57
|
-
* @memberof Strategy
|
|
58
|
-
*/
|
|
59
|
-
snapshotAt: number;
|
|
60
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
/**
|
|
4
|
-
* Ember Protocol Vaults API
|
|
5
|
-
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
6
|
-
*
|
|
7
|
-
* The version of the OpenAPI document: 1.0.0
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
-
* https://openapi-generator.tech
|
|
12
|
-
* Do not edit the class manually.
|
|
13
|
-
*/
|
|
14
|
-
export {};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ember Protocol Vaults API
|
|
3
|
-
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
4
|
-
*
|
|
5
|
-
* The version of the OpenAPI document: 1.0.0
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
9
|
-
* https://openapi-generator.tech
|
|
10
|
-
* Do not edit the class manually.
|
|
11
|
-
*/
|
|
12
|
-
import type { Strategy } from "./strategy.js";
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @export
|
|
16
|
-
* @interface UpdateVaultStrategies
|
|
17
|
-
*/
|
|
18
|
-
export interface UpdateVaultStrategies {
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* @type {Array<Strategy>}
|
|
22
|
-
* @memberof UpdateVaultStrategies
|
|
23
|
-
*/
|
|
24
|
-
strategies: Array<Strategy>;
|
|
25
|
-
/**
|
|
26
|
-
* The timestamp of the signature
|
|
27
|
-
* @type {number}
|
|
28
|
-
* @memberof UpdateVaultStrategies
|
|
29
|
-
*/
|
|
30
|
-
signedAt: number;
|
|
31
|
-
/**
|
|
32
|
-
* The id of the vault
|
|
33
|
-
* @type {string}
|
|
34
|
-
* @memberof UpdateVaultStrategies
|
|
35
|
-
*/
|
|
36
|
-
vaultId: string;
|
|
37
|
-
/**
|
|
38
|
-
* The target apy of the strategy
|
|
39
|
-
* @type {string}
|
|
40
|
-
* @memberof UpdateVaultStrategies
|
|
41
|
-
*/
|
|
42
|
-
targetApyE9: string;
|
|
43
|
-
/**
|
|
44
|
-
* The supply apy of the strategy
|
|
45
|
-
* @type {string}
|
|
46
|
-
* @memberof UpdateVaultStrategies
|
|
47
|
-
*/
|
|
48
|
-
supplyApyE9: string;
|
|
49
|
-
/**
|
|
50
|
-
* The reported apy of the strategy
|
|
51
|
-
* @type {string}
|
|
52
|
-
* @memberof UpdateVaultStrategies
|
|
53
|
-
*/
|
|
54
|
-
reportedApyE9: string;
|
|
55
|
-
/**
|
|
56
|
-
* The signature of the request body
|
|
57
|
-
* @type {string}
|
|
58
|
-
* @memberof UpdateVaultStrategies
|
|
59
|
-
*/
|
|
60
|
-
signature: string;
|
|
61
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
/**
|
|
4
|
-
* Ember Protocol Vaults API
|
|
5
|
-
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
6
|
-
*
|
|
7
|
-
* The version of the OpenAPI document: 1.0.0
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
-
* https://openapi-generator.tech
|
|
12
|
-
* Do not edit the class manually.
|
|
13
|
-
*/
|
|
14
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export declare const BcsUpdateVaultStrategyRequest: import("@mysten/bcs").BcsStruct<{
|
|
2
|
-
vaultId: import("@mysten/bcs").BcsType<string, string, "string">;
|
|
3
|
-
strategies: import("@mysten/bcs").BcsType<{
|
|
4
|
-
platformName: string;
|
|
5
|
-
strategistAddress: string;
|
|
6
|
-
strategyType: string;
|
|
7
|
-
allocationE9: string;
|
|
8
|
-
apyE9: string;
|
|
9
|
-
pointsApyE9: string;
|
|
10
|
-
snapshotAt: string;
|
|
11
|
-
}[], Iterable<{
|
|
12
|
-
platformName: string;
|
|
13
|
-
strategistAddress: string;
|
|
14
|
-
strategyType: string;
|
|
15
|
-
allocationE9: string;
|
|
16
|
-
apyE9: string;
|
|
17
|
-
pointsApyE9: string;
|
|
18
|
-
snapshotAt: string | number | bigint;
|
|
19
|
-
}> & {
|
|
20
|
-
length: number;
|
|
21
|
-
}, string>;
|
|
22
|
-
targetApyE9: import("@mysten/bcs").BcsType<string, string, "string">;
|
|
23
|
-
supplyApyE9: import("@mysten/bcs").BcsType<string, string, "string">;
|
|
24
|
-
reportedApyE9: import("@mysten/bcs").BcsType<string, string, "string">;
|
|
25
|
-
signedAt: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
26
|
-
}, string>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { bcs } from "@mysten/bcs";
|
|
2
|
-
export const BcsUpdateVaultStrategyRequest = bcs.struct("UpdateVaultStrategyRequest", {
|
|
3
|
-
vaultId: bcs.string(),
|
|
4
|
-
strategies: bcs.vector(bcs.struct("Strategy", {
|
|
5
|
-
platformName: bcs.string(),
|
|
6
|
-
strategistAddress: bcs.string(),
|
|
7
|
-
strategyType: bcs.string(),
|
|
8
|
-
allocationE9: bcs.string(),
|
|
9
|
-
apyE9: bcs.string(),
|
|
10
|
-
pointsApyE9: bcs.string(),
|
|
11
|
-
snapshotAt: bcs.u64()
|
|
12
|
-
})),
|
|
13
|
-
targetApyE9: bcs.string(),
|
|
14
|
-
supplyApyE9: bcs.string(),
|
|
15
|
-
reportedApyE9: bcs.string(),
|
|
16
|
-
signedAt: bcs.u64()
|
|
17
|
-
});
|