@ember-finance/sdk 2.21.0 → 2.22.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/sui-vaults/on-chain-calls/operator.d.ts +10 -1
- package/dist/src/sui-vaults/on-chain-calls/operator.js +22 -2
- package/dist/src/sui-vaults/on-chain-calls/protocol-config-reader.d.ts +8 -0
- package/dist/src/sui-vaults/on-chain-calls/protocol-config-reader.js +10 -0
- package/dist/src/sui-vaults/on-chain-calls/tx-builder.d.ts +7 -0
- package/dist/src/sui-vaults/on-chain-calls/tx-builder.js +26 -0
- package/package.json +1 -1
|
@@ -6,12 +6,21 @@ import { NumStr } from "@firefly-exchange/library-sui";
|
|
|
6
6
|
export declare class OperatorCalls extends OnChainCalls {
|
|
7
7
|
constructor(_network: string, _suiClient: SuiClient, _deployment: ISuiDeployment, _signer?: Signer, _walletAddress?: string);
|
|
8
8
|
/**
|
|
9
|
-
* Collect platform fee from a vault
|
|
9
|
+
* Collect platform fee from a vault, through whichever entry the protocol's
|
|
10
|
+
* current version accepts: `collect_platform_fee_v2` from VERSION 6, the
|
|
11
|
+
* legacy `collect_platform_fee` before it.
|
|
10
12
|
* @param vaultId The id of the vault to collect platform fee from
|
|
11
13
|
* @param options Optional tx execution params
|
|
12
14
|
* @returns OnChainCallResponse
|
|
13
15
|
*/
|
|
14
16
|
collectPlatformFee(vaultId: string, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
|
|
17
|
+
/**
|
|
18
|
+
* Collect platform fee from a vault via `collect_platform_fee_v2` (VERSION 6+)
|
|
19
|
+
* @param vaultId The id of the vault to collect platform fee from
|
|
20
|
+
* @param options Optional tx execution params
|
|
21
|
+
* @returns OnChainCallResponse
|
|
22
|
+
*/
|
|
23
|
+
collectPlatformFeeV2(vaultId: string, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
|
|
15
24
|
/**
|
|
16
25
|
* Charge platform fee from a vault
|
|
17
26
|
* @param vaultId The id of the vault to charge platform fee from
|
|
@@ -1,19 +1,39 @@
|
|
|
1
1
|
import { OnChainCalls } from "./onchain-calls.js";
|
|
2
2
|
import { TransactionBlock } from "@firefly-exchange/library-sui";
|
|
3
3
|
import { CoinUtils } from "@firefly-exchange/library-sui";
|
|
4
|
+
import { SuiProtocolConfigReader, usesCollectPlatformFeeV2 } from "./protocol-config-reader.js";
|
|
4
5
|
export class OperatorCalls extends OnChainCalls {
|
|
5
6
|
constructor(_network, _suiClient, _deployment, _signer, _walletAddress) {
|
|
6
7
|
super(_network, _suiClient, _deployment, _signer, _walletAddress);
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
|
-
* Collect platform fee from a vault
|
|
10
|
+
* Collect platform fee from a vault, through whichever entry the protocol's
|
|
11
|
+
* current version accepts: `collect_platform_fee_v2` from VERSION 6, the
|
|
12
|
+
* legacy `collect_platform_fee` before it.
|
|
10
13
|
* @param vaultId The id of the vault to collect platform fee from
|
|
11
14
|
* @param options Optional tx execution params
|
|
12
15
|
* @returns OnChainCallResponse
|
|
13
16
|
*/
|
|
14
17
|
async collectPlatformFee(vaultId, options) {
|
|
18
|
+
const { version } = await new SuiProtocolConfigReader(this.suiClient, this.parser.getProtocolConfig()).getProtocolConfigState();
|
|
15
19
|
const txb = options?.txBlock || new TransactionBlock();
|
|
16
|
-
|
|
20
|
+
if (usesCollectPlatformFeeV2(version)) {
|
|
21
|
+
this.txBuilder.collectPlatformFeeV2(vaultId, { ...options, txBlock: txb });
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this.txBuilder.collectPlatformFee(vaultId, { ...options, txBlock: txb });
|
|
25
|
+
}
|
|
26
|
+
return this.execCall(txb, options);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Collect platform fee from a vault via `collect_platform_fee_v2` (VERSION 6+)
|
|
30
|
+
* @param vaultId The id of the vault to collect platform fee from
|
|
31
|
+
* @param options Optional tx execution params
|
|
32
|
+
* @returns OnChainCallResponse
|
|
33
|
+
*/
|
|
34
|
+
async collectPlatformFeeV2(vaultId, options) {
|
|
35
|
+
const txb = options?.txBlock || new TransactionBlock();
|
|
36
|
+
this.txBuilder.collectPlatformFeeV2(vaultId, { ...options, txBlock: txb });
|
|
17
37
|
return this.execCall(txb, options);
|
|
18
38
|
}
|
|
19
39
|
/**
|
|
@@ -2,6 +2,14 @@ import { BaseClient as SuiClient } from "@mysten/sui/client";
|
|
|
2
2
|
import { IProtocolConfigState } from "../interfaces/index.js";
|
|
3
3
|
/** The protocol's sentinel for "no guardian". */
|
|
4
4
|
export declare const SUI_ZERO_ADDRESS: string;
|
|
5
|
+
/** First ProtocolConfig.version whose package aborts `collect_platform_fee`. */
|
|
6
|
+
export declare const SUI_COLLECT_PLATFORM_FEE_V2_VERSION = 6;
|
|
7
|
+
/**
|
|
8
|
+
* Whether platform fees must be collected through `collect_platform_fee_v2`.
|
|
9
|
+
* @param protocolVersion ProtocolConfig.version
|
|
10
|
+
* @returns True from VERSION 6 on
|
|
11
|
+
*/
|
|
12
|
+
export declare function usesCollectPlatformFeeV2(protocolVersion: string | number): boolean;
|
|
5
13
|
export declare class SuiProtocolConfigReader {
|
|
6
14
|
suiClient: SuiClient;
|
|
7
15
|
protocolConfigId: string;
|
|
@@ -4,6 +4,16 @@ import { normalizeSuiAddress } from "@mysten/sui/utils";
|
|
|
4
4
|
const GUARDIAN_FIELD_KEY = "guardian";
|
|
5
5
|
/** The protocol's sentinel for "no guardian". */
|
|
6
6
|
export const SUI_ZERO_ADDRESS = normalizeSuiAddress("0x0");
|
|
7
|
+
/** First ProtocolConfig.version whose package aborts `collect_platform_fee`. */
|
|
8
|
+
export const SUI_COLLECT_PLATFORM_FEE_V2_VERSION = 6;
|
|
9
|
+
/**
|
|
10
|
+
* Whether platform fees must be collected through `collect_platform_fee_v2`.
|
|
11
|
+
* @param protocolVersion ProtocolConfig.version
|
|
12
|
+
* @returns True from VERSION 6 on
|
|
13
|
+
*/
|
|
14
|
+
export function usesCollectPlatformFeeV2(protocolVersion) {
|
|
15
|
+
return Number(protocolVersion) >= SUI_COLLECT_PLATFORM_FEE_V2_VERSION;
|
|
16
|
+
}
|
|
7
17
|
/** gRPC flattens Move structs; JSON-RPC keeps a `fields` wrapper. */
|
|
8
18
|
const unwrapMoveFields = (value) => value?.fields ?? value;
|
|
9
19
|
export class SuiProtocolConfigReader {
|
|
@@ -353,6 +353,13 @@ export declare class TxBuilder {
|
|
|
353
353
|
* @returns TransactionBlock
|
|
354
354
|
*/
|
|
355
355
|
collectPlatformFee(vaultId: string, options?: ITxBuilderOptionalParams): TransactionBlock;
|
|
356
|
+
/**
|
|
357
|
+
* Collect platform fee (package VERSION 6+, where `collect_platform_fee` aborts)
|
|
358
|
+
* @param vaultId Id of the vault
|
|
359
|
+
* @param options Optional tx building params
|
|
360
|
+
* @returns TransactionBlock
|
|
361
|
+
*/
|
|
362
|
+
collectPlatformFeeV2(vaultId: string, options?: ITxBuilderOptionalParams): TransactionBlock;
|
|
356
363
|
/**
|
|
357
364
|
* Deposit asset
|
|
358
365
|
* @param vaultId Id of the vault
|
|
@@ -1041,6 +1041,32 @@ export class TxBuilder {
|
|
|
1041
1041
|
txb.setSenderIfNotSet(options.sender);
|
|
1042
1042
|
return txb;
|
|
1043
1043
|
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Collect platform fee (package VERSION 6+, where `collect_platform_fee` aborts)
|
|
1046
|
+
* @param vaultId Id of the vault
|
|
1047
|
+
* @param options Optional tx building params
|
|
1048
|
+
* @returns TransactionBlock
|
|
1049
|
+
*/
|
|
1050
|
+
collectPlatformFeeV2(vaultId, options) {
|
|
1051
|
+
const txb = options?.txBlock || new TransactionBlock();
|
|
1052
|
+
txb.moveCall({
|
|
1053
|
+
arguments: [
|
|
1054
|
+
txb.object(vaultId),
|
|
1055
|
+
txb.object(this.parser.getProtocolConfig()),
|
|
1056
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
1057
|
+
],
|
|
1058
|
+
typeArguments: [
|
|
1059
|
+
this.parser.getDepositCoinType(vaultId),
|
|
1060
|
+
this.parser.getReceiptCoinType(vaultId)
|
|
1061
|
+
],
|
|
1062
|
+
target: `${this.targetPackageId(options)}::gateway::collect_platform_fee_v2`
|
|
1063
|
+
});
|
|
1064
|
+
if (options?.gasBudget)
|
|
1065
|
+
txb.setGasBudget(options.gasBudget);
|
|
1066
|
+
if (options?.sender)
|
|
1067
|
+
txb.setSenderIfNotSet(options.sender);
|
|
1068
|
+
return txb;
|
|
1069
|
+
}
|
|
1044
1070
|
/**
|
|
1045
1071
|
* Deposit asset
|
|
1046
1072
|
* @param vaultId Id of the vault
|