@owney/sdk 0.6.7-beta.3 → 0.6.8-beta.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/dist/index.cjs +45 -0
- package/dist/index.js +45 -0
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -648,6 +648,18 @@ function buildAutoSelectUpdate(current, asset, chainId) {
|
|
|
648
648
|
};
|
|
649
649
|
}
|
|
650
650
|
|
|
651
|
+
// src/agents/zyfai/protocol-merge.ts
|
|
652
|
+
function buildProtocolMergeUpdate(available, current, asset) {
|
|
653
|
+
const enabled = current.protocols ?? [];
|
|
654
|
+
const enabledSet = new Set(enabled);
|
|
655
|
+
const missing = available.filter((p) => !enabledSet.has(p.id));
|
|
656
|
+
if (missing.length === 0) return null;
|
|
657
|
+
return {
|
|
658
|
+
asset,
|
|
659
|
+
protocols: [.../* @__PURE__ */ new Set([...enabled, ...missing.map((p) => p.id)])]
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
|
|
651
663
|
// src/agents/zyfai/zyfai.agent.ts
|
|
652
664
|
var DEFAULT_ZYFAI_RPC_URLS = {
|
|
653
665
|
8453: "https://base-mainnet.g.alchemy.com/v2/ZWyVU-9XfS3z8Rn-xkq7V",
|
|
@@ -956,6 +968,34 @@ var ZyfaiAgent = class {
|
|
|
956
968
|
}
|
|
957
969
|
}
|
|
958
970
|
}
|
|
971
|
+
/**
|
|
972
|
+
* Sync newly-available protocols onto an existing user's profile at wallet
|
|
973
|
+
* connection. Zyfai's own protocol sync (`updateUserProtocols`) runs only when
|
|
974
|
+
* a session key is created, so existing users — who already have one — never
|
|
975
|
+
* pick up protocols Zyfai adds later. This closes that gap idempotently:
|
|
976
|
+
* it diffs available-vs-enabled by protocol id and writes the full union
|
|
977
|
+
* back, or does nothing when none are missing.
|
|
978
|
+
*
|
|
979
|
+
* Non-fatal: a sync failure must never block activation. Only "USDC" / "WETH"
|
|
980
|
+
* are modeled per-asset by the Zyfai profile API, so other assets are skipped.
|
|
981
|
+
*/
|
|
982
|
+
async ensureProtocolsSynced(chainId, asset) {
|
|
983
|
+
if (asset !== "USDC" && asset !== "WETH") return;
|
|
984
|
+
try {
|
|
985
|
+
const [current, { protocols: available }] = await Promise.all([
|
|
986
|
+
this.sdk.getUserDetails(asset),
|
|
987
|
+
this.sdk.getAvailableProtocols(chainId)
|
|
988
|
+
]);
|
|
989
|
+
const update = buildProtocolMergeUpdate(available, current, asset);
|
|
990
|
+
if (!update) return;
|
|
991
|
+
await this.sdk.updateUserProfile(update);
|
|
992
|
+
} catch (error) {
|
|
993
|
+
console.warn(
|
|
994
|
+
"[zyfai] ensureProtocolsSynced failed (non-fatal):",
|
|
995
|
+
error instanceof Error ? error.message : String(error)
|
|
996
|
+
);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
959
999
|
/** Connect + resolve smart wallet address for read operations. */
|
|
960
1000
|
async resolveSmartWallet(state, chainId) {
|
|
961
1001
|
await this.connectAuth(state, chainId);
|
|
@@ -987,6 +1027,11 @@ var ZyfaiAgent = class {
|
|
|
987
1027
|
async activateAgent(state, chainId) {
|
|
988
1028
|
try {
|
|
989
1029
|
await this.connectAuth(state, chainId);
|
|
1030
|
+
const validChainId = isValidChainId(chainId);
|
|
1031
|
+
await Promise.all([
|
|
1032
|
+
this.ensureProtocolsSynced(validChainId, "USDC"),
|
|
1033
|
+
this.ensureProtocolsSynced(validChainId, "WETH")
|
|
1034
|
+
]);
|
|
990
1035
|
} catch (error) {
|
|
991
1036
|
throw error;
|
|
992
1037
|
}
|
package/dist/index.js
CHANGED
|
@@ -616,6 +616,18 @@ function buildAutoSelectUpdate(current, asset, chainId) {
|
|
|
616
616
|
};
|
|
617
617
|
}
|
|
618
618
|
|
|
619
|
+
// src/agents/zyfai/protocol-merge.ts
|
|
620
|
+
function buildProtocolMergeUpdate(available, current, asset) {
|
|
621
|
+
const enabled = current.protocols ?? [];
|
|
622
|
+
const enabledSet = new Set(enabled);
|
|
623
|
+
const missing = available.filter((p) => !enabledSet.has(p.id));
|
|
624
|
+
if (missing.length === 0) return null;
|
|
625
|
+
return {
|
|
626
|
+
asset,
|
|
627
|
+
protocols: [.../* @__PURE__ */ new Set([...enabled, ...missing.map((p) => p.id)])]
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
|
|
619
631
|
// src/agents/zyfai/zyfai.agent.ts
|
|
620
632
|
var DEFAULT_ZYFAI_RPC_URLS = {
|
|
621
633
|
8453: "https://base-mainnet.g.alchemy.com/v2/ZWyVU-9XfS3z8Rn-xkq7V",
|
|
@@ -924,6 +936,34 @@ var ZyfaiAgent = class {
|
|
|
924
936
|
}
|
|
925
937
|
}
|
|
926
938
|
}
|
|
939
|
+
/**
|
|
940
|
+
* Sync newly-available protocols onto an existing user's profile at wallet
|
|
941
|
+
* connection. Zyfai's own protocol sync (`updateUserProtocols`) runs only when
|
|
942
|
+
* a session key is created, so existing users — who already have one — never
|
|
943
|
+
* pick up protocols Zyfai adds later. This closes that gap idempotently:
|
|
944
|
+
* it diffs available-vs-enabled by protocol id and writes the full union
|
|
945
|
+
* back, or does nothing when none are missing.
|
|
946
|
+
*
|
|
947
|
+
* Non-fatal: a sync failure must never block activation. Only "USDC" / "WETH"
|
|
948
|
+
* are modeled per-asset by the Zyfai profile API, so other assets are skipped.
|
|
949
|
+
*/
|
|
950
|
+
async ensureProtocolsSynced(chainId, asset) {
|
|
951
|
+
if (asset !== "USDC" && asset !== "WETH") return;
|
|
952
|
+
try {
|
|
953
|
+
const [current, { protocols: available }] = await Promise.all([
|
|
954
|
+
this.sdk.getUserDetails(asset),
|
|
955
|
+
this.sdk.getAvailableProtocols(chainId)
|
|
956
|
+
]);
|
|
957
|
+
const update = buildProtocolMergeUpdate(available, current, asset);
|
|
958
|
+
if (!update) return;
|
|
959
|
+
await this.sdk.updateUserProfile(update);
|
|
960
|
+
} catch (error) {
|
|
961
|
+
console.warn(
|
|
962
|
+
"[zyfai] ensureProtocolsSynced failed (non-fatal):",
|
|
963
|
+
error instanceof Error ? error.message : String(error)
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
927
967
|
/** Connect + resolve smart wallet address for read operations. */
|
|
928
968
|
async resolveSmartWallet(state, chainId) {
|
|
929
969
|
await this.connectAuth(state, chainId);
|
|
@@ -955,6 +995,11 @@ var ZyfaiAgent = class {
|
|
|
955
995
|
async activateAgent(state, chainId) {
|
|
956
996
|
try {
|
|
957
997
|
await this.connectAuth(state, chainId);
|
|
998
|
+
const validChainId = isValidChainId(chainId);
|
|
999
|
+
await Promise.all([
|
|
1000
|
+
this.ensureProtocolsSynced(validChainId, "USDC"),
|
|
1001
|
+
this.ensureProtocolsSynced(validChainId, "WETH")
|
|
1002
|
+
]);
|
|
958
1003
|
} catch (error) {
|
|
959
1004
|
throw error;
|
|
960
1005
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owney/sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test:watch": "vitest"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@zyfai/sdk": "0.2.
|
|
26
|
+
"@zyfai/sdk": "^0.2.41",
|
|
27
27
|
"siwe": "^3.0.0",
|
|
28
28
|
"viem": "^2.48.1"
|
|
29
29
|
},
|