@ember-finance/sdk 0.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.
- package/LICENSE +201 -0
- package/README.md +102 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/src/common/types.d.ts +1 -0
- package/dist/src/common/types.js +2 -0
- package/dist/src/vaults/bluefin-vaults.d.ts +15 -0
- package/dist/src/vaults/bluefin-vaults.js +19 -0
- package/dist/src/vaults/interfaces/bcs.d.ts +29 -0
- package/dist/src/vaults/interfaces/bcs.js +18 -0
- package/dist/src/vaults/interfaces/index.d.ts +82 -0
- package/dist/src/vaults/interfaces/index.js +2 -0
- package/dist/src/vaults/on-chain-calls/admin.d.ts +88 -0
- package/dist/src/vaults/on-chain-calls/admin.js +144 -0
- package/dist/src/vaults/on-chain-calls/index.d.ts +6 -0
- package/dist/src/vaults/on-chain-calls/index.js +22 -0
- package/dist/src/vaults/on-chain-calls/onchain-calls.d.ts +34 -0
- package/dist/src/vaults/on-chain-calls/onchain-calls.js +53 -0
- package/dist/src/vaults/on-chain-calls/operator.d.ts +74 -0
- package/dist/src/vaults/on-chain-calls/operator.js +136 -0
- package/dist/src/vaults/on-chain-calls/tx-builder.d.ts +252 -0
- package/dist/src/vaults/on-chain-calls/tx-builder.js +805 -0
- package/dist/src/vaults/on-chain-calls/user.d.ts +47 -0
- package/dist/src/vaults/on-chain-calls/user.js +114 -0
- package/dist/src/vaults/on-chain-calls/vault-admin.d.ts +64 -0
- package/dist/src/vaults/on-chain-calls/vault-admin.js +114 -0
- package/dist/src/vaults/on-chain-calls/vault.d.ts +42 -0
- package/dist/src/vaults/on-chain-calls/vault.js +79 -0
- package/dist/src/vaults/utils/common.d.ts +2 -0
- package/dist/src/vaults/utils/common.js +8 -0
- package/dist/src/vaults/utils/deployment-parser.d.ts +13 -0
- package/dist/src/vaults/utils/deployment-parser.js +49 -0
- package/dist/src/vaults/utils/index.d.ts +2 -0
- package/dist/src/vaults/utils/index.js +18 -0
- package/package.json +79 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { OnChainCalls } from "./onchain-calls";
|
|
2
|
+
import { IDeployment, IVaultOptionalParams } from "../interfaces";
|
|
3
|
+
import { OnChainCallResponse, Signer, SuiAddress, SuiClient, SuiTransactionBlockResponseOptions, NumStr } from "@firefly-exchange/library-sui";
|
|
4
|
+
export declare class UserCalls extends OnChainCalls {
|
|
5
|
+
constructor(_network: string, _suiClient: SuiClient, _deployment: IDeployment, _signer?: Signer, _walletAddress?: string, _isUIWallet?: boolean);
|
|
6
|
+
/**
|
|
7
|
+
* Deposit asset into a vault
|
|
8
|
+
* @param vaultId The id of the vault to deposit into
|
|
9
|
+
* @param amount The amount of asset to deposit
|
|
10
|
+
* @param options Optional tx execution params
|
|
11
|
+
* @returns OnChainCallResponse
|
|
12
|
+
*/
|
|
13
|
+
depositAsset(vaultId: string, amount: NumStr, options?: IVaultOptionalParams & {
|
|
14
|
+
coinId?: string;
|
|
15
|
+
} & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
|
|
16
|
+
/**
|
|
17
|
+
* Mint shares of a vault
|
|
18
|
+
* @param vaultId The id of the vault to mint shares for
|
|
19
|
+
* @param numberOfShares The number of shares to mint
|
|
20
|
+
* @param coinId The id of the coin used to mint shares
|
|
21
|
+
* @param options Optional tx execution params
|
|
22
|
+
* @returns OnChainCallResponse
|
|
23
|
+
*/
|
|
24
|
+
mintShares(vaultId: string, numberOfShares: NumStr, options?: IVaultOptionalParams & {
|
|
25
|
+
receiver?: SuiAddress;
|
|
26
|
+
coinId?: string;
|
|
27
|
+
} & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
|
|
28
|
+
/**
|
|
29
|
+
* Redeem shares of a vault
|
|
30
|
+
* @param vaultId The id of the vault to redeem shares from
|
|
31
|
+
* @param amountOfShares The number of shares to redeem
|
|
32
|
+
* @param options Optional tx execution params
|
|
33
|
+
* @returns OnChainCallResponse
|
|
34
|
+
*/
|
|
35
|
+
redeemShares(vaultId: string, amountOfShares: NumStr, options?: IVaultOptionalParams & {
|
|
36
|
+
receiver?: SuiAddress;
|
|
37
|
+
coinId?: string;
|
|
38
|
+
} & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
|
|
39
|
+
/**
|
|
40
|
+
* Cancel pending withdrawal request
|
|
41
|
+
* @param vaultId The id of the vault to cancel the pending withdrawal request from
|
|
42
|
+
* @param sequenceNumber The sequence number of the withdrawal request to cancel
|
|
43
|
+
* @param options Optional tx execution params
|
|
44
|
+
* @returns OnChainCallResponse
|
|
45
|
+
*/
|
|
46
|
+
cancelPendingWithdrawalRequest(vaultId: string, sequenceNumber: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserCalls = void 0;
|
|
4
|
+
const onchain_calls_1 = require("./onchain-calls");
|
|
5
|
+
const library_sui_1 = require("@firefly-exchange/library-sui");
|
|
6
|
+
const vault_1 = require("./vault");
|
|
7
|
+
class UserCalls extends onchain_calls_1.OnChainCalls {
|
|
8
|
+
constructor(_network, _suiClient, _deployment, _signer, _walletAddress, _isUIWallet) {
|
|
9
|
+
super(_network, _suiClient, _deployment, _signer, _walletAddress, _isUIWallet);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Deposit asset into a vault
|
|
13
|
+
* @param vaultId The id of the vault to deposit into
|
|
14
|
+
* @param amount The amount of asset to deposit
|
|
15
|
+
* @param options Optional tx execution params
|
|
16
|
+
* @returns OnChainCallResponse
|
|
17
|
+
*/
|
|
18
|
+
async depositAsset(vaultId, amount, options) {
|
|
19
|
+
let coinId = options?.coinId;
|
|
20
|
+
const txb = options?.txBlock || new library_sui_1.TransactionBlock();
|
|
21
|
+
let split;
|
|
22
|
+
let merged;
|
|
23
|
+
if (!coinId) {
|
|
24
|
+
const coinType = this.parser.getDepositCoinType(vaultId);
|
|
25
|
+
[split, merged] = await library_sui_1.CoinUtils.createCoinWithBalance(this.suiClient, txb, (0, library_sui_1.bigNumber)(amount).toFixed(0), coinType, this.walletAddress);
|
|
26
|
+
coinId = split;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
[split, merged] = await library_sui_1.CoinUtils.validateCoinBalance(this.suiClient, txb, (0, library_sui_1.bigNumber)(amount).toFixed(0), coinId);
|
|
30
|
+
coinId = split;
|
|
31
|
+
}
|
|
32
|
+
this.txBuilder.depositAsset(vaultId, coinId, { ...options, txBlock: txb });
|
|
33
|
+
if (merged) {
|
|
34
|
+
txb.transferObjects([merged], this.walletAddress);
|
|
35
|
+
}
|
|
36
|
+
return this.execCall(txb, options);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Mint shares of a vault
|
|
40
|
+
* @param vaultId The id of the vault to mint shares for
|
|
41
|
+
* @param numberOfShares The number of shares to mint
|
|
42
|
+
* @param coinId The id of the coin used to mint shares
|
|
43
|
+
* @param options Optional tx execution params
|
|
44
|
+
* @returns OnChainCallResponse
|
|
45
|
+
*/
|
|
46
|
+
async mintShares(vaultId, numberOfShares, options) {
|
|
47
|
+
let coinId = options?.coinId;
|
|
48
|
+
const txb = options?.txBlock || new library_sui_1.TransactionBlock();
|
|
49
|
+
const vaultRate = await vault_1.Vault.getVaultRate(this.suiClient, vaultId);
|
|
50
|
+
const vaultRateBN = (0, library_sui_1.bigNumber)(vaultRate).shiftedBy(library_sui_1.SUI_NATIVE_BASE);
|
|
51
|
+
const assetAmountRequired = (0, library_sui_1.bigNumber)(numberOfShares)
|
|
52
|
+
.multipliedBy(vaultRateBN)
|
|
53
|
+
.toFixed(0);
|
|
54
|
+
let split;
|
|
55
|
+
let merged;
|
|
56
|
+
if (!coinId) {
|
|
57
|
+
const coinType = this.parser.getDepositCoinType(vaultId);
|
|
58
|
+
[split, merged] = await library_sui_1.CoinUtils.createCoinWithBalance(this.suiClient, txb, assetAmountRequired, coinType, this.walletAddress);
|
|
59
|
+
coinId = split;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
[split, merged] = await library_sui_1.CoinUtils.validateCoinBalance(this.suiClient, txb, assetAmountRequired, coinId);
|
|
63
|
+
coinId = split;
|
|
64
|
+
}
|
|
65
|
+
this.txBuilder.mintShares(vaultId, coinId, numberOfShares, options?.receiver || this.walletAddress, { ...options, txBlock: txb });
|
|
66
|
+
if (merged) {
|
|
67
|
+
txb.transferObjects([merged], this.walletAddress);
|
|
68
|
+
}
|
|
69
|
+
return this.execCall(txb, options);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Redeem shares of a vault
|
|
73
|
+
* @param vaultId The id of the vault to redeem shares from
|
|
74
|
+
* @param amountOfShares The number of shares to redeem
|
|
75
|
+
* @param options Optional tx execution params
|
|
76
|
+
* @returns OnChainCallResponse
|
|
77
|
+
*/
|
|
78
|
+
async redeemShares(vaultId, amountOfShares, options) {
|
|
79
|
+
let coinId = options?.coinId;
|
|
80
|
+
const txb = options?.txBlock || new library_sui_1.TransactionBlock();
|
|
81
|
+
let merged;
|
|
82
|
+
let split;
|
|
83
|
+
if (!coinId) {
|
|
84
|
+
const coinType = this.parser.getReceiptCoinType(vaultId);
|
|
85
|
+
[split, merged] = await library_sui_1.CoinUtils.createCoinWithBalance(this.suiClient, txb, (0, library_sui_1.bigNumber)(amountOfShares).toFixed(0), coinType, this.walletAddress);
|
|
86
|
+
coinId = split;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
[split, merged] = await library_sui_1.CoinUtils.validateCoinBalance(this.suiClient, txb, (0, library_sui_1.bigNumber)(amountOfShares).toFixed(0), coinId);
|
|
90
|
+
coinId = split;
|
|
91
|
+
}
|
|
92
|
+
this.txBuilder.redeemShares(vaultId, coinId, options?.receiver || this.walletAddress, { ...options, txBlock: txb });
|
|
93
|
+
if (merged) {
|
|
94
|
+
txb.transferObjects([merged], this.walletAddress);
|
|
95
|
+
}
|
|
96
|
+
return this.execCall(txb, options);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Cancel pending withdrawal request
|
|
100
|
+
* @param vaultId The id of the vault to cancel the pending withdrawal request from
|
|
101
|
+
* @param sequenceNumber The sequence number of the withdrawal request to cancel
|
|
102
|
+
* @param options Optional tx execution params
|
|
103
|
+
* @returns OnChainCallResponse
|
|
104
|
+
*/
|
|
105
|
+
async cancelPendingWithdrawalRequest(vaultId, sequenceNumber, options) {
|
|
106
|
+
const txb = options?.txBlock || new library_sui_1.TransactionBlock();
|
|
107
|
+
this.txBuilder.cancelPendingWithdrawalRequest(vaultId, sequenceNumber, {
|
|
108
|
+
...options,
|
|
109
|
+
txBlock: txb
|
|
110
|
+
});
|
|
111
|
+
return this.execCall(txb, options);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.UserCalls = UserCalls;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { OnChainCalls } from "./onchain-calls";
|
|
2
|
+
import { IDeployment, IVaultOptionalParams } from "../interfaces";
|
|
3
|
+
import { NumStr } from "@firefly-exchange/library-sui";
|
|
4
|
+
import { OnChainCallResponse, Signer, SuiClient, SuiTransactionBlockResponseOptions } from "@firefly-exchange/library-sui";
|
|
5
|
+
export declare class VaultAdminCalls extends OnChainCalls {
|
|
6
|
+
constructor(_network: string, _suiClient: SuiClient, _deployment: IDeployment, _signer?: Signer, _walletAddress?: string);
|
|
7
|
+
/**
|
|
8
|
+
* Set min withdrawal shares
|
|
9
|
+
* @param vaultId The id of the vault to set the min withdrawal shares for
|
|
10
|
+
* @param minWithdrawalShares The minimum number of shares to withdraw
|
|
11
|
+
* @param options Optional tx execution params
|
|
12
|
+
* @returns OnChainCallResponse
|
|
13
|
+
*/
|
|
14
|
+
setMinWithdrawalShares(vaultId: string, minWithdrawalShares: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
|
|
15
|
+
/**
|
|
16
|
+
* Update vault fee percentage
|
|
17
|
+
* @param vaultId The id of the vault to update the fee percentage for
|
|
18
|
+
* @param feePercentage The new fee percentage to set for the vault
|
|
19
|
+
* @param options Optional tx execution params
|
|
20
|
+
* @returns OnChainCallResponse
|
|
21
|
+
*/
|
|
22
|
+
updateVaultFeePercentage(vaultId: string, feePercentage: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Set/unset sub account
|
|
25
|
+
* @param vaultId The id of the vault to set the sub account for
|
|
26
|
+
* @param subAccount The sub account to set for the vault
|
|
27
|
+
* @param isSubAccount Whether the sub account is a sub account
|
|
28
|
+
* @param options Optional tx execution params
|
|
29
|
+
* @returns OnChainCallResponse
|
|
30
|
+
*/
|
|
31
|
+
setSubAccount(vaultId: string, subAccount: string, isSubAccount: boolean, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
|
|
32
|
+
/**
|
|
33
|
+
* Update vault operator
|
|
34
|
+
* @param vaultId The id of the vault to update the operator for
|
|
35
|
+
* @param operator The operator to update for the vault
|
|
36
|
+
* @param options Optional tx execution params
|
|
37
|
+
* @returns OnChainCallResponse
|
|
38
|
+
*/
|
|
39
|
+
updateVaultOperator(vaultId: string, operator: string, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
|
|
40
|
+
/**
|
|
41
|
+
* Update vault paused status
|
|
42
|
+
* @param vaultId The id of the vault to update the paused status for
|
|
43
|
+
* @param paused The new paused status to set for the vault
|
|
44
|
+
* @param options Optional tx execution params
|
|
45
|
+
* @returns OnChainCallResponse
|
|
46
|
+
*/
|
|
47
|
+
updateVaultPausedStatus(vaultId: string, paused: boolean, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
|
|
48
|
+
/**
|
|
49
|
+
* Update vault rate update interval
|
|
50
|
+
* @param vaultId The id of the vault to update the rate update interval for
|
|
51
|
+
* @param rateUpdateInterval The new rate update interval to set for the vault
|
|
52
|
+
* @param options Optional tx execution params
|
|
53
|
+
* @returns OnChainCallResponse
|
|
54
|
+
*/
|
|
55
|
+
updateVaultRateUpdateInterval(vaultId: string, rateUpdateInterval: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
|
|
56
|
+
/**
|
|
57
|
+
* Update vault max TVL
|
|
58
|
+
* @param vaultId The id of the vault to update the max TVL for
|
|
59
|
+
* @param maxTVL The new max TVL to set for the vault
|
|
60
|
+
* @param options Optional tx execution params
|
|
61
|
+
* @returns OnChainCallResponse
|
|
62
|
+
*/
|
|
63
|
+
updateVaultMaxTVL(vaultId: string, maxTVL: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
|
|
64
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultAdminCalls = void 0;
|
|
4
|
+
const onchain_calls_1 = require("./onchain-calls");
|
|
5
|
+
const library_sui_1 = require("@firefly-exchange/library-sui");
|
|
6
|
+
class VaultAdminCalls extends onchain_calls_1.OnChainCalls {
|
|
7
|
+
constructor(_network, _suiClient, _deployment, _signer, _walletAddress) {
|
|
8
|
+
super(_network, _suiClient, _deployment, _signer, _walletAddress);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Set min withdrawal shares
|
|
12
|
+
* @param vaultId The id of the vault to set the min withdrawal shares for
|
|
13
|
+
* @param minWithdrawalShares The minimum number of shares to withdraw
|
|
14
|
+
* @param options Optional tx execution params
|
|
15
|
+
* @returns OnChainCallResponse
|
|
16
|
+
*/
|
|
17
|
+
async setMinWithdrawalShares(vaultId, minWithdrawalShares, options) {
|
|
18
|
+
const txb = options?.txBlock || new library_sui_1.TransactionBlock();
|
|
19
|
+
this.txBuilder.setMinWithdrawalShares(vaultId, minWithdrawalShares, {
|
|
20
|
+
...options,
|
|
21
|
+
txBlock: txb
|
|
22
|
+
});
|
|
23
|
+
return this.execCall(txb, options);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Update vault fee percentage
|
|
27
|
+
* @param vaultId The id of the vault to update the fee percentage for
|
|
28
|
+
* @param feePercentage The new fee percentage to set for the vault
|
|
29
|
+
* @param options Optional tx execution params
|
|
30
|
+
* @returns OnChainCallResponse
|
|
31
|
+
*/
|
|
32
|
+
async updateVaultFeePercentage(vaultId, feePercentage, options) {
|
|
33
|
+
const txb = options?.txBlock || new library_sui_1.TransactionBlock();
|
|
34
|
+
this.txBuilder.updateVaultFeePercentage(vaultId, feePercentage, {
|
|
35
|
+
...options,
|
|
36
|
+
txBlock: txb
|
|
37
|
+
});
|
|
38
|
+
return this.execCall(txb, options);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Set/unset sub account
|
|
42
|
+
* @param vaultId The id of the vault to set the sub account for
|
|
43
|
+
* @param subAccount The sub account to set for the vault
|
|
44
|
+
* @param isSubAccount Whether the sub account is a sub account
|
|
45
|
+
* @param options Optional tx execution params
|
|
46
|
+
* @returns OnChainCallResponse
|
|
47
|
+
*/
|
|
48
|
+
async setSubAccount(vaultId, subAccount, isSubAccount, options) {
|
|
49
|
+
const txb = options?.txBlock || new library_sui_1.TransactionBlock();
|
|
50
|
+
this.txBuilder.setSubAccount(vaultId, subAccount, isSubAccount, {
|
|
51
|
+
...options,
|
|
52
|
+
txBlock: txb
|
|
53
|
+
});
|
|
54
|
+
return this.execCall(txb, options);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Update vault operator
|
|
58
|
+
* @param vaultId The id of the vault to update the operator for
|
|
59
|
+
* @param operator The operator to update for the vault
|
|
60
|
+
* @param options Optional tx execution params
|
|
61
|
+
* @returns OnChainCallResponse
|
|
62
|
+
*/
|
|
63
|
+
async updateVaultOperator(vaultId, operator, options) {
|
|
64
|
+
const txb = options?.txBlock || new library_sui_1.TransactionBlock();
|
|
65
|
+
this.txBuilder.updateVaultOperator(vaultId, operator, {
|
|
66
|
+
...options,
|
|
67
|
+
txBlock: txb
|
|
68
|
+
});
|
|
69
|
+
return this.execCall(txb, options);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Update vault paused status
|
|
73
|
+
* @param vaultId The id of the vault to update the paused status for
|
|
74
|
+
* @param paused The new paused status to set for the vault
|
|
75
|
+
* @param options Optional tx execution params
|
|
76
|
+
* @returns OnChainCallResponse
|
|
77
|
+
*/
|
|
78
|
+
async updateVaultPausedStatus(vaultId, paused, options) {
|
|
79
|
+
const txb = options?.txBlock || new library_sui_1.TransactionBlock();
|
|
80
|
+
this.txBuilder.updateVaultPausedStatus(vaultId, paused, {
|
|
81
|
+
...options,
|
|
82
|
+
txBlock: txb
|
|
83
|
+
});
|
|
84
|
+
return this.execCall(txb, options);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Update vault rate update interval
|
|
88
|
+
* @param vaultId The id of the vault to update the rate update interval for
|
|
89
|
+
* @param rateUpdateInterval The new rate update interval to set for the vault
|
|
90
|
+
* @param options Optional tx execution params
|
|
91
|
+
* @returns OnChainCallResponse
|
|
92
|
+
*/
|
|
93
|
+
async updateVaultRateUpdateInterval(vaultId, rateUpdateInterval, options) {
|
|
94
|
+
const txb = options?.txBlock || new library_sui_1.TransactionBlock();
|
|
95
|
+
this.txBuilder.updateVaultRateUpdateInterval(vaultId, rateUpdateInterval, {
|
|
96
|
+
...options,
|
|
97
|
+
txBlock: txb
|
|
98
|
+
});
|
|
99
|
+
return this.execCall(txb, options);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Update vault max TVL
|
|
103
|
+
* @param vaultId The id of the vault to update the max TVL for
|
|
104
|
+
* @param maxTVL The new max TVL to set for the vault
|
|
105
|
+
* @param options Optional tx execution params
|
|
106
|
+
* @returns OnChainCallResponse
|
|
107
|
+
*/
|
|
108
|
+
async updateVaultMaxTVL(vaultId, maxTVL, options) {
|
|
109
|
+
const txb = options?.txBlock || new library_sui_1.TransactionBlock();
|
|
110
|
+
this.txBuilder.updateVaultMaxTVL(vaultId, maxTVL, { ...options, txBlock: txb });
|
|
111
|
+
return this.execCall(txb, options);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.VaultAdminCalls = VaultAdminCalls;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Signer, SuiClient } from "@firefly-exchange/library-sui";
|
|
2
|
+
import { IVaultAccount } from "../interfaces";
|
|
3
|
+
export declare class Vault {
|
|
4
|
+
/**
|
|
5
|
+
* Fetches the vault rate from on-chain
|
|
6
|
+
* @param suiClient Sui Client
|
|
7
|
+
* @param vaultId The id of the vault to fetch the rate for
|
|
8
|
+
* @returns The vault rate
|
|
9
|
+
*/
|
|
10
|
+
static getVaultRate(suiClient: SuiClient, vaultId: string): Promise<number>;
|
|
11
|
+
static getPendingWithdrawalRequests(suiClient: SuiClient, vaultId: string, walletAddress: string): Promise<IVaultAccount>;
|
|
12
|
+
static signUpdateVaultStrategyRequest(payload: {
|
|
13
|
+
vaultId: string;
|
|
14
|
+
strategies: {
|
|
15
|
+
platformName: string;
|
|
16
|
+
strategistAddress: string;
|
|
17
|
+
strategyType: string;
|
|
18
|
+
allocationE9: string;
|
|
19
|
+
apyE9: string;
|
|
20
|
+
pointsApyE9: string;
|
|
21
|
+
snapshotAt: number;
|
|
22
|
+
}[];
|
|
23
|
+
targetApyE9: string;
|
|
24
|
+
}, signer: Signer): Promise<{
|
|
25
|
+
bcsPayload: string;
|
|
26
|
+
requestBody: {
|
|
27
|
+
vaultId: string;
|
|
28
|
+
strategies: {
|
|
29
|
+
platformName: string;
|
|
30
|
+
strategistAddress: string;
|
|
31
|
+
strategyType: string;
|
|
32
|
+
allocationE9: string;
|
|
33
|
+
apyE9: string;
|
|
34
|
+
pointsApyE9: string;
|
|
35
|
+
snapshotAt: number;
|
|
36
|
+
}[];
|
|
37
|
+
targetApyE9: string;
|
|
38
|
+
signedAt: number;
|
|
39
|
+
signature: string;
|
|
40
|
+
};
|
|
41
|
+
}>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Vault = void 0;
|
|
4
|
+
const bcs_1 = require("../interfaces/bcs");
|
|
5
|
+
class Vault {
|
|
6
|
+
/**
|
|
7
|
+
* Fetches the vault rate from on-chain
|
|
8
|
+
* @param suiClient Sui Client
|
|
9
|
+
* @param vaultId The id of the vault to fetch the rate for
|
|
10
|
+
* @returns The vault rate
|
|
11
|
+
*/
|
|
12
|
+
static async getVaultRate(suiClient, vaultId) {
|
|
13
|
+
const response = await suiClient.getObject({
|
|
14
|
+
id: vaultId,
|
|
15
|
+
options: {
|
|
16
|
+
showContent: true
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return (response.data?.content).fields?.["rate"]?.fields?.["value"];
|
|
20
|
+
}
|
|
21
|
+
static async getPendingWithdrawalRequests(suiClient, vaultId, walletAddress) {
|
|
22
|
+
const objDetails = await suiClient.getObject({
|
|
23
|
+
id: vaultId,
|
|
24
|
+
options: { showContent: true }
|
|
25
|
+
});
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
const userTable = (objDetails.data?.content).fields.accounts.fields.id.id;
|
|
28
|
+
try {
|
|
29
|
+
const userData = await suiClient.getDynamicFieldObject({
|
|
30
|
+
parentId: userTable,
|
|
31
|
+
name: {
|
|
32
|
+
type: "address",
|
|
33
|
+
value: walletAddress
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
// parse the account
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
const fields = (userData.data?.content).fields.value.fields;
|
|
39
|
+
const cancellationPendingWithdrawalRequestsSequenceNumbers = fields.cancel_withdraw_request;
|
|
40
|
+
return {
|
|
41
|
+
cancellation_pending_withdrawal_requests: fields.pending_withdrawal_requests
|
|
42
|
+
.filter((request) => cancellationPendingWithdrawalRequestsSequenceNumbers.includes(request.fields.sequence_number))
|
|
43
|
+
.map((request) => request.fields),
|
|
44
|
+
pending_withdrawal_requests: fields.pending_withdrawal_requests
|
|
45
|
+
.filter((request) => !cancellationPendingWithdrawalRequestsSequenceNumbers.includes(request.fields.sequence_number))
|
|
46
|
+
.map((request) => request.fields),
|
|
47
|
+
total_pending_withdrawal_shares: fields.total_pending_withdrawal_shares.toString()
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
return {
|
|
52
|
+
cancellation_pending_withdrawal_requests: [],
|
|
53
|
+
pending_withdrawal_requests: [],
|
|
54
|
+
total_pending_withdrawal_shares: "0"
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
static async signUpdateVaultStrategyRequest(payload, signer) {
|
|
59
|
+
const now = Date.now();
|
|
60
|
+
const bcsPayload = bcs_1.BcsUpdateVaultStrategyRequest.serialize({
|
|
61
|
+
vaultId: payload.vaultId,
|
|
62
|
+
strategies: payload.strategies,
|
|
63
|
+
targetApyE9: payload.targetApyE9,
|
|
64
|
+
signedAt: now
|
|
65
|
+
}).toBytes();
|
|
66
|
+
const { signature, bytes } = await signer.signPersonalMessage(bcsPayload);
|
|
67
|
+
return {
|
|
68
|
+
bcsPayload: bytes,
|
|
69
|
+
requestBody: {
|
|
70
|
+
vaultId: payload.vaultId,
|
|
71
|
+
strategies: payload.strategies,
|
|
72
|
+
signedAt: now,
|
|
73
|
+
targetApyE9: payload.targetApyE9,
|
|
74
|
+
signature: signature
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.Vault = Vault;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTxBytes = void 0;
|
|
4
|
+
const utils_1 = require("@mysten/sui/utils");
|
|
5
|
+
const getTxBytes = async (tx, client) => {
|
|
6
|
+
return (0, utils_1.toBase64)(await tx.build({ client: client, onlyTransactionKind: false }));
|
|
7
|
+
};
|
|
8
|
+
exports.getTxBytes = getTxBytes;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IDeployment } from "../interfaces";
|
|
2
|
+
export declare class DeploymentParser {
|
|
3
|
+
deployment: IDeployment;
|
|
4
|
+
constructor(_deployment: IDeployment);
|
|
5
|
+
getAdminCap(): string;
|
|
6
|
+
getPackageId(): string;
|
|
7
|
+
getUpgradeCap(): string;
|
|
8
|
+
getProtocolConfig(): string;
|
|
9
|
+
getReceiptCoinTreasuryCap(receiptCoinType: string): string;
|
|
10
|
+
getDepositCoinType(vaultId: string): string;
|
|
11
|
+
getReceiptCoinType(vaultId: string): string;
|
|
12
|
+
getDepositCoinDecimals(vaultId: string): number;
|
|
13
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeploymentParser = void 0;
|
|
4
|
+
class DeploymentParser {
|
|
5
|
+
constructor(_deployment) {
|
|
6
|
+
this.deployment = _deployment;
|
|
7
|
+
}
|
|
8
|
+
getAdminCap() {
|
|
9
|
+
return this.deployment.VaultProtocol.AdminCap;
|
|
10
|
+
}
|
|
11
|
+
getPackageId() {
|
|
12
|
+
return this.deployment.VaultProtocol.Package;
|
|
13
|
+
}
|
|
14
|
+
getUpgradeCap() {
|
|
15
|
+
return this.deployment.VaultProtocol.UpgradeCap;
|
|
16
|
+
}
|
|
17
|
+
getProtocolConfig() {
|
|
18
|
+
return this.deployment.VaultProtocol.ProtocolConfig;
|
|
19
|
+
}
|
|
20
|
+
getReceiptCoinTreasuryCap(receiptCoinType) {
|
|
21
|
+
const treasuryCap = this.deployment.UltraCoins.find(coin => coin.Currency === receiptCoinType)?.TreasuryCap;
|
|
22
|
+
if (!treasuryCap) {
|
|
23
|
+
throw new Error(`Treasury cap not found for receipt coin type: ${receiptCoinType}`);
|
|
24
|
+
}
|
|
25
|
+
return treasuryCap;
|
|
26
|
+
}
|
|
27
|
+
getDepositCoinType(vaultId) {
|
|
28
|
+
const vault = Object.values(this.deployment.Vaults).find(vault => vault.ObjectId === vaultId);
|
|
29
|
+
if (!vault) {
|
|
30
|
+
throw new Error(`Vault not found for id: ${vaultId}`);
|
|
31
|
+
}
|
|
32
|
+
return vault.DepositCoinType;
|
|
33
|
+
}
|
|
34
|
+
getReceiptCoinType(vaultId) {
|
|
35
|
+
const vault = Object.values(this.deployment.Vaults).find(vault => vault.ObjectId === vaultId);
|
|
36
|
+
if (!vault) {
|
|
37
|
+
throw new Error(`Vault not found for id: ${vaultId}`);
|
|
38
|
+
}
|
|
39
|
+
return vault.ReceiptCoinType;
|
|
40
|
+
}
|
|
41
|
+
getDepositCoinDecimals(vaultId) {
|
|
42
|
+
const vault = Object.values(this.deployment.Vaults).find(vault => vault.ObjectId === vaultId);
|
|
43
|
+
if (!vault) {
|
|
44
|
+
throw new Error(`Vault not found for id: ${vaultId}`);
|
|
45
|
+
}
|
|
46
|
+
return vault.DepositCoinDecimals;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.DeploymentParser = DeploymentParser;
|
|
@@ -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("./deployment-parser"), exports);
|
|
18
|
+
__exportStar(require("./common"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ember-finance/sdk",
|
|
3
|
+
"description": "Ember Protocol SDK",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"module": "./dist/index.js",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"react-native": {
|
|
10
|
+
"fs": false
|
|
11
|
+
},
|
|
12
|
+
"browser": {
|
|
13
|
+
"fs": false
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
"./vaults": {
|
|
17
|
+
"types": "./dist/src/vaults/index.d.ts",
|
|
18
|
+
"import": "./dist/src/vaults/index.js",
|
|
19
|
+
"require": "./dist/src/vaults/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "yarn run clean && tsc",
|
|
24
|
+
"clean": "rm -rf dist",
|
|
25
|
+
"prepare": "husky install",
|
|
26
|
+
"lint": "yarn eslint --fix --cache --max-warnings=-1 .",
|
|
27
|
+
"format-all": "yarn prettier --write .",
|
|
28
|
+
"format-staged": "git-format-staged -f \"prettier '{}'\" '**/*.js' '**/*.json' '**/*.ts' ",
|
|
29
|
+
"ci:code-formatting": "yarn prettier --check .",
|
|
30
|
+
"ci:code-style": "yarn eslint .",
|
|
31
|
+
"setup:sui": "docker-compose -f local/sui/docker-compose.yml up -d",
|
|
32
|
+
"teardown:sui": "docker-compose -f local/sui/docker-compose.yml down",
|
|
33
|
+
"test": "ts-mocha --no-timeout tests/*.test.ts",
|
|
34
|
+
"publish-beta": "npm publish --tag beta"
|
|
35
|
+
},
|
|
36
|
+
"directories": {
|
|
37
|
+
"test": "tests"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@firefly-exchange/library-sui": "^2.8.22",
|
|
41
|
+
"yargs": "^17.6.2",
|
|
42
|
+
"yarn": "^1.22.19"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/chai": "^4.3.3",
|
|
46
|
+
"@types/chai-as-promised": "^7.1.5",
|
|
47
|
+
"@types/dotenv-parse-variables": "^2.0.1",
|
|
48
|
+
"@types/expect": "^24.3.0",
|
|
49
|
+
"@types/lodash": "^4.14.195",
|
|
50
|
+
"@types/mocha": "^10.0.0",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
52
|
+
"chai": "^4.3.6",
|
|
53
|
+
"eslint": "^8.42.0",
|
|
54
|
+
"eslint-config-standard-with-typescript": "^34.0.0",
|
|
55
|
+
"eslint-plugin-import": "^2.25.2",
|
|
56
|
+
"eslint-plugin-n": "^15.0.0",
|
|
57
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
58
|
+
"git-format-staged": "^3.0.0",
|
|
59
|
+
"husky": "^8.0.0",
|
|
60
|
+
"mocha": "^10.1.0",
|
|
61
|
+
"prettier": "^2.8.8",
|
|
62
|
+
"pretty-quick": "^3.1.3",
|
|
63
|
+
"ts-mocha": "^10.0.0",
|
|
64
|
+
"ts-node": "^10.9.1",
|
|
65
|
+
"typescript": "*"
|
|
66
|
+
},
|
|
67
|
+
"repository": {
|
|
68
|
+
"type": "git",
|
|
69
|
+
"url": "git+https://github.com/fireflyprotocol/ember-sdk.git"
|
|
70
|
+
},
|
|
71
|
+
"author": "",
|
|
72
|
+
"license": "ISC",
|
|
73
|
+
"publishConfig": {
|
|
74
|
+
"access": "public"
|
|
75
|
+
},
|
|
76
|
+
"files": [
|
|
77
|
+
"dist"
|
|
78
|
+
]
|
|
79
|
+
}
|