@ember-finance/sdk 2.0.0-beta.1 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -217,6 +217,12 @@ export interface VaultDetail {
|
|
|
217
217
|
* @memberof VaultDetail
|
|
218
218
|
*/
|
|
219
219
|
isPrivate: boolean;
|
|
220
|
+
/**
|
|
221
|
+
* The redemption price of the vault in e9 form
|
|
222
|
+
* @type {string}
|
|
223
|
+
* @memberof VaultDetail
|
|
224
|
+
*/
|
|
225
|
+
redemptionPriceE9?: string;
|
|
220
226
|
}
|
|
221
227
|
export declare const VaultDetailStatusEnum: {
|
|
222
228
|
readonly Active: "active";
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
1
2
|
import { BcsUpdateVaultStrategyRequest } from "../interfaces/bcs.js";
|
|
3
|
+
const unwrapMoveFields = (value) => value?.fields ?? value;
|
|
2
4
|
export class Vault {
|
|
3
5
|
/**
|
|
4
6
|
* Fetches the vault rate from on-chain
|
|
@@ -7,26 +9,31 @@ export class Vault {
|
|
|
7
9
|
* @returns The vault rate
|
|
8
10
|
*/
|
|
9
11
|
static async getVaultRate(suiClient, vaultId) {
|
|
10
|
-
const response = await suiClient.getObject({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const response = await suiClient.core.getObject({
|
|
13
|
+
objectId: vaultId,
|
|
14
|
+
include: {
|
|
15
|
+
json: true
|
|
14
16
|
}
|
|
15
17
|
});
|
|
16
|
-
|
|
18
|
+
const fields = unwrapMoveFields(response.object?.json);
|
|
19
|
+
const rate = unwrapMoveFields(fields?.rate);
|
|
20
|
+
return rate?.value !== undefined ? Number(rate.value) : undefined;
|
|
17
21
|
}
|
|
18
22
|
static async getVault(suiClient, vaultId) {
|
|
19
|
-
const response = await suiClient.getObject({
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
const response = await suiClient.core.getObject({
|
|
24
|
+
objectId: vaultId,
|
|
25
|
+
include: { json: true }
|
|
22
26
|
});
|
|
23
27
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
-
const fields = response.
|
|
28
|
+
const fields = unwrapMoveFields(response.object?.json);
|
|
25
29
|
if (!fields) {
|
|
26
30
|
throw new Error("Vault not found or invalid response");
|
|
27
31
|
}
|
|
32
|
+
const fee = unwrapMoveFields(fields.fee);
|
|
33
|
+
const rate = unwrapMoveFields(fields.rate);
|
|
34
|
+
const vaultIdField = unwrapMoveFields(fields.id);
|
|
28
35
|
return {
|
|
29
|
-
id: fields.id
|
|
36
|
+
id: vaultIdField?.id || fields.id || vaultId,
|
|
30
37
|
name: fields.name || "",
|
|
31
38
|
admin: fields.admin,
|
|
32
39
|
operator: fields.operator,
|
|
@@ -40,35 +47,43 @@ export class Vault {
|
|
|
40
47
|
sub_accounts: fields.sub_accounts || [],
|
|
41
48
|
blacklisted: fields.blacklisted || [],
|
|
42
49
|
fee: {
|
|
43
|
-
accrued:
|
|
44
|
-
last_charged_at:
|
|
50
|
+
accrued: fee?.accrued || "0",
|
|
51
|
+
last_charged_at: fee?.last_charged_at || "0"
|
|
45
52
|
},
|
|
46
53
|
rate: {
|
|
47
|
-
last_updated_at:
|
|
48
|
-
max_rate_change_per_update:
|
|
49
|
-
rate_update_interval:
|
|
50
|
-
value:
|
|
54
|
+
last_updated_at: rate?.last_updated_at || "0",
|
|
55
|
+
max_rate_change_per_update: rate?.max_rate_change_per_update || "0",
|
|
56
|
+
rate_update_interval: rate?.rate_update_interval || "0",
|
|
57
|
+
value: rate?.value || "0"
|
|
51
58
|
}
|
|
52
59
|
};
|
|
53
60
|
}
|
|
54
61
|
static async getPendingWithdrawalRequests(suiClient, vaultId, walletAddress) {
|
|
55
|
-
const objDetails = await suiClient.getObject({
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
const objDetails = await suiClient.core.getObject({
|
|
63
|
+
objectId: vaultId,
|
|
64
|
+
include: { json: true }
|
|
58
65
|
});
|
|
59
66
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
-
const
|
|
67
|
+
const fields = unwrapMoveFields(objDetails.object?.json);
|
|
68
|
+
const accounts = unwrapMoveFields(fields?.accounts);
|
|
69
|
+
const accountTableId = unwrapMoveFields(accounts?.id);
|
|
70
|
+
const userTable = accountTableId?.id || accounts?.id;
|
|
61
71
|
try {
|
|
62
|
-
const userData = await suiClient.
|
|
72
|
+
const userData = await suiClient.core.getDynamicObjectField({
|
|
63
73
|
parentId: userTable,
|
|
64
74
|
name: {
|
|
65
75
|
type: "address",
|
|
66
|
-
|
|
76
|
+
bcs: bcs.Address.serialize(walletAddress).toBytes()
|
|
77
|
+
},
|
|
78
|
+
include: {
|
|
79
|
+
json: true
|
|
67
80
|
}
|
|
68
81
|
});
|
|
69
82
|
// parse the account
|
|
70
83
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
-
const
|
|
84
|
+
const dynamicFields = unwrapMoveFields(userData.object?.json);
|
|
85
|
+
const value = unwrapMoveFields(dynamicFields?.value);
|
|
86
|
+
const fields = unwrapMoveFields(value);
|
|
72
87
|
const cancellationPendingWithdrawalRequestsSequenceNumbers = fields.cancel_withdraw_request;
|
|
73
88
|
return {
|
|
74
89
|
cancellation_pending_withdrawal_requests: fields.pending_withdrawal_requests
|
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.0.
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"setup:sui": "docker-compose -f local/sui/docker-compose.yml up -d",
|
|
69
69
|
"teardown:sui": "docker-compose -f local/sui/docker-compose.yml down",
|
|
70
70
|
"test": "node --loader ts-node/esm ./node_modules/mocha/bin/mocha.js --no-timeout tests/*.test.ts",
|
|
71
|
+
"test:integration": "node --loader ts-node/esm ./node_modules/mocha/bin/mocha.js --no-timeout tests/Vault.integration.test.ts",
|
|
71
72
|
"publish-beta": "npm publish --tag beta",
|
|
72
73
|
"generate:vaults:api-client-v2": "openapi-generator-cli generate -i ./src/api/v2/openapi.yml -g typescript-axios -c ./src/api/v2/config.json -o ./src/api/v2 && node ./scripts/fix-openapi-esm.mjs ./src/api/v2",
|
|
73
74
|
"generate:vaults:api-client": "openapi-generator-cli generate -i ./src/api/openapi.yml -g typescript-axios -c ./src/api/config.json -o ./src/api && node ./scripts/fix-openapi-esm.mjs ./src/api",
|
|
@@ -78,15 +79,14 @@
|
|
|
78
79
|
"test": "tests"
|
|
79
80
|
},
|
|
80
81
|
"dependencies": {
|
|
81
|
-
"@firefly-exchange/library-sui": "3.0.0
|
|
82
|
-
"@mysten/bcs": "2.0.3",
|
|
83
|
-
"@mysten/sui": "2.9.1",
|
|
84
|
-
"@mysten/zklogin": "0.8.1",
|
|
82
|
+
"@firefly-exchange/library-sui": "^3.0.0",
|
|
85
83
|
"axios": "1.13.6",
|
|
86
84
|
"ethers": "^6.13.4",
|
|
87
85
|
"yarn": "^1.22.19"
|
|
88
86
|
},
|
|
89
87
|
"devDependencies": {
|
|
88
|
+
"@mysten/bcs": "^2.0.3",
|
|
89
|
+
"@mysten/sui": "^2.0.0",
|
|
90
90
|
"@openapitools/openapi-generator-cli": "^2.24.0",
|
|
91
91
|
"@types/chai": "^4.3.3",
|
|
92
92
|
"@types/chai-as-promised": "^7.1.5",
|
|
@@ -111,6 +111,10 @@
|
|
|
111
111
|
"typescript": "*",
|
|
112
112
|
"widdershins": "^4.0.1"
|
|
113
113
|
},
|
|
114
|
+
"peerDependencies": {
|
|
115
|
+
"@mysten/bcs": "^2.0.3",
|
|
116
|
+
"@mysten/sui": "^2.0.0"
|
|
117
|
+
},
|
|
114
118
|
"repository": {
|
|
115
119
|
"type": "git",
|
|
116
120
|
"url": "git+https://github.com/fireflyprotocol/ember-sdk.git"
|