diff --git a/package-lock.json b/package-lock.json index 099c838..d5e4d05 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0-beta.14", "license": "Apache-2.0", "dependencies": { - "@tetherto/wdk-wallet": "^1.0.0-beta.13", + "@tetherto/wdk-wallet": "^1.0.0-beta.15", "bare-node-runtime": "^1.4.0", "zod": "^4.4.3" }, @@ -1293,9 +1293,9 @@ } }, "node_modules/@tetherto/wdk-wallet": { - "version": "1.0.0-beta.13", - "resolved": "https://registry.npmjs.org/@tetherto/wdk-wallet/-/wdk-wallet-1.0.0-beta.13.tgz", - "integrity": "sha512-0lF6TVxcgui/uLpU54x+3+qcAiypiMhJhnHbnHlyCxwKNjpzncq2DsJwJg/IeyeH1mm2wKWE4QqOohRr/VQbwA==", + "version": "1.0.0-beta.15", + "resolved": "https://registry.npmjs.org/@tetherto/wdk-wallet/-/wdk-wallet-1.0.0-beta.15.tgz", + "integrity": "sha512-gGfEEwPDgQkRpoXW6O7e9B5O3Ys1ZCoFF8eHHoyPwlRZE2bfWC9UfBT8X4b33iMAOL0ieEaTdn1TVqVx3j33kg==", "license": "Apache-2.0", "dependencies": { "bare-node-runtime": "^1.4.0", diff --git a/package.json b/package.json index 03fca1f..0301e9b 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage" }, "dependencies": { - "@tetherto/wdk-wallet": "^1.0.0-beta.13", + "@tetherto/wdk-wallet": "^1.0.0-beta.15", "bare-node-runtime": "^1.4.0", "zod": "^4.4.3" }, diff --git a/src/policy/constants.js b/src/policy/constants.js index 432148a..1bf0b2b 100644 --- a/src/policy/constants.js +++ b/src/policy/constants.js @@ -36,7 +36,11 @@ export const OPERATIONS = [ 'repay', 'buy', 'sell', - 'swidge' + 'swidge', + 'createDepositAddress', + 'renewDepositAddress', + 'recoverDepositAddress', + 'disableDepositAddress' ] export const WILDCARD = '*' @@ -50,5 +54,6 @@ export const PROTOCOL_METHODS = { bridge: ['bridge'], lending: ['supply', 'withdraw', 'borrow', 'repay'], fiat: ['buy', 'sell'], - swidge: ['swidge'] + swidge: ['swidge'], + sda: ['createDepositAddress', 'renewDepositAddress', 'recoverDepositAddress', 'disableDepositAddress'] } diff --git a/src/policy/policy-account-proxy.js b/src/policy/policy-account-proxy.js index 24ff79b..4b2c8db 100644 --- a/src/policy/policy-account-proxy.js +++ b/src/policy/policy-account-proxy.js @@ -27,7 +27,8 @@ const PROTOCOL_GETTERS = [ ['getBridgeProtocol', 'bridge'], ['getLendingProtocol', 'lending'], ['getFiatProtocol', 'fiat'], - ['getSwidgeProtocol', 'swidge'] + ['getSwidgeProtocol', 'swidge'], + ['getSdaProtocol', 'sda'] ] /** diff --git a/src/policy/policy-engine.js b/src/policy/policy-engine.js index 6abfab7..18d43d9 100644 --- a/src/policy/policy-engine.js +++ b/src/policy/policy-engine.js @@ -45,7 +45,8 @@ import { * @typedef {'sendTransaction' | 'signTransaction' | 'transfer' | 'approve' * | 'sign' | 'signTypedData' | 'signAuthorization' | 'delegate' | 'revokeDelegation' * | 'swap' | 'bridge' | 'supply' | 'withdraw' | 'borrow' | 'repay' | 'buy' | 'sell' - * | 'swidge' | '*'} PolicyOperation + * | 'swidge' | 'createDepositAddress' | 'renewDepositAddress' + * | 'recoverDepositAddress' | 'disableDepositAddress' | '*'} PolicyOperation */ /** diff --git a/src/wallet-account-with-protocols.js b/src/wallet-account-with-protocols.js index 81ea892..9b6890f 100644 --- a/src/wallet-account-with-protocols.js +++ b/src/wallet-account-with-protocols.js @@ -17,27 +17,26 @@ import { IWalletAccount, NotImplementedError } from '@tetherto/wdk-wallet' /** @typedef {import('@tetherto/wdk-wallet/protocols').ISwapProtocol} ISwapProtocol */ -/** @typedef {typeof import('@tetherto/wdk-wallet/protocols').SwapProtocol} SwapProtocolCtor */ - /** @typedef {import('@tetherto/wdk-wallet/protocols').IBridgeProtocol} IBridgeProtocol */ -/** @typedef {typeof import('@tetherto/wdk-wallet/protocols').BridgeProtocol} BridgeProtocolCtor */ - /** @typedef {import('@tetherto/wdk-wallet/protocols').ILendingProtocol} ILendingProtocol */ -/** @typedef {typeof import('@tetherto/wdk-wallet/protocols').LendingProtocol} LendingProtocolCtor */ - /** @typedef {import('@tetherto/wdk-wallet/protocols').IFiatProtocol} IFiatProtocol */ -/** @typedef {typeof import('@tetherto/wdk-wallet/protocols').FiatProtocol} FiatProtocolCtor */ - /** @typedef {import('@tetherto/wdk-wallet/protocols').ISwidgeProtocol} ISwidgeProtocol */ -/** @typedef {typeof import('@tetherto/wdk-wallet/protocols').SwidgeProtocol} SwidgeProtocolCtor */ +/** @typedef {import('@tetherto/wdk-wallet/protocols').ISdaProtocol} ISdaProtocol */ + +/** @typedef {import('@tetherto/wdk-wallet/protocols').SwapProtocol} SwapProtocol */ +/** @typedef {import('@tetherto/wdk-wallet/protocols').BridgeProtocol} BridgeProtocol */ +/** @typedef {import('@tetherto/wdk-wallet/protocols').LendingProtocol} LendingProtocol */ +/** @typedef {import('@tetherto/wdk-wallet/protocols').FiatProtocol} FiatProtocol */ +/** @typedef {import('@tetherto/wdk-wallet/protocols').SwidgeProtocol} SwidgeProtocol */ +/** @typedef {import('@tetherto/wdk-wallet/protocols').SdaProtocol} SdaProtocol */ /** * Interface for wallet accounts that also expose the WDK's protocol-getter * helpers (`registerProtocol`, `getSwapProtocol`, `getBridgeProtocol`, - * `getLendingProtocol`, `getFiatProtocol`, `getSwidgeProtocol`). The - * concrete shape is materialized at runtime by `wdk.getAccount` / - * `getAccountByPath` after middlewares and protocol getters have been - * installed. See `WdkAccount` for the consumer-facing type that pairs + * `getLendingProtocol`, `getFiatProtocol`, `getSwidgeProtocol`, + * `getSdaProtocol`). The concrete shape is materialized at runtime by + * `wdk.getAccount` / `getAccountByPath` after middlewares and protocol getters + * have been installed. See `WdkAccount` for the consumer-facing type that pairs * this surface with the underlying `IWalletAccount` shape. * * @interface @@ -49,7 +48,7 @@ export class IWalletAccountWithProtocols extends IWalletAccount { * The label must be unique in the scope of the account and the type of protocol (i.e., there can’t be two protocols of the same * type bound to the same account with the same label). * - * @template {SwapProtocolCtor | BridgeProtocolCtor | LendingProtocolCtor | FiatProtocolCtor | SwidgeProtocolCtor} P + * @template {typeof SwapProtocol | typeof BridgeProtocol | typeof LendingProtocol | typeof FiatProtocol | typeof SwidgeProtocol | typeof SdaProtocol} P * @param {string} label - The label. * @param {P} Protocol - The protocol class. * @param {ConstructorParameters
[1]} config - The protocol configuration. @@ -113,4 +112,15 @@ export class IWalletAccountWithProtocols extends IWalletAccount { getSwidgeProtocol (label) { throw new NotImplementedError('getSwidgeProtocol(label)') } + + /** + * Returns the SDA protocol with the given label. + * + * @param {string} label - The label. + * @returns {ISdaProtocol} The SDA protocol. + * @throws {Error} If no SDA protocol has been registered on this account with the given label. + */ + getSdaProtocol (label) { + throw new NotImplementedError('getSdaProtocol(label)') + } } diff --git a/src/wdk.js b/src/wdk.js index 53e55cd..5d616ab 100644 --- a/src/wdk.js +++ b/src/wdk.js @@ -16,7 +16,7 @@ import WalletManager from '@tetherto/wdk-wallet' -import { SwapProtocol, BridgeProtocol, LendingProtocol, FiatProtocol, SwidgeProtocol } from '@tetherto/wdk-wallet/protocols' +import { SwapProtocol, BridgeProtocol, LendingProtocol, FiatProtocol, SwidgeProtocol, SdaProtocol } from '@tetherto/wdk-wallet/protocols' import PolicyEngine from './policy/policy-engine.js' @@ -74,7 +74,7 @@ export default class WDK { this._wallets = new Map() /** @private */ - this._protocols = { swap: Object.create(null), bridge: Object.create(null), lending: Object.create(null), fiat: Object.create(null), swidge: Object.create(null) } + this._protocols = { swap: Object.create(null), bridge: Object.create(null), lending: Object.create(null), fiat: Object.create(null), swidge: Object.create(null), sda: Object.create(null) } /** @private */ this._middlewares = Object.create(null) @@ -139,7 +139,7 @@ export default class WDK { * same type bound to the same blockchain with the same label). * * @see {@link IWalletAccountWithProtocols#registerProtocol} to register protocols only for specific accounts. - * @template {typeof SwapProtocol | typeof BridgeProtocol | typeof LendingProtocol | typeof FiatProtocol | typeof SwidgeProtocol} P + * @template {typeof SwapProtocol | typeof BridgeProtocol | typeof LendingProtocol | typeof FiatProtocol | typeof SwidgeProtocol | typeof SdaProtocol} P * @param {string} blockchain - The name of the blockchain the protocol must be bound to. Can be any string (e.g., "ethereum"). * @param {string} label - The label. * @param {P} Protocol - The protocol class. @@ -151,6 +151,10 @@ export default class WDK { this._protocols.swidge[blockchain] ??= Object.create(null) this._protocols.swidge[blockchain][label] = { Protocol, config } + } else if (Protocol.prototype instanceof SdaProtocol) { + this._protocols.sda[blockchain] ??= Object.create(null) + + this._protocols.sda[blockchain][label] = { Protocol, config } } else if (Protocol.prototype instanceof SwapProtocol) { this._protocols.swap[blockchain] ??= Object.create(null) @@ -322,13 +326,15 @@ export default class WDK { _registerProtocols (account, { blockchain }) { if (this._decoratedAccounts.has(account)) return - const protocols = { swap: Object.create(null), bridge: Object.create(null), lending: Object.create(null), fiat: Object.create(null), swidge: Object.create(null) } + const protocols = { swap: Object.create(null), bridge: Object.create(null), lending: Object.create(null), fiat: Object.create(null), swidge: Object.create(null), sda: Object.create(null) } this._decoratedAccounts.add(account) account.registerProtocol = (label, Protocol, config) => { if (Protocol.prototype instanceof SwidgeProtocol) { protocols.swidge[label] = new Protocol(account, config) + } else if (Protocol.prototype instanceof SdaProtocol) { + protocols.sda[label] = new Protocol(account, config) } else if (Protocol.prototype instanceof SwapProtocol) { protocols.swap[label] = new Protocol(account, config) } else if (Protocol.prototype instanceof BridgeProtocol) { @@ -421,5 +427,21 @@ export default class WDK { throw new Error(`No swidge protocol registered for label: ${label}.`) } + + account.getSdaProtocol = (label) => { + if (this._protocols.sda[blockchain]?.[label]) { + const { Protocol, config } = this._protocols.sda[blockchain][label] + + const protocol = new Protocol(account, config) + + return protocol + } + + if (protocols.sda[label]) { + return protocols.sda[label] + } + + throw new Error(`No sda protocol registered for label: ${label}.`) + } } } diff --git a/tests/wdk-policy.test.js b/tests/wdk-policy.test.js index e9b8928..f7ae086 100644 --- a/tests/wdk-policy.test.js +++ b/tests/wdk-policy.test.js @@ -4,7 +4,7 @@ import { beforeEach, describe, expect, jest, test } from '@jest/globals' import WalletManager from '@tetherto/wdk-wallet' -import { BridgeProtocol, SwapProtocol, SwidgeProtocol } from '@tetherto/wdk-wallet/protocols' +import { BridgeProtocol, SdaProtocol, SwapProtocol, SwidgeProtocol } from '@tetherto/wdk-wallet/protocols' import WDK, { PolicyConfigurationError, PolicyViolationError } from '../index.js' @@ -19,6 +19,8 @@ const DUMMY_QUOTE = { fee: 1n } const DUMMY_SWAP_RESULT = { hash: '0xdummy-swap-hash' } const DUMMY_BRIDGE_RESULT = { hash: '0xdummy-bridge-hash' } const DUMMY_SWIDGE_RESULT = { hash: '0xdummy-swidge-hash' } +const DUMMY_SDA_ADDRESS_RESULT = [{ address: '0xdummy-deposit-address' }] +const DUMMY_SDA_ROUTES = [{ sourceChains: ['arbitrum'], destinationChain: 'polygon' }] const DUMMY_SIGNED_TX = '0xdummy-signed-tx' // Test inputs (no DUMMY_ prefix per CQ5). Addresses are valid EVM shape @@ -1798,6 +1800,73 @@ describe('WDK — policy engine', () => { expect(swidgeInstanceMock).not.toHaveBeenCalled() }) + test('an sda protocol write method (createDepositAddress) is wrapped and blocks on DENY; getSupportedRoutes is not wrapped', async () => { + const createDepositAddressInstanceMock = jest.fn().mockResolvedValue(DUMMY_SDA_ADDRESS_RESULT) + const getSupportedRoutesInstanceMock = jest.fn().mockResolvedValue(DUMMY_SDA_ROUTES) + + class MySdaProtocol extends SdaProtocol { + constructor () { super() } + async createDepositAddress (opts) { return createDepositAddressInstanceMock(opts) } + async getSupportedRoutes (opts) { return getSupportedRoutesInstanceMock(opts) } + } + + getAccountMock.mockResolvedValue(buildAccount()) + + wdk + .registerWallet('ethereum', WalletManagerMock, {}) + .registerProtocol('ethereum', 'accumulate', MySdaProtocol, {}) + .registerPolicy({ + id: 'no-sda', + name: 'no-sda', + scope: 'project', + rules: [{ name: 'deny-create-deposit', operation: 'createDepositAddress', action: 'DENY', conditions: [] }] + }) + + const account = await wdk.getAccount('ethereum', 0) + const sda = account.getSdaProtocol('accumulate') + + const denied = await catchAsync(() => sda.createDepositAddress({ sourceChains: ['arbitrum'], destinationChain: 'polygon' })) + + expect(denied.name).toBe('PolicyViolationError') + expect(denied.policyId).toBe('no-sda') + expect(denied.ruleName).toBe('deny-create-deposit') + expect(createDepositAddressInstanceMock).not.toHaveBeenCalled() + + const routes = await sda.getSupportedRoutes({}) + expect(routes).toEqual(DUMMY_SDA_ROUTES) + expect(getSupportedRoutesInstanceMock).toHaveBeenCalledWith({}) + }) + + test('account.simulate.getSdaProtocol(label).createDepositAddress(...) returns a structured DENY without executing', async () => { + const createDepositAddressInstanceMock = jest.fn().mockResolvedValue(DUMMY_SDA_ADDRESS_RESULT) + + class MySdaProtocol extends SdaProtocol { + constructor () { super() } + async createDepositAddress (opts) { return createDepositAddressInstanceMock(opts) } + } + + getAccountMock.mockResolvedValue(buildAccount()) + + wdk + .registerWallet('ethereum', WalletManagerMock, {}) + .registerProtocol('ethereum', 'accumulate', MySdaProtocol, {}) + .registerPolicy({ + id: 'no-sda', + name: 'no-sda', + scope: 'project', + rules: [{ name: 'deny-create-deposit', operation: 'createDepositAddress', action: 'DENY', conditions: [] }] + }) + + const account = await wdk.getAccount('ethereum', 0) + const sim = await account.simulate.getSdaProtocol('accumulate').createDepositAddress({ sourceChains: ['arbitrum'], destinationChain: 'polygon' }) + + expect(sim.decision).toBe('DENY') + expect(sim.policy_id).toBe('no-sda') + expect(sim.matched_rule).toBe('deny-create-deposit') + expect(sim.reason).toBe('deny-create-deposit') + expect(createDepositAddressInstanceMock).not.toHaveBeenCalled() + }) + test('account.registerProtocol(...) returns the proxy so chained calls stay enforced (C-2)', async () => { // Regression for C-2: without intercepting registerProtocol in the // proxy's get trap, the underlying _registerProtocols closure hands diff --git a/tests/wdk.test.js b/tests/wdk.test.js index da22c5b..04691ef 100644 --- a/tests/wdk.test.js +++ b/tests/wdk.test.js @@ -4,7 +4,7 @@ import { beforeEach, describe, expect, jest, test } from '@jest/globals' import WalletManager from '@tetherto/wdk-wallet' -import { BridgeProtocol, LendingProtocol, SwapProtocol, SwidgeProtocol } from '@tetherto/wdk-wallet/protocols' +import { BridgeProtocol, LendingProtocol, SdaProtocol, SwapProtocol, SwidgeProtocol } from '@tetherto/wdk-wallet/protocols' import WDK from '../index.js' @@ -316,6 +316,65 @@ describe('WDK', () => { expect(sameAccount.getSwidgeProtocol('test')).toBeInstanceOf(SwidgeProtocolMock) }) }) + + describe('getSdaProtocol', () => { + const SDA_CONFIG = { apiKey: 'dummy-key' } + + let SdaProtocolMock + + beforeEach(() => { + SdaProtocolMock = jest.fn() + + Object.setPrototypeOf(SdaProtocolMock.prototype, SdaProtocol.prototype) + }) + + test("should return the sda protocol registered for the account's blockchain and the given label", async () => { + wdk.registerWallet('ethereum', WalletManagerMock, CONFIG) + .registerProtocol('ethereum', 'test', SdaProtocolMock, SDA_CONFIG) + + const account = await wdk.getAccount('ethereum', 0) + + const protocol = account.getSdaProtocol('test') + + expect(SdaProtocolMock).toHaveBeenCalledWith(account, SDA_CONFIG) + + expect(protocol).toBeInstanceOf(SdaProtocolMock) + }) + + test('should return the sda protocol registered for the account and the given label', async () => { + wdk.registerWallet('ethereum', WalletManagerMock, CONFIG) + + const account = await wdk.getAccount('ethereum', 0) + + account.registerProtocol('test', SdaProtocolMock, SDA_CONFIG) + + const protocol = account.getSdaProtocol('test') + + expect(SdaProtocolMock).toHaveBeenCalledWith(account, SDA_CONFIG) + + expect(protocol).toBeInstanceOf(SdaProtocolMock) + }) + + test('should throw if no sda protocol has been registered for the given label', async () => { + wdk.registerWallet('ethereum', WalletManagerMock, CONFIG) + + const account = await wdk.getAccount('ethereum', 0) + + expect(() => account.getSdaProtocol('test')) + .toThrow('No sda protocol registered for label: test.') + }) + + test('should preserve account-scoped protocols across repeated getAccount calls', async () => { + wdk.registerWallet('ethereum', WalletManagerMock, CONFIG) + + const account = await wdk.getAccount('ethereum', 0) + account.registerProtocol('test', SdaProtocolMock, SDA_CONFIG) + + const sameAccount = await wdk.getAccount('ethereum', 0) + + expect(sameAccount.getSdaProtocol('test')).toBeInstanceOf(SdaProtocolMock) + }) + }) }) }) @@ -544,6 +603,54 @@ describe('WDK', () => { .toThrow('No swidge protocol registered for label: test.') }) }) + + describe('getSdaProtocol', () => { + const SDA_CONFIG = { apiKey: 'dummy-key' } + + let SdaProtocolMock + + beforeEach(() => { + SdaProtocolMock = jest.fn() + + Object.setPrototypeOf(SdaProtocolMock.prototype, SdaProtocol.prototype) + }) + + test("should return the sda protocol registered for the account's blockchain and the given label", async () => { + wdk.registerWallet('ethereum', WalletManagerMock, CONFIG) + .registerProtocol('ethereum', 'test', SdaProtocolMock, SDA_CONFIG) + + const account = await wdk.getAccountByPath('ethereum', "0'/0/0") + + const protocol = account.getSdaProtocol('test') + + expect(SdaProtocolMock).toHaveBeenCalledWith(account, SDA_CONFIG) + + expect(protocol).toBeInstanceOf(SdaProtocolMock) + }) + + test('should return the sda protocol registered for the account and the given label', async () => { + wdk.registerWallet('ethereum', WalletManagerMock, CONFIG) + + const account = await wdk.getAccountByPath('ethereum', "0'/0/0") + + account.registerProtocol('test', SdaProtocolMock, SDA_CONFIG) + + const protocol = account.getSdaProtocol('test') + + expect(SdaProtocolMock).toHaveBeenCalledWith(account, SDA_CONFIG) + + expect(protocol).toBeInstanceOf(SdaProtocolMock) + }) + + test('should throw if no sda protocol has been registered for the given label', async () => { + wdk.registerWallet('ethereum', WalletManagerMock, CONFIG) + + const account = await wdk.getAccountByPath('ethereum', "0'/0/0") + + expect(() => account.getSdaProtocol('test')) + .toThrow('No sda protocol registered for label: test.') + }) + }) }) }) diff --git a/types/src/policy/constants.d.ts b/types/src/policy/constants.d.ts index fd3403a..2e0e03e 100644 --- a/types/src/policy/constants.d.ts +++ b/types/src/policy/constants.d.ts @@ -8,4 +8,5 @@ export namespace PROTOCOL_METHODS { let lending: string[]; let fiat: string[]; let swidge: string[]; + let sda: string[]; } diff --git a/types/src/policy/policy-engine.d.ts b/types/src/policy/policy-engine.d.ts index d409a19..0af69ff 100644 --- a/types/src/policy/policy-engine.d.ts +++ b/types/src/policy/policy-engine.d.ts @@ -65,7 +65,7 @@ export type PolicyScope = "project" | "account"; * A wrapped operation name from the supported set, or `*` to match any wrapped operation. * Each name must match an actual method on `IWalletAccount` or a registered protocol. */ -export type PolicyOperation = "sendTransaction" | "signTransaction" | "transfer" | "approve" | "sign" | "signTypedData" | "signAuthorization" | "delegate" | "revokeDelegation" | "swap" | "bridge" | "supply" | "withdraw" | "borrow" | "repay" | "buy" | "sell" | "swidge" | "*"; +export type PolicyOperation = "sendTransaction" | "signTransaction" | "transfer" | "approve" | "sign" | "signTypedData" | "signAuthorization" | "delegate" | "revokeDelegation" | "swap" | "bridge" | "supply" | "withdraw" | "borrow" | "repay" | "buy" | "sell" | "swidge" | "createDepositAddress" | "renewDepositAddress" | "recoverDepositAddress" | "disableDepositAddress" | "*"; /** * The frozen context object passed to every condition function during evaluation. */ diff --git a/types/src/wallet-account-with-protocols.d.ts b/types/src/wallet-account-with-protocols.d.ts index bf6041b..f1502e4 100644 --- a/types/src/wallet-account-with-protocols.d.ts +++ b/types/src/wallet-account-with-protocols.d.ts @@ -1,20 +1,10 @@ -/** @typedef {import('@tetherto/wdk-wallet/protocols').ISwapProtocol} ISwapProtocol */ -/** @typedef {typeof import('@tetherto/wdk-wallet/protocols').SwapProtocol} SwapProtocolCtor */ -/** @typedef {import('@tetherto/wdk-wallet/protocols').IBridgeProtocol} IBridgeProtocol */ -/** @typedef {typeof import('@tetherto/wdk-wallet/protocols').BridgeProtocol} BridgeProtocolCtor */ -/** @typedef {import('@tetherto/wdk-wallet/protocols').ILendingProtocol} ILendingProtocol */ -/** @typedef {typeof import('@tetherto/wdk-wallet/protocols').LendingProtocol} LendingProtocolCtor */ -/** @typedef {import('@tetherto/wdk-wallet/protocols').IFiatProtocol} IFiatProtocol */ -/** @typedef {typeof import('@tetherto/wdk-wallet/protocols').FiatProtocol} FiatProtocolCtor */ -/** @typedef {import('@tetherto/wdk-wallet/protocols').ISwidgeProtocol} ISwidgeProtocol */ -/** @typedef {typeof import('@tetherto/wdk-wallet/protocols').SwidgeProtocol} SwidgeProtocolCtor */ /** * Interface for wallet accounts that also expose the WDK's protocol-getter * helpers (`registerProtocol`, `getSwapProtocol`, `getBridgeProtocol`, - * `getLendingProtocol`, `getFiatProtocol`, `getSwidgeProtocol`). The - * concrete shape is materialized at runtime by `wdk.getAccount` / - * `getAccountByPath` after middlewares and protocol getters have been - * installed. See `WdkAccount` for the consumer-facing type that pairs + * `getLendingProtocol`, `getFiatProtocol`, `getSwidgeProtocol`, + * `getSdaProtocol`). The concrete shape is materialized at runtime by + * `wdk.getAccount` / `getAccountByPath` after middlewares and protocol getters + * have been installed. See `WdkAccount` for the consumer-facing type that pairs * this surface with the underlying `IWalletAccount` shape. * * @interface @@ -26,13 +16,13 @@ export class IWalletAccountWithProtocols { * The label must be unique in the scope of the account and the type of protocol (i.e., there can’t be two protocols of the same * type bound to the same account with the same label). * - * @template {SwapProtocolCtor | BridgeProtocolCtor | LendingProtocolCtor | FiatProtocolCtor | SwidgeProtocolCtor} P + * @template {typeof SwapProtocol | typeof BridgeProtocol | typeof LendingProtocol | typeof FiatProtocol | typeof SwidgeProtocol | typeof SdaProtocol} P * @param {string} label - The label. * @param {P} Protocol - The protocol class. * @param {ConstructorParameters
[1]} config - The protocol configuration. * @returns {IWalletAccountWithProtocols} The account. */ - registerProtocol
(label: string, Protocol: P, config: ConstructorParameters
[1]): IWalletAccountWithProtocols; + registerProtocol
(label: string, Protocol: P, config: ConstructorParameters
[1]): IWalletAccountWithProtocols;
/**
* Returns the swap protocol with the given label.
*
@@ -73,14 +63,24 @@ export class IWalletAccountWithProtocols {
* @throws {Error} If no swidge protocol has been registered on this account with the given label.
*/
getSwidgeProtocol(label: string): ISwidgeProtocol;
+ /**
+ * Returns the SDA protocol with the given label.
+ *
+ * @param {string} label - The label.
+ * @returns {ISdaProtocol} The SDA protocol.
+ * @throws {Error} If no SDA protocol has been registered on this account with the given label.
+ */
+ getSdaProtocol(label: string): ISdaProtocol;
}
export type ISwapProtocol = import("@tetherto/wdk-wallet/protocols").ISwapProtocol;
-export type SwapProtocolCtor = typeof import("@tetherto/wdk-wallet/protocols").SwapProtocol;
export type IBridgeProtocol = import("@tetherto/wdk-wallet/protocols").IBridgeProtocol;
-export type BridgeProtocolCtor = typeof import("@tetherto/wdk-wallet/protocols").BridgeProtocol;
export type ILendingProtocol = import("@tetherto/wdk-wallet/protocols").ILendingProtocol;
-export type LendingProtocolCtor = typeof import("@tetherto/wdk-wallet/protocols").LendingProtocol;
export type IFiatProtocol = import("@tetherto/wdk-wallet/protocols").IFiatProtocol;
-export type FiatProtocolCtor = typeof import("@tetherto/wdk-wallet/protocols").FiatProtocol;
export type ISwidgeProtocol = import("@tetherto/wdk-wallet/protocols").ISwidgeProtocol;
-export type SwidgeProtocolCtor = typeof import("@tetherto/wdk-wallet/protocols").SwidgeProtocol;
+export type ISdaProtocol = import("@tetherto/wdk-wallet/protocols").ISdaProtocol;
+import { SwapProtocol } from '@tetherto/wdk-wallet/protocols';
+import { BridgeProtocol } from '@tetherto/wdk-wallet/protocols';
+import { LendingProtocol } from '@tetherto/wdk-wallet/protocols';
+import { FiatProtocol } from '@tetherto/wdk-wallet/protocols';
+import { SwidgeProtocol } from '@tetherto/wdk-wallet/protocols';
+import { SdaProtocol } from '@tetherto/wdk-wallet/protocols';
diff --git a/types/src/wdk.d.ts b/types/src/wdk.d.ts
index 34048cf..654e019 100644
--- a/types/src/wdk.d.ts
+++ b/types/src/wdk.d.ts
@@ -1,24 +1,3 @@
-/** @typedef {import('@tetherto/wdk-wallet').IWalletAccount} IWalletAccount */
-/** @typedef {import('@tetherto/wdk-wallet').FeeRates} FeeRates */
-/** @typedef {import('./wallet-account-with-protocols.js').IWalletAccountWithProtocols} IWalletAccountWithProtocols */
-/**
- * The shape returned by `getAccount` / `getAccountByPath`: the underlying
- * IWalletAccount (sendTransaction, signTransaction, transfer, approve,
- * sign, …) plus the protocol-getter surface added by the WDK at account
- * retrieval time. Concrete wallet packages may further extend this shape.
- *
- * @typedef {IWalletAccount & IWalletAccountWithProtocols} WdkAccount
- */
-/** @typedef {(account: A) => Promise [1]} config - The protocol configuration.
* @returns {WDK} The WDK.
*/
- registerProtocol (blockchain: string, label: string, Protocol: P, config: ConstructorParameters [1]): WDK;
+ registerProtocol (blockchain: string, label: string, Protocol: P, config: ConstructorParameters [1]): WDK;
/**
* Registers a new middleware to the WDK.
*
@@ -170,8 +149,10 @@ export type PolicyScope = import("./policy/policy-engine.js").PolicyScope;
export type PolicyOperation = import("./policy/policy-engine.js").PolicyOperation;
export type SimulationResult = import("./policy/policy-engine.js").SimulationResult;
export type RegisterPolicyOptions = import("./policy/policy-engine.js").RegisterPolicyOptions;
+import WalletManager from '@tetherto/wdk-wallet';
import { SwapProtocol } from '@tetherto/wdk-wallet/protocols';
import { BridgeProtocol } from '@tetherto/wdk-wallet/protocols';
import { LendingProtocol } from '@tetherto/wdk-wallet/protocols';
import { FiatProtocol } from '@tetherto/wdk-wallet/protocols';
import { SwidgeProtocol } from '@tetherto/wdk-wallet/protocols';
+import { SdaProtocol } from '@tetherto/wdk-wallet/protocols';