@ember-finance/sdk 2.16.0 → 2.18.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.
@@ -48,13 +48,13 @@ export declare const VaultsApiAxiosParamCreator: (configuration?: Configuration)
48
48
  /**
49
49
  * Pointers only: which protocol venues list the coin. No amounts are returned — clients read those from chain, so a stale row here can drop a venue but can never report a wrong balance.
50
50
  * @summary Get venues that list an Ember receipt coin
51
- * @param {string} coin Sui coin type or EVM token address of the receipt coin
51
+ * @param {string} [coin] Sui coin type or EVM token address of the receipt coin. Omit it to get every active placement, sorted by coin. A blank value is rejected.
52
52
  * @param {string} [protocol] Restrict to one protocol adapter id, e.g. \"bluefin-spot\"
53
53
  * @param {string} [chainIdentifier] Narrow to one chain, e.g. \"sui-mainnet\".
54
54
  * @param {*} [options] Override http request option.
55
55
  * @throws {RequiredError}
56
56
  */
57
- getCoinPlacements: (coin: string, protocol?: string, chainIdentifier?: string, options?: RawAxiosRequestConfig) => Promise<RequestArgs>;
57
+ getCoinPlacements: (coin?: string, protocol?: string, chainIdentifier?: string, options?: RawAxiosRequestConfig) => Promise<RequestArgs>;
58
58
  /**
59
59
  *
60
60
  * @summary Get the price of the coins
@@ -215,13 +215,13 @@ export declare const VaultsApiFp: (configuration?: Configuration) => {
215
215
  /**
216
216
  * Pointers only: which protocol venues list the coin. No amounts are returned — clients read those from chain, so a stale row here can drop a venue but can never report a wrong balance.
217
217
  * @summary Get venues that list an Ember receipt coin
218
- * @param {string} coin Sui coin type or EVM token address of the receipt coin
218
+ * @param {string} [coin] Sui coin type or EVM token address of the receipt coin. Omit it to get every active placement, sorted by coin. A blank value is rejected.
219
219
  * @param {string} [protocol] Restrict to one protocol adapter id, e.g. \&quot;bluefin-spot\&quot;
220
220
  * @param {string} [chainIdentifier] Narrow to one chain, e.g. \&quot;sui-mainnet\&quot;.
221
221
  * @param {*} [options] Override http request option.
222
222
  * @throws {RequiredError}
223
223
  */
224
- getCoinPlacements(coin: string, protocol?: string, chainIdentifier?: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<CoinPlacementsResponse>>;
224
+ getCoinPlacements(coin?: string, protocol?: string, chainIdentifier?: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<CoinPlacementsResponse>>;
225
225
  /**
226
226
  *
227
227
  * @summary Get the price of the coins
@@ -382,13 +382,13 @@ export declare const VaultsApiFactory: (configuration?: Configuration, basePath?
382
382
  /**
383
383
  * Pointers only: which protocol venues list the coin. No amounts are returned — clients read those from chain, so a stale row here can drop a venue but can never report a wrong balance.
384
384
  * @summary Get venues that list an Ember receipt coin
385
- * @param {string} coin Sui coin type or EVM token address of the receipt coin
385
+ * @param {string} [coin] Sui coin type or EVM token address of the receipt coin. Omit it to get every active placement, sorted by coin. A blank value is rejected.
386
386
  * @param {string} [protocol] Restrict to one protocol adapter id, e.g. \&quot;bluefin-spot\&quot;
387
387
  * @param {string} [chainIdentifier] Narrow to one chain, e.g. \&quot;sui-mainnet\&quot;.
388
388
  * @param {*} [options] Override http request option.
389
389
  * @throws {RequiredError}
390
390
  */
391
- getCoinPlacements(coin: string, protocol?: string, chainIdentifier?: string, options?: RawAxiosRequestConfig): AxiosPromise<CoinPlacementsResponse>;
391
+ getCoinPlacements(coin?: string, protocol?: string, chainIdentifier?: string, options?: RawAxiosRequestConfig): AxiosPromise<CoinPlacementsResponse>;
392
392
  /**
393
393
  *
394
394
  * @summary Get the price of the coins
@@ -552,14 +552,14 @@ export declare class VaultsApi extends BaseAPI {
552
552
  /**
553
553
  * Pointers only: which protocol venues list the coin. No amounts are returned — clients read those from chain, so a stale row here can drop a venue but can never report a wrong balance.
554
554
  * @summary Get venues that list an Ember receipt coin
555
- * @param {string} coin Sui coin type or EVM token address of the receipt coin
555
+ * @param {string} [coin] Sui coin type or EVM token address of the receipt coin. Omit it to get every active placement, sorted by coin. A blank value is rejected.
556
556
  * @param {string} [protocol] Restrict to one protocol adapter id, e.g. \&quot;bluefin-spot\&quot;
557
557
  * @param {string} [chainIdentifier] Narrow to one chain, e.g. \&quot;sui-mainnet\&quot;.
558
558
  * @param {*} [options] Override http request option.
559
559
  * @throws {RequiredError}
560
560
  * @memberof VaultsApi
561
561
  */
562
- getCoinPlacements(coin: string, protocol?: string, chainIdentifier?: string, options?: RawAxiosRequestConfig): Promise<import("axios").AxiosResponse<CoinPlacementsResponse, any, {}>>;
562
+ getCoinPlacements(coin?: string, protocol?: string, chainIdentifier?: string, options?: RawAxiosRequestConfig): Promise<import("axios").AxiosResponse<CoinPlacementsResponse, any, {}>>;
563
563
  /**
564
564
  *
565
565
  * @summary Get the price of the coins
@@ -55,15 +55,13 @@ export const VaultsApiAxiosParamCreator = function (configuration) {
55
55
  /**
56
56
  * Pointers only: which protocol venues list the coin. No amounts are returned — clients read those from chain, so a stale row here can drop a venue but can never report a wrong balance.
57
57
  * @summary Get venues that list an Ember receipt coin
58
- * @param {string} coin Sui coin type or EVM token address of the receipt coin
58
+ * @param {string} [coin] Sui coin type or EVM token address of the receipt coin. Omit it to get every active placement, sorted by coin. A blank value is rejected.
59
59
  * @param {string} [protocol] Restrict to one protocol adapter id, e.g. \&quot;bluefin-spot\&quot;
60
60
  * @param {string} [chainIdentifier] Narrow to one chain, e.g. \&quot;sui-mainnet\&quot;.
61
61
  * @param {*} [options] Override http request option.
62
62
  * @throws {RequiredError}
63
63
  */
64
64
  getCoinPlacements: async (coin, protocol, chainIdentifier, options = {}) => {
65
- // verify required parameter 'coin' is not null or undefined
66
- assertParamExists("getCoinPlacements", "coin", coin);
67
65
  const localVarPath = `/api/v2/vaults/placements`;
68
66
  // use dummy base URL string because the URL constructor only accepts absolute URLs.
69
67
  const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
@@ -713,7 +711,7 @@ export const VaultsApiFp = function (configuration) {
713
711
  /**
714
712
  * Pointers only: which protocol venues list the coin. No amounts are returned — clients read those from chain, so a stale row here can drop a venue but can never report a wrong balance.
715
713
  * @summary Get venues that list an Ember receipt coin
716
- * @param {string} coin Sui coin type or EVM token address of the receipt coin
714
+ * @param {string} [coin] Sui coin type or EVM token address of the receipt coin. Omit it to get every active placement, sorted by coin. A blank value is rejected.
717
715
  * @param {string} [protocol] Restrict to one protocol adapter id, e.g. \&quot;bluefin-spot\&quot;
718
716
  * @param {string} [chainIdentifier] Narrow to one chain, e.g. \&quot;sui-mainnet\&quot;.
719
717
  * @param {*} [options] Override http request option.
@@ -974,7 +972,7 @@ export const VaultsApiFactory = function (configuration, basePath, axios) {
974
972
  /**
975
973
  * Pointers only: which protocol venues list the coin. No amounts are returned — clients read those from chain, so a stale row here can drop a venue but can never report a wrong balance.
976
974
  * @summary Get venues that list an Ember receipt coin
977
- * @param {string} coin Sui coin type or EVM token address of the receipt coin
975
+ * @param {string} [coin] Sui coin type or EVM token address of the receipt coin. Omit it to get every active placement, sorted by coin. A blank value is rejected.
978
976
  * @param {string} [protocol] Restrict to one protocol adapter id, e.g. \&quot;bluefin-spot\&quot;
979
977
  * @param {string} [chainIdentifier] Narrow to one chain, e.g. \&quot;sui-mainnet\&quot;.
980
978
  * @param {*} [options] Override http request option.
@@ -1217,7 +1215,7 @@ export class VaultsApi extends BaseAPI {
1217
1215
  /**
1218
1216
  * Pointers only: which protocol venues list the coin. No amounts are returned — clients read those from chain, so a stale row here can drop a venue but can never report a wrong balance.
1219
1217
  * @summary Get venues that list an Ember receipt coin
1220
- * @param {string} coin Sui coin type or EVM token address of the receipt coin
1218
+ * @param {string} [coin] Sui coin type or EVM token address of the receipt coin. Omit it to get every active placement, sorted by coin. A blank value is rejected.
1221
1219
  * @param {string} [protocol] Restrict to one protocol adapter id, e.g. \&quot;bluefin-spot\&quot;
1222
1220
  * @param {string} [chainIdentifier] Narrow to one chain, e.g. \&quot;sui-mainnet\&quot;.
1223
1221
  * @param {*} [options] Override http request option.
@@ -0,0 +1,84 @@
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: 2.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
+ * An Atomic Liquidity Vault on Sui. Not a VaultInfo with extra fields: an ALV mints no receipt coin, so it has no ReceiptCoinType, and it carries a rate manager because its rate is set externally rather than derived from a receipt supply.
14
+ * @export
15
+ * @interface AtomicVaultInfo
16
+ */
17
+ export interface AtomicVaultInfo {
18
+ /**
19
+ * The name of the vault
20
+ * @type {string}
21
+ * @memberof AtomicVaultInfo
22
+ */
23
+ Name?: string;
24
+ /**
25
+ * The object identifier of the vault
26
+ * @type {string}
27
+ * @memberof AtomicVaultInfo
28
+ */
29
+ ObjectId?: string;
30
+ /**
31
+ * The coin type the vault holds and pays out in
32
+ * @type {string}
33
+ * @memberof AtomicVaultInfo
34
+ */
35
+ CollateralCoinType?: string;
36
+ /**
37
+ * The number of decimals for the collateral coin
38
+ * @type {number}
39
+ * @memberof AtomicVaultInfo
40
+ */
41
+ CollateralCoinDecimals?: number;
42
+ /**
43
+ * The admin identifier for the vault
44
+ * @type {string}
45
+ * @memberof AtomicVaultInfo
46
+ */
47
+ Admin?: string;
48
+ /**
49
+ * The operator identifier for the vault
50
+ * @type {string}
51
+ * @memberof AtomicVaultInfo
52
+ */
53
+ Operator?: string;
54
+ /**
55
+ * The address allowed to update the vault\'s rate
56
+ * @type {string}
57
+ * @memberof AtomicVaultInfo
58
+ */
59
+ RateManager?: string;
60
+ /**
61
+ * The maximum rate change per update
62
+ * @type {string}
63
+ * @memberof AtomicVaultInfo
64
+ */
65
+ MaxRateChangePerUpdate?: string;
66
+ /**
67
+ * The fee percentage for the vault
68
+ * @type {string}
69
+ * @memberof AtomicVaultInfo
70
+ */
71
+ FeePercentage?: string;
72
+ /**
73
+ * The minimum withdrawal shares
74
+ * @type {string}
75
+ * @memberof AtomicVaultInfo
76
+ */
77
+ MinWithdrawalShares?: string;
78
+ /**
79
+ * List of sub-account identifiers
80
+ * @type {Array<string>}
81
+ * @memberof AtomicVaultInfo
82
+ */
83
+ SubAccounts?: Array<string>;
84
+ }
@@ -0,0 +1,14 @@
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: 2.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 {};
@@ -12,6 +12,7 @@ export * from "./apy-history.js";
12
12
  export * from "./apy-history-response.js";
13
13
  export * from "./apy-period-average.js";
14
14
  export * from "./asset.js";
15
+ export * from "./atomic-vault-info.js";
15
16
  export * from "./borrowed.js";
16
17
  export * from "./chain.js";
17
18
  export * from "./chain-vault-details.js";
@@ -12,6 +12,7 @@ export * from "./apy-history.js";
12
12
  export * from "./apy-history-response.js";
13
13
  export * from "./apy-period-average.js";
14
14
  export * from "./asset.js";
15
+ export * from "./atomic-vault-info.js";
15
16
  export * from "./borrowed.js";
16
17
  export * from "./chain.js";
17
18
  export * from "./chain-vault-details.js";
@@ -9,6 +9,7 @@
9
9
  * https://openapi-generator.tech
10
10
  * Do not edit the class manually.
11
11
  */
12
+ import type { AtomicVaultInfo } from "./atomic-vault-info.js";
12
13
  import type { UltraCoinInfo } from "./ultra-coin-info.js";
13
14
  import type { VaultInfo } from "./vault-info.js";
14
15
  import type { VaultProtocol } from "./vault-protocol.js";
@@ -38,4 +39,12 @@ export interface SuiProtocolInfo {
38
39
  Vaults?: {
39
40
  [key: string]: VaultInfo;
40
41
  };
42
+ /**
43
+ * Map of Atomic Liquidity Vaults by id
44
+ * @type {{ [key: string]: AtomicVaultInfo; }}
45
+ * @memberof SuiProtocolInfo
46
+ */
47
+ AtomicVaults?: {
48
+ [key: string]: AtomicVaultInfo;
49
+ };
41
50
  }
@@ -56,11 +56,34 @@ export interface ITxBuilderOptionalParams {
56
56
  txBlock?: TransactionBlock;
57
57
  gasBudget?: number;
58
58
  sender?: string;
59
+ /**
60
+ * Build the call against this package id instead of the deployment's.
61
+ *
62
+ * Guarded entry points abort unless invoked through the package whose
63
+ * compiled VERSION equals `ProtocolConfig.version`, so during an upgrade —
64
+ * new package published, version not yet increased — the callable package is
65
+ * the retired one, which no on-chain record names.
66
+ */
67
+ packageId?: string;
59
68
  }
60
69
  export interface IVaultOptionalParams extends ITxBuilderOptionalParams {
61
70
  dryRun?: boolean;
62
71
  returnTxb?: boolean;
63
72
  }
73
+ /** `version` and the protocol-wide pause flag from the shared ProtocolConfig. */
74
+ export interface IProtocolConfigState {
75
+ /** The package VERSION the protocol currently accepts, as a decimal string. */
76
+ version: string;
77
+ pauseNonAdminOperations: boolean;
78
+ }
79
+ /** Whether one package id can service a guarded call right now. */
80
+ export interface IPackageSupportResult {
81
+ packageId: string;
82
+ /** True when this package's compiled VERSION equals `ProtocolConfig.version`. */
83
+ supported: boolean;
84
+ /** Abort or resolution reason when `supported` is false. */
85
+ reason?: string;
86
+ }
64
87
  export interface ICancellationPendingWithdrawalRequest {
65
88
  sequence_number: NumStr;
66
89
  timestamp: NumStr;
@@ -1,8 +1,8 @@
1
1
  import { BaseClient as SuiClient } from "@mysten/sui/client";
2
2
  import { OnChainCalls } from "./onchain-calls.js";
3
- import { ISuiDeployment, IVaultOptionalParams } from "../interfaces/index.js";
3
+ import { IPackageSupportResult, IProtocolConfigState, ISuiDeployment, IVaultOptionalParams } from "../interfaces/index.js";
4
4
  import { OnChainCallResponse, Signer, SuiAddress, SuiTransactionBlockResponseOptions } from "@firefly-exchange/library-sui";
5
- import { NumStr } from "@firefly-exchange/library-sui";
5
+ import { Address, NumStr } from "@firefly-exchange/library-sui";
6
6
  export declare class AdminCalls extends OnChainCalls {
7
7
  constructor(_network: string, _suiClient: SuiClient, _deployment: ISuiDeployment, _signer?: Signer, _walletAddress?: string);
8
8
  /**
@@ -73,6 +73,61 @@ export declare class AdminCalls extends OnChainCalls {
73
73
  * @returns OnChainCallResponse
74
74
  */
75
75
  pauseNonAdminOperations(pause: boolean, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
76
+ /**
77
+ * Guardian fast-path for pausing/unpausing all non-admin protocol operations.
78
+ * Needs no AdminCap — the signer must be the address `set_guardian` recorded.
79
+ *
80
+ * Only executes through the package whose compiled VERSION matches
81
+ * `ProtocolConfig.version`; pass `options.packageId` (see
82
+ * {@link getSupportedPackageId}) to route through a retired one while an
83
+ * upgrade is half-applied.
84
+ * @param pause True to pause non admin operations, false to resume
85
+ * @param options Optional tx execution params
86
+ * @returns OnChainCallResponse
87
+ */
88
+ guardianPauseNonAdminOperations(pause: boolean, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
89
+ /**
90
+ * Set or clear the guardian address. AdminCap-gated.
91
+ * @param newGuardian The new guardian address, or the zero address to unset
92
+ * @param options Optional tx execution params
93
+ * @returns OnChainCallResponse
94
+ */
95
+ setGuardian(newGuardian: Address, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
96
+ /** Reader for the shared ProtocolConfig; rebuilt per call so a deployment update is picked up. */
97
+ private protocolConfigReader;
98
+ /**
99
+ * Read `version` and `pause_non_admin_operations` off the shared ProtocolConfig.
100
+ * @returns The package VERSION the protocol accepts, and the protocol-wide pause flag
101
+ */
102
+ getProtocolConfigState(): Promise<IProtocolConfigState>;
103
+ /**
104
+ * Read the guardian address. See {@link SuiProtocolConfigReader.getGuardian} —
105
+ * it is a dynamic field, so it never shows up in the ProtocolConfig's contents,
106
+ * and an absent field reads as the zero address.
107
+ * @returns The guardian address, or the zero address when unset
108
+ */
109
+ getGuardian(): Promise<Address>;
110
+ /**
111
+ * Ask the chain whether a package id is the one the protocol currently accepts,
112
+ * by simulating `admin::verify_supported_package` against it.
113
+ *
114
+ * The compiled VERSION has no getter, so running the assert is the only way to
115
+ * find out. Simulated with checks disabled, so it needs no gas and no signer.
116
+ * @param packageId Package id to test; defaults to the deployment's
117
+ * @returns Whether the package is supported, and the abort reason when it is not
118
+ */
119
+ isPackageSupported(packageId?: string): Promise<IPackageSupportResult>;
120
+ /**
121
+ * First of `candidatePackageIds` that the protocol currently accepts, probed in
122
+ * order. Callers pass the deployment's package id followed by retired ones, so
123
+ * a half-applied upgrade still resolves to something callable.
124
+ * @param candidatePackageIds Package ids to probe, most-preferred first
125
+ * @returns The supported package id (null if none) and every probe result
126
+ */
127
+ getSupportedPackageId(candidatePackageIds?: string[]): Promise<{
128
+ supportedPackageId: string | null;
129
+ probes: IPackageSupportResult[];
130
+ }>;
76
131
  /**
77
132
  * Increase the protocol version
78
133
  * @param options Optional tx execution params
@@ -1,5 +1,15 @@
1
1
  import { OnChainCalls } from "./onchain-calls.js";
2
+ import { SUI_ZERO_ADDRESS, SuiProtocolConfigReader } from "./protocol-config-reader.js";
2
3
  import { TransactionBlock } from "@firefly-exchange/library-sui";
4
+ /** Node resolution errors arrive percent-encoded. */
5
+ const decodeReason = (message) => {
6
+ try {
7
+ return decodeURIComponent(message);
8
+ }
9
+ catch {
10
+ return message;
11
+ }
12
+ };
3
13
  export class AdminCalls extends OnChainCalls {
4
14
  constructor(_network, _suiClient, _deployment, _signer, _walletAddress) {
5
15
  super(_network, _suiClient, _deployment, _signer, _walletAddress);
@@ -113,6 +123,116 @@ export class AdminCalls extends OnChainCalls {
113
123
  this.txBuilder.pauseNonAdminOperations(pause, { ...options, txBlock: txb });
114
124
  return this.execCall(txb, options);
115
125
  }
126
+ /**
127
+ * Guardian fast-path for pausing/unpausing all non-admin protocol operations.
128
+ * Needs no AdminCap — the signer must be the address `set_guardian` recorded.
129
+ *
130
+ * Only executes through the package whose compiled VERSION matches
131
+ * `ProtocolConfig.version`; pass `options.packageId` (see
132
+ * {@link getSupportedPackageId}) to route through a retired one while an
133
+ * upgrade is half-applied.
134
+ * @param pause True to pause non admin operations, false to resume
135
+ * @param options Optional tx execution params
136
+ * @returns OnChainCallResponse
137
+ */
138
+ async guardianPauseNonAdminOperations(pause, options) {
139
+ const txb = options?.txBlock || new TransactionBlock();
140
+ this.txBuilder.guardianPauseNonAdminOperations(pause, {
141
+ ...options,
142
+ txBlock: txb
143
+ });
144
+ return this.execCall(txb, options);
145
+ }
146
+ /**
147
+ * Set or clear the guardian address. AdminCap-gated.
148
+ * @param newGuardian The new guardian address, or the zero address to unset
149
+ * @param options Optional tx execution params
150
+ * @returns OnChainCallResponse
151
+ */
152
+ async setGuardian(newGuardian, options) {
153
+ const txb = options?.txBlock || new TransactionBlock();
154
+ this.txBuilder.setGuardian(newGuardian, { ...options, txBlock: txb });
155
+ return this.execCall(txb, options);
156
+ }
157
+ /** Reader for the shared ProtocolConfig; rebuilt per call so a deployment update is picked up. */
158
+ protocolConfigReader() {
159
+ return new SuiProtocolConfigReader(this.suiClient, this.parser.getProtocolConfig());
160
+ }
161
+ /**
162
+ * Read `version` and `pause_non_admin_operations` off the shared ProtocolConfig.
163
+ * @returns The package VERSION the protocol accepts, and the protocol-wide pause flag
164
+ */
165
+ async getProtocolConfigState() {
166
+ return this.protocolConfigReader().getProtocolConfigState();
167
+ }
168
+ /**
169
+ * Read the guardian address. See {@link SuiProtocolConfigReader.getGuardian} —
170
+ * it is a dynamic field, so it never shows up in the ProtocolConfig's contents,
171
+ * and an absent field reads as the zero address.
172
+ * @returns The guardian address, or the zero address when unset
173
+ */
174
+ async getGuardian() {
175
+ return this.protocolConfigReader().getGuardian();
176
+ }
177
+ /**
178
+ * Ask the chain whether a package id is the one the protocol currently accepts,
179
+ * by simulating `admin::verify_supported_package` against it.
180
+ *
181
+ * The compiled VERSION has no getter, so running the assert is the only way to
182
+ * find out. Simulated with checks disabled, so it needs no gas and no signer.
183
+ * @param packageId Package id to test; defaults to the deployment's
184
+ * @returns Whether the package is supported, and the abort reason when it is not
185
+ */
186
+ async isPackageSupported(packageId) {
187
+ const target = packageId || this.parser.getPackageId();
188
+ const txb = this.txBuilder.verifySupportedPackage({ packageId: target });
189
+ txb.setSender(SUI_ZERO_ADDRESS);
190
+ try {
191
+ const result = await this.suiClient.core.simulateTransaction({
192
+ transaction: txb,
193
+ checksEnabled: false
194
+ });
195
+ const simulated = result.Transaction ?? result.FailedTransaction;
196
+ const supported = result.$kind === "Transaction" &&
197
+ simulated?.status?.success === true;
198
+ return {
199
+ packageId: target,
200
+ supported,
201
+ reason: supported
202
+ ? undefined
203
+ : (simulated?.status?.error?.message ?? "unknown")
204
+ };
205
+ }
206
+ catch (error) {
207
+ // A package that predates the function fails at resolution rather than
208
+ // execution, and the node percent-encodes that message.
209
+ return {
210
+ packageId: target,
211
+ supported: false,
212
+ reason: decodeReason(error?.message ?? "unknown")
213
+ };
214
+ }
215
+ }
216
+ /**
217
+ * First of `candidatePackageIds` that the protocol currently accepts, probed in
218
+ * order. Callers pass the deployment's package id followed by retired ones, so
219
+ * a half-applied upgrade still resolves to something callable.
220
+ * @param candidatePackageIds Package ids to probe, most-preferred first
221
+ * @returns The supported package id (null if none) and every probe result
222
+ */
223
+ async getSupportedPackageId(candidatePackageIds) {
224
+ const candidates = candidatePackageIds && candidatePackageIds.length > 0
225
+ ? candidatePackageIds
226
+ : [this.parser.getPackageId()];
227
+ const probes = [];
228
+ for (const candidate of candidates) {
229
+ probes.push(await this.isPackageSupported(candidate));
230
+ }
231
+ return {
232
+ supportedPackageId: probes.find(p => p.supported)?.packageId ?? null,
233
+ probes
234
+ };
235
+ }
116
236
  /**
117
237
  * Increase the protocol version
118
238
  * @param options Optional tx execution params
@@ -5,3 +5,4 @@ export * from "./vault-admin.js";
5
5
  export * from "./operator.js";
6
6
  export * from "./vault.js";
7
7
  export * from "./atomic-liquidity.js";
8
+ export * from "./protocol-config-reader.js";
@@ -5,3 +5,4 @@ export * from "./vault-admin.js";
5
5
  export * from "./operator.js";
6
6
  export * from "./vault.js";
7
7
  export * from "./atomic-liquidity.js";
8
+ export * from "./protocol-config-reader.js";
@@ -0,0 +1,24 @@
1
+ import { BaseClient as SuiClient } from "@mysten/sui/client";
2
+ import { IProtocolConfigState } from "../interfaces/index.js";
3
+ /** The protocol's sentinel for "no guardian". */
4
+ export declare const SUI_ZERO_ADDRESS: string;
5
+ export declare class SuiProtocolConfigReader {
6
+ suiClient: SuiClient;
7
+ protocolConfigId: string;
8
+ constructor(_suiClient: SuiClient, _protocolConfigId: string);
9
+ /**
10
+ * Read `version` and `pause_non_admin_operations`.
11
+ * @returns The package VERSION the protocol accepts, and the protocol-wide pause flag
12
+ */
13
+ getProtocolConfigState(): Promise<IProtocolConfigState>;
14
+ /**
15
+ * Read the guardian address.
16
+ *
17
+ * The guardian is a dynamic field keyed by `b"guardian"`, not a struct field,
18
+ * so it never appears in the ProtocolConfig's contents. An absent field means
19
+ * the guardian was never set or has been cleared, which the protocol
20
+ * represents as the zero address.
21
+ * @returns The guardian address, or the zero address when unset
22
+ */
23
+ getGuardian(): Promise<string>;
24
+ }
@@ -0,0 +1,67 @@
1
+ import { bcs } from "@mysten/sui/bcs";
2
+ import { normalizeSuiAddress } from "@mysten/sui/utils";
3
+ /** Matches `KEY_GUARDIAN` in `admin.move`. */
4
+ const GUARDIAN_FIELD_KEY = "guardian";
5
+ /** The protocol's sentinel for "no guardian". */
6
+ export const SUI_ZERO_ADDRESS = normalizeSuiAddress("0x0");
7
+ /** gRPC flattens Move structs; JSON-RPC keeps a `fields` wrapper. */
8
+ const unwrapMoveFields = (value) => value?.fields ?? value;
9
+ export class SuiProtocolConfigReader {
10
+ constructor(_suiClient, _protocolConfigId) {
11
+ this.suiClient = _suiClient;
12
+ this.protocolConfigId = _protocolConfigId;
13
+ }
14
+ /**
15
+ * Read `version` and `pause_non_admin_operations`.
16
+ * @returns The package VERSION the protocol accepts, and the protocol-wide pause flag
17
+ */
18
+ async getProtocolConfigState() {
19
+ const res = await this.suiClient.core.getObject({
20
+ objectId: this.protocolConfigId,
21
+ include: { json: true }
22
+ });
23
+ const fields = unwrapMoveFields(res.object?.json);
24
+ if (!fields || fields.version === undefined) {
25
+ throw new Error(`ProtocolConfig ${this.protocolConfigId} not found`);
26
+ }
27
+ return {
28
+ version: String(fields.version),
29
+ pauseNonAdminOperations: Boolean(fields.pause_non_admin_operations)
30
+ };
31
+ }
32
+ /**
33
+ * Read the guardian address.
34
+ *
35
+ * The guardian is a dynamic field keyed by `b"guardian"`, not a struct field,
36
+ * so it never appears in the ProtocolConfig's contents. An absent field means
37
+ * the guardian was never set or has been cleared, which the protocol
38
+ * represents as the zero address.
39
+ * @returns The guardian address, or the zero address when unset
40
+ */
41
+ async getGuardian() {
42
+ try {
43
+ const df = await this.suiClient.core.getDynamicField({
44
+ parentId: this.protocolConfigId,
45
+ name: {
46
+ type: "vector<u8>",
47
+ bcs: bcs
48
+ .vector(bcs.u8())
49
+ .serialize(new TextEncoder().encode(GUARDIAN_FIELD_KEY))
50
+ .toBytes()
51
+ }
52
+ });
53
+ const fieldId = df?.dynamicField?.fieldId;
54
+ if (!fieldId)
55
+ return SUI_ZERO_ADDRESS;
56
+ const obj = await this.suiClient.core.getObject({
57
+ objectId: fieldId,
58
+ include: { json: true }
59
+ });
60
+ const value = unwrapMoveFields(obj.object?.json)?.value;
61
+ return value ? normalizeSuiAddress(String(value)) : SUI_ZERO_ADDRESS;
62
+ }
63
+ catch {
64
+ return SUI_ZERO_ADDRESS;
65
+ }
66
+ }
67
+ }
@@ -1,6 +1,6 @@
1
1
  import { SuiDeploymentParser } from "../utils/index.js";
2
2
  import { ISuiDeployment, ITxBuilderOptionalParams } from "../interfaces/index.js";
3
- import { NumStr, TransactionBlock } from "@firefly-exchange/library-sui";
3
+ import { Address, NumStr, TransactionBlock } from "@firefly-exchange/library-sui";
4
4
  export declare class TxBuilder {
5
5
  parser: SuiDeploymentParser;
6
6
  constructor(_deployment: ISuiDeployment);
@@ -9,6 +9,13 @@ export declare class TxBuilder {
9
9
  * @param newDeployment The new deployment configuration
10
10
  */
11
11
  updateDeployment(newDeployment: ISuiDeployment): void;
12
+ /**
13
+ * Package id to build the call against: the caller's override when given,
14
+ * otherwise the deployment's. An override exists because a guarded call only
15
+ * executes through the package whose compiled VERSION matches
16
+ * `ProtocolConfig.version`, which is not always the newest one.
17
+ */
18
+ protected targetPackageId(options?: ITxBuilderOptionalParams): string;
12
19
  /**
13
20
  * Pauses or unpauses the non-admin operations
14
21
  * @param pause True if the non-admin operations should be paused, false otherwise
@@ -16,6 +23,40 @@ export declare class TxBuilder {
16
23
  * @returns TransactionBlock
17
24
  */
18
25
  pauseNonAdminOperations(pause: boolean, options?: ITxBuilderOptionalParams): TransactionBlock;
26
+ /**
27
+ * Guardian fast-path for pausing/unpausing all non-admin protocol operations.
28
+ * Callable directly by the guardian address — no AdminCap — and so the lever
29
+ * used during an incident.
30
+ *
31
+ * Aborts with EUnsupportedPackage (1000) unless it is invoked through the
32
+ * package whose compiled VERSION matches `ProtocolConfig.version`; pass
33
+ * `options.packageId` to route through a retired package while an upgrade is
34
+ * half-applied. See {@link verifySupportedPackage}.
35
+ * @param pause True to pause non admin operations, false to resume
36
+ * @param options Optional tx building params
37
+ * @returns TransactionBlock
38
+ */
39
+ guardianPauseNonAdminOperations(pause: boolean, options?: ITxBuilderOptionalParams): TransactionBlock;
40
+ /**
41
+ * Sets or clears the guardian address. AdminCap-gated. Pass the zero address
42
+ * to unset, which makes every guardian-gated entry point unreachable.
43
+ * @param newGuardian The new guardian address, or `0x0` to unset
44
+ * @param options Optional tx building params
45
+ * @returns TransactionBlock
46
+ */
47
+ setGuardian(newGuardian: Address, options?: ITxBuilderOptionalParams): TransactionBlock;
48
+ /**
49
+ * Asserts `ProtocolConfig.version` equals the VERSION compiled into the target
50
+ * package, aborting EUnsupportedPackage (1000) otherwise.
51
+ *
52
+ * On its own this changes nothing; it is built to be simulated. The compiled
53
+ * VERSION has no getter, so running this assert is the only way to ask whether
54
+ * a given package id is the one the protocol currently accepts — and it is the
55
+ * same check every guarded entry point performs first.
56
+ * @param options Optional tx building params; `packageId` selects the package to test
57
+ * @returns TransactionBlock
58
+ */
59
+ verifySupportedPackage(options?: ITxBuilderOptionalParams): TransactionBlock;
19
60
  /**
20
61
  * Increases the version of the protocol supported. Only admin can invoke this
21
62
  * @param options Optional tx building params
@@ -12,6 +12,15 @@ export class TxBuilder {
12
12
  updateDeployment(newDeployment) {
13
13
  this.parser.updateDeployment(newDeployment);
14
14
  }
15
+ /**
16
+ * Package id to build the call against: the caller's override when given,
17
+ * otherwise the deployment's. An override exists because a guarded call only
18
+ * executes through the package whose compiled VERSION matches
19
+ * `ProtocolConfig.version`, which is not always the newest one.
20
+ */
21
+ targetPackageId(options) {
22
+ return options?.packageId || this.parser.getPackageId();
23
+ }
15
24
  /**
16
25
  * Pauses or unpauses the non-admin operations
17
26
  * @param pause True if the non-admin operations should be paused, false otherwise
@@ -34,6 +43,80 @@ export class TxBuilder {
34
43
  txb.setSenderIfNotSet(options.sender);
35
44
  return txb;
36
45
  }
46
+ /**
47
+ * Guardian fast-path for pausing/unpausing all non-admin protocol operations.
48
+ * Callable directly by the guardian address — no AdminCap — and so the lever
49
+ * used during an incident.
50
+ *
51
+ * Aborts with EUnsupportedPackage (1000) unless it is invoked through the
52
+ * package whose compiled VERSION matches `ProtocolConfig.version`; pass
53
+ * `options.packageId` to route through a retired package while an upgrade is
54
+ * half-applied. See {@link verifySupportedPackage}.
55
+ * @param pause True to pause non admin operations, false to resume
56
+ * @param options Optional tx building params
57
+ * @returns TransactionBlock
58
+ */
59
+ guardianPauseNonAdminOperations(pause, options) {
60
+ const txb = options?.txBlock || new TransactionBlock();
61
+ txb.moveCall({
62
+ arguments: [
63
+ txb.object(this.parser.getProtocolConfig()),
64
+ txb.pure.bool(pause)
65
+ ],
66
+ target: `${this.targetPackageId(options)}::gateway::guardian_pause_non_admin_operations`
67
+ });
68
+ if (options?.gasBudget)
69
+ txb.setGasBudget(options.gasBudget);
70
+ if (options?.sender)
71
+ txb.setSenderIfNotSet(options.sender);
72
+ return txb;
73
+ }
74
+ /**
75
+ * Sets or clears the guardian address. AdminCap-gated. Pass the zero address
76
+ * to unset, which makes every guardian-gated entry point unreachable.
77
+ * @param newGuardian The new guardian address, or `0x0` to unset
78
+ * @param options Optional tx building params
79
+ * @returns TransactionBlock
80
+ */
81
+ setGuardian(newGuardian, options) {
82
+ const txb = options?.txBlock || new TransactionBlock();
83
+ txb.moveCall({
84
+ arguments: [
85
+ txb.object(this.parser.getProtocolConfig()),
86
+ txb.object(this.parser.getAdminCap()),
87
+ txb.pure.address(newGuardian)
88
+ ],
89
+ target: `${this.targetPackageId(options)}::gateway::set_guardian`
90
+ });
91
+ if (options?.gasBudget)
92
+ txb.setGasBudget(options.gasBudget);
93
+ if (options?.sender)
94
+ txb.setSenderIfNotSet(options.sender);
95
+ return txb;
96
+ }
97
+ /**
98
+ * Asserts `ProtocolConfig.version` equals the VERSION compiled into the target
99
+ * package, aborting EUnsupportedPackage (1000) otherwise.
100
+ *
101
+ * On its own this changes nothing; it is built to be simulated. The compiled
102
+ * VERSION has no getter, so running this assert is the only way to ask whether
103
+ * a given package id is the one the protocol currently accepts — and it is the
104
+ * same check every guarded entry point performs first.
105
+ * @param options Optional tx building params; `packageId` selects the package to test
106
+ * @returns TransactionBlock
107
+ */
108
+ verifySupportedPackage(options) {
109
+ const txb = options?.txBlock || new TransactionBlock();
110
+ txb.moveCall({
111
+ arguments: [txb.object(this.parser.getProtocolConfig())],
112
+ target: `${this.targetPackageId(options)}::admin::verify_supported_package`
113
+ });
114
+ if (options?.gasBudget)
115
+ txb.setGasBudget(options.gasBudget);
116
+ if (options?.sender)
117
+ txb.setSenderIfNotSet(options.sender);
118
+ return txb;
119
+ }
37
120
  /**
38
121
  * Increases the version of the protocol supported. Only admin can invoke this
39
122
  * @param options Optional tx building params
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.16.0",
4
+ "version": "2.18.0",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
7
7
  "main": "./dist/index.js",