diff --git a/package-lock.json b/package-lock.json index 88e22d1..e8685fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0-beta.12", "license": "Apache-2.0", "dependencies": { - "@tetherto/wdk-wallet": "^1.0.0-beta.10", + "@tetherto/wdk-wallet": "github:tetherto/wdk-wallet#feat/sda-protocol", "bare-node-runtime": "^1.4.0", "zod": "^4.4.3" }, @@ -51,7 +51,6 @@ "integrity": "sha512-RgHBCvtjbOK2gXSNBNIkNoEc9qoVEtau3hj8gEqKQuL3HZAibKarWFEI3Lfm6EYKkLalOh8eSrj9b+ch9H/VBA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@babel/code-frame": "^7.29.7", "@babel/generator": "^7.29.7", @@ -1294,9 +1293,8 @@ } }, "node_modules/@tetherto/wdk-wallet": { - "version": "1.0.0-beta.10", - "resolved": "https://registry.npmjs.org/@tetherto/wdk-wallet/-/wdk-wallet-1.0.0-beta.10.tgz", - "integrity": "sha512-qCOxvNIltfwwMhOjWAgk2DN/0TZ+RjNOk10BXKQM2XMmq6KR8yJZV3Yc5FoJ+AFsCHZBhVJR6k6eF0/ZMI1pIA==", + "version": "1.0.0-beta.11", + "resolved": "git+ssh://git@github.com/tetherto/wdk-wallet.git#9aafb6c4cc8ac780b226ecc4c04bb8e3b52a136f", "license": "Apache-2.0", "dependencies": { "bare-node-runtime": "^1.4.0", @@ -1753,7 +1751,6 @@ "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", "dev": true, "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -2187,7 +2184,6 @@ "resolved": "https://registry.npmjs.org/bare-abort-controller/-/bare-abort-controller-1.1.1.tgz", "integrity": "sha512-A/3w+PHaGnjlrRcmBeuCk8v23SP35db1X6a5GOkTVSloVmMEWdVhhnlrJWzIvnLJh79ljhAFS1lvLRev09LCGg==", "license": "Apache-2.0", - "peer": true, "dependencies": { "bare-events": "^2.7.0" } @@ -2957,7 +2953,6 @@ "resolved": "https://registry.npmjs.org/bare-tcp/-/bare-tcp-2.2.13.tgz", "integrity": "sha512-4KQPgqYugvK6QxcSnVGbl87XslBebxmXlv7Glf4M9iwwoSCDKtYmC1t6zsMctTNhzKXbWCId7mB4R9qLWj3JMw==", "license": "Apache-2.0", - "peer": true, "dependencies": { "bare-dns": "^2.0.4", "bare-events": "^2.5.4", @@ -3167,7 +3162,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "baseline-browser-mapping": "^2.10.12", "caniuse-lite": "^1.0.30001782", @@ -3962,7 +3956,6 @@ "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", @@ -4170,7 +4163,6 @@ "integrity": "sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@rtsao/scc": "^1.1.0", "array-includes": "^3.1.9", @@ -4252,7 +4244,6 @@ "integrity": "sha512-jDex9s7D/Qial8AGVIHq4W7NswpUD5DPDL2RH8Lzd9EloWUuvUkHfv4FRLMipH5q2UtyurorBkPeNi1wVWNh3Q==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "builtins": "^5.0.1", "eslint-plugin-es": "^4.1.0", @@ -4338,7 +4329,6 @@ "integrity": "sha512-57Zzfw8G6+Gq7axm2Pdo3gW/Rx3h9Yywgn61uE/3elTCOePEHVrn2i5CdfBwA1BLK0Q0WqctICIUSqXZW/VprQ==", "dev": true, "license": "ISC", - "peer": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, @@ -4355,7 +4345,6 @@ "integrity": "sha512-Qteup0SqU15kdocexFNAJMvCJEfa2xUKNV4CC1xsVMrIIqEy3SQ/rqyxCWNzfrd3/ldy6HMlD2e0JDVpDg2qIA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "array-includes": "^3.1.8", "array.prototype.findlast": "^1.2.5", diff --git a/package.json b/package.json index ffe4165..e51f40d 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.10", + "@tetherto/wdk-wallet": "github:tetherto/wdk-wallet#feat/sda-protocol", "bare-node-runtime": "^1.4.0", "zod": "^4.4.3" }, 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/wallet-account-with-protocols.js b/src/wallet-account-with-protocols.js index a800648..6996f1e 100644 --- a/src/wallet-account-with-protocols.js +++ b/src/wallet-account-with-protocols.js @@ -26,6 +26,8 @@ import { IWalletAccount, NotImplementedError } from '@tetherto/wdk-wallet' /** @typedef {import('@tetherto/wdk-wallet/protocols').ISwidgeProtocol} ISwidgeProtocol */ +/** @typedef {import('@tetherto/wdk-wallet/protocols').ISdaProtocol} ISdaProtocol */ + /** @interface */ export class IWalletAccountWithProtocols extends IWalletAccount { /** @@ -34,7 +36,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 {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} label - The label. * @param {P} Protocol - The protocol class. * @param {ConstructorParameters

[1]} config - The protocol configuration. @@ -98,4 +100,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 19e95bd..25406ca 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' @@ -65,7 +65,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) @@ -130,7 +130,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. @@ -142,6 +142,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) @@ -313,13 +317,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) { @@ -412,5 +418,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}.`) + } } }