@terkoizmy/intent-sdk 1.0.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/LICENSE +21 -0
- package/README.md +258 -0
- package/dist/config/chains.d.ts +25 -0
- package/dist/config/chains.d.ts.map +1 -0
- package/dist/config/chains.js +85 -0
- package/dist/config/chains.js.map +1 -0
- package/dist/config/default.d.ts +39 -0
- package/dist/config/default.d.ts.map +1 -0
- package/dist/config/default.js +46 -0
- package/dist/config/default.js.map +1 -0
- package/dist/config/testnets.d.ts +31 -0
- package/dist/config/testnets.d.ts.map +1 -0
- package/dist/config/testnets.js +99 -0
- package/dist/config/testnets.js.map +1 -0
- package/dist/errors/inventory-errors.d.ts +31 -0
- package/dist/errors/inventory-errors.d.ts.map +1 -0
- package/dist/errors/inventory-errors.js +45 -0
- package/dist/errors/inventory-errors.js.map +1 -0
- package/dist/errors/settlement-errors.d.ts +27 -0
- package/dist/errors/settlement-errors.d.ts.map +1 -0
- package/dist/errors/settlement-errors.js +39 -0
- package/dist/errors/settlement-errors.js.map +1 -0
- package/dist/errors/solver-errors.d.ts +45 -0
- package/dist/errors/solver-errors.d.ts.map +1 -0
- package/dist/errors/solver-errors.js +66 -0
- package/dist/errors/solver-errors.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/classifiers/intent-classifier.d.ts +40 -0
- package/dist/parser/classifiers/intent-classifier.d.ts.map +1 -0
- package/dist/parser/classifiers/intent-classifier.js +72 -0
- package/dist/parser/classifiers/intent-classifier.js.map +1 -0
- package/dist/parser/extractors/action.d.ts +32 -0
- package/dist/parser/extractors/action.d.ts.map +1 -0
- package/dist/parser/extractors/action.js +72 -0
- package/dist/parser/extractors/action.js.map +1 -0
- package/dist/parser/extractors/amount.d.ts +39 -0
- package/dist/parser/extractors/amount.d.ts.map +1 -0
- package/dist/parser/extractors/amount.js +113 -0
- package/dist/parser/extractors/amount.js.map +1 -0
- package/dist/parser/extractors/constraints.d.ts +37 -0
- package/dist/parser/extractors/constraints.d.ts.map +1 -0
- package/dist/parser/extractors/constraints.js +119 -0
- package/dist/parser/extractors/constraints.js.map +1 -0
- package/dist/parser/extractors/index.d.ts +5 -0
- package/dist/parser/extractors/index.d.ts.map +1 -0
- package/dist/parser/extractors/index.js +5 -0
- package/dist/parser/extractors/index.js.map +1 -0
- package/dist/parser/extractors/token.d.ts +24 -0
- package/dist/parser/extractors/token.d.ts.map +1 -0
- package/dist/parser/extractors/token.js +124 -0
- package/dist/parser/extractors/token.js.map +1 -0
- package/dist/parser/index.d.ts +125 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +293 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/template/bridge.d.ts +37 -0
- package/dist/parser/template/bridge.d.ts.map +1 -0
- package/dist/parser/template/bridge.js +80 -0
- package/dist/parser/template/bridge.js.map +1 -0
- package/dist/parser/template/claim.d.ts +15 -0
- package/dist/parser/template/claim.d.ts.map +1 -0
- package/dist/parser/template/claim.js +36 -0
- package/dist/parser/template/claim.js.map +1 -0
- package/dist/parser/template/index.d.ts +28 -0
- package/dist/parser/template/index.d.ts.map +1 -0
- package/dist/parser/template/index.js +50 -0
- package/dist/parser/template/index.js.map +1 -0
- package/dist/parser/template/nft.d.ts +3 -0
- package/dist/parser/template/nft.d.ts.map +1 -0
- package/dist/parser/template/nft.js +19 -0
- package/dist/parser/template/nft.js.map +1 -0
- package/dist/parser/template/send.d.ts +24 -0
- package/dist/parser/template/send.d.ts.map +1 -0
- package/dist/parser/template/send.js +61 -0
- package/dist/parser/template/send.js.map +1 -0
- package/dist/parser/template/swap.d.ts +3 -0
- package/dist/parser/template/swap.d.ts.map +1 -0
- package/dist/parser/template/swap.js +21 -0
- package/dist/parser/template/swap.js.map +1 -0
- package/dist/parser/template/unknown.d.ts +3 -0
- package/dist/parser/template/unknown.d.ts.map +1 -0
- package/dist/parser/template/unknown.js +11 -0
- package/dist/parser/template/unknown.js.map +1 -0
- package/dist/parser/template/yield.d.ts +3 -0
- package/dist/parser/template/yield.d.ts.map +1 -0
- package/dist/parser/template/yield.js +25 -0
- package/dist/parser/template/yield.js.map +1 -0
- package/dist/parser/utils/normalize.d.ts +41 -0
- package/dist/parser/utils/normalize.d.ts.map +1 -0
- package/dist/parser/utils/normalize.js +71 -0
- package/dist/parser/utils/normalize.js.map +1 -0
- package/dist/parser/utils/parser-helpers.d.ts +20 -0
- package/dist/parser/utils/parser-helpers.d.ts.map +1 -0
- package/dist/parser/utils/parser-helpers.js +282 -0
- package/dist/parser/utils/parser-helpers.js.map +1 -0
- package/dist/parser/validators/schema.d.ts +14 -0
- package/dist/parser/validators/schema.d.ts.map +1 -0
- package/dist/parser/validators/schema.js +81 -0
- package/dist/parser/validators/schema.js.map +1 -0
- package/dist/sdk-factory.d.ts +55 -0
- package/dist/sdk-factory.d.ts.map +1 -0
- package/dist/sdk-factory.js +49 -0
- package/dist/sdk-factory.js.map +1 -0
- package/dist/services/token-resolver.d.ts +142 -0
- package/dist/services/token-resolver.d.ts.map +1 -0
- package/dist/services/token-resolver.js +254 -0
- package/dist/services/token-resolver.js.map +1 -0
- package/dist/shared/chain-registry/chain-names.d.ts +22 -0
- package/dist/shared/chain-registry/chain-names.d.ts.map +1 -0
- package/dist/shared/chain-registry/chain-names.js +49 -0
- package/dist/shared/chain-registry/chain-names.js.map +1 -0
- package/dist/shared/chain-registry/configs/arbitrum-sepolia.d.ts +9 -0
- package/dist/shared/chain-registry/configs/arbitrum-sepolia.d.ts.map +1 -0
- package/dist/shared/chain-registry/configs/arbitrum-sepolia.js +9 -0
- package/dist/shared/chain-registry/configs/arbitrum-sepolia.js.map +1 -0
- package/dist/shared/chain-registry/configs/base-sepolia.d.ts +9 -0
- package/dist/shared/chain-registry/configs/base-sepolia.d.ts.map +1 -0
- package/dist/shared/chain-registry/configs/base-sepolia.js +9 -0
- package/dist/shared/chain-registry/configs/base-sepolia.js.map +1 -0
- package/dist/shared/chain-registry/configs/ethereum.d.ts +7 -0
- package/dist/shared/chain-registry/configs/ethereum.d.ts.map +1 -0
- package/dist/shared/chain-registry/configs/ethereum.js +7 -0
- package/dist/shared/chain-registry/configs/ethereum.js.map +1 -0
- package/dist/shared/chain-registry/configs/polygon.d.ts +7 -0
- package/dist/shared/chain-registry/configs/polygon.d.ts.map +1 -0
- package/dist/shared/chain-registry/configs/polygon.js +7 -0
- package/dist/shared/chain-registry/configs/polygon.js.map +1 -0
- package/dist/shared/chain-registry/configs/sepolia.d.ts +9 -0
- package/dist/shared/chain-registry/configs/sepolia.d.ts.map +1 -0
- package/dist/shared/chain-registry/configs/sepolia.js +9 -0
- package/dist/shared/chain-registry/configs/sepolia.js.map +1 -0
- package/dist/shared/chain-registry/configs/unichain-sepolia.d.ts +9 -0
- package/dist/shared/chain-registry/configs/unichain-sepolia.d.ts.map +1 -0
- package/dist/shared/chain-registry/configs/unichain-sepolia.js +9 -0
- package/dist/shared/chain-registry/configs/unichain-sepolia.js.map +1 -0
- package/dist/shared/chain-registry/registry.d.ts +50 -0
- package/dist/shared/chain-registry/registry.d.ts.map +1 -0
- package/dist/shared/chain-registry/registry.js +72 -0
- package/dist/shared/chain-registry/registry.js.map +1 -0
- package/dist/shared/rpc/provider-manager.d.ts +111 -0
- package/dist/shared/rpc/provider-manager.d.ts.map +1 -0
- package/dist/shared/rpc/provider-manager.js +116 -0
- package/dist/shared/rpc/provider-manager.js.map +1 -0
- package/dist/shared/rpc/viem-provider.d.ts +78 -0
- package/dist/shared/rpc/viem-provider.d.ts.map +1 -0
- package/dist/shared/rpc/viem-provider.js +187 -0
- package/dist/shared/rpc/viem-provider.js.map +1 -0
- package/dist/shared/token-registry/enrichment.d.ts +48 -0
- package/dist/shared/token-registry/enrichment.d.ts.map +1 -0
- package/dist/shared/token-registry/enrichment.js +69 -0
- package/dist/shared/token-registry/enrichment.js.map +1 -0
- package/dist/shared/token-registry/registry.d.ts +119 -0
- package/dist/shared/token-registry/registry.d.ts.map +1 -0
- package/dist/shared/token-registry/registry.js +200 -0
- package/dist/shared/token-registry/registry.js.map +1 -0
- package/dist/shared/utils/erc20-utils.d.ts +24 -0
- package/dist/shared/utils/erc20-utils.d.ts.map +1 -0
- package/dist/shared/utils/erc20-utils.js +31 -0
- package/dist/shared/utils/erc20-utils.js.map +1 -0
- package/dist/shared/utils/retry.d.ts +57 -0
- package/dist/shared/utils/retry.d.ts.map +1 -0
- package/dist/shared/utils/retry.js +104 -0
- package/dist/shared/utils/retry.js.map +1 -0
- package/dist/shared/wallet-manager/viem-signer.d.ts +68 -0
- package/dist/shared/wallet-manager/viem-signer.d.ts.map +1 -0
- package/dist/shared/wallet-manager/viem-signer.js +116 -0
- package/dist/shared/wallet-manager/viem-signer.js.map +1 -0
- package/dist/shared/wallet-manager/wallet-manager.d.ts +96 -0
- package/dist/shared/wallet-manager/wallet-manager.d.ts.map +1 -0
- package/dist/shared/wallet-manager/wallet-manager.js +104 -0
- package/dist/shared/wallet-manager/wallet-manager.js.map +1 -0
- package/dist/solver/agent/agent-config.d.ts +62 -0
- package/dist/solver/agent/agent-config.d.ts.map +1 -0
- package/dist/solver/agent/agent-config.js +59 -0
- package/dist/solver/agent/agent-config.js.map +1 -0
- package/dist/solver/agent/index.d.ts +6 -0
- package/dist/solver/agent/index.d.ts.map +1 -0
- package/dist/solver/agent/index.js +6 -0
- package/dist/solver/agent/index.js.map +1 -0
- package/dist/solver/agent/liquidity-agent.d.ts +118 -0
- package/dist/solver/agent/liquidity-agent.d.ts.map +1 -0
- package/dist/solver/agent/liquidity-agent.js +285 -0
- package/dist/solver/agent/liquidity-agent.js.map +1 -0
- package/dist/solver/contracts/intent-settlement/index.d.ts +2 -0
- package/dist/solver/contracts/intent-settlement/index.d.ts.map +1 -0
- package/dist/solver/contracts/intent-settlement/index.js +2 -0
- package/dist/solver/contracts/intent-settlement/index.js.map +1 -0
- package/dist/solver/contracts/intent-settlement/intent-settlement.d.ts +22 -0
- package/dist/solver/contracts/intent-settlement/intent-settlement.d.ts.map +1 -0
- package/dist/solver/contracts/intent-settlement/intent-settlement.js +58 -0
- package/dist/solver/contracts/intent-settlement/intent-settlement.js.map +1 -0
- package/dist/solver/contracts/intent-settlement/viem-settlement-contract.d.ts +226 -0
- package/dist/solver/contracts/intent-settlement/viem-settlement-contract.d.ts.map +1 -0
- package/dist/solver/contracts/intent-settlement/viem-settlement-contract.js +204 -0
- package/dist/solver/contracts/intent-settlement/viem-settlement-contract.js.map +1 -0
- package/dist/solver/index.d.ts +87 -0
- package/dist/solver/index.d.ts.map +1 -0
- package/dist/solver/index.js +167 -0
- package/dist/solver/index.js.map +1 -0
- package/dist/solver/inventory/index.d.ts +7 -0
- package/dist/solver/inventory/index.d.ts.map +1 -0
- package/dist/solver/inventory/index.js +7 -0
- package/dist/solver/inventory/index.js.map +1 -0
- package/dist/solver/inventory/inventory-manager.d.ts +135 -0
- package/dist/solver/inventory/inventory-manager.d.ts.map +1 -0
- package/dist/solver/inventory/inventory-manager.js +323 -0
- package/dist/solver/inventory/inventory-manager.js.map +1 -0
- package/dist/solver/inventory/inventory-monitor.d.ts +72 -0
- package/dist/solver/inventory/inventory-monitor.d.ts.map +1 -0
- package/dist/solver/inventory/inventory-monitor.js +123 -0
- package/dist/solver/inventory/inventory-monitor.js.map +1 -0
- package/dist/solver/inventory/rebalancer.d.ts +78 -0
- package/dist/solver/inventory/rebalancer.d.ts.map +1 -0
- package/dist/solver/inventory/rebalancer.js +210 -0
- package/dist/solver/inventory/rebalancer.js.map +1 -0
- package/dist/solver/mempool/index.d.ts +8 -0
- package/dist/solver/mempool/index.d.ts.map +1 -0
- package/dist/solver/mempool/index.js +8 -0
- package/dist/solver/mempool/index.js.map +1 -0
- package/dist/solver/mempool/intent-filter.d.ts +49 -0
- package/dist/solver/mempool/intent-filter.d.ts.map +1 -0
- package/dist/solver/mempool/intent-filter.js +75 -0
- package/dist/solver/mempool/intent-filter.js.map +1 -0
- package/dist/solver/mempool/mempool-client.d.ts +105 -0
- package/dist/solver/mempool/mempool-client.d.ts.map +1 -0
- package/dist/solver/mempool/mempool-client.js +161 -0
- package/dist/solver/mempool/mempool-client.js.map +1 -0
- package/dist/solver/mempool/mempool-monitor.d.ts +71 -0
- package/dist/solver/mempool/mempool-monitor.d.ts.map +1 -0
- package/dist/solver/mempool/mempool-monitor.js +127 -0
- package/dist/solver/mempool/mempool-monitor.js.map +1 -0
- package/dist/solver/mempool/solution-submitter.d.ts +41 -0
- package/dist/solver/mempool/solution-submitter.d.ts.map +1 -0
- package/dist/solver/mempool/solution-submitter.js +71 -0
- package/dist/solver/mempool/solution-submitter.js.map +1 -0
- package/dist/solver/monitoring/alert-manager.d.ts +43 -0
- package/dist/solver/monitoring/alert-manager.d.ts.map +1 -0
- package/dist/solver/monitoring/alert-manager.js +69 -0
- package/dist/solver/monitoring/alert-manager.js.map +1 -0
- package/dist/solver/monitoring/health-checker.d.ts +53 -0
- package/dist/solver/monitoring/health-checker.d.ts.map +1 -0
- package/dist/solver/monitoring/health-checker.js +94 -0
- package/dist/solver/monitoring/health-checker.js.map +1 -0
- package/dist/solver/monitoring/index.d.ts +7 -0
- package/dist/solver/monitoring/index.d.ts.map +1 -0
- package/dist/solver/monitoring/index.js +7 -0
- package/dist/solver/monitoring/index.js.map +1 -0
- package/dist/solver/monitoring/profit-tracker.d.ts +47 -0
- package/dist/solver/monitoring/profit-tracker.d.ts.map +1 -0
- package/dist/solver/monitoring/profit-tracker.js +112 -0
- package/dist/solver/monitoring/profit-tracker.js.map +1 -0
- package/dist/solver/pricing/dynamic-pricing.d.ts +86 -0
- package/dist/solver/pricing/dynamic-pricing.d.ts.map +1 -0
- package/dist/solver/pricing/dynamic-pricing.js +189 -0
- package/dist/solver/pricing/dynamic-pricing.js.map +1 -0
- package/dist/solver/pricing/fee-calculator.d.ts +101 -0
- package/dist/solver/pricing/fee-calculator.d.ts.map +1 -0
- package/dist/solver/pricing/fee-calculator.js +149 -0
- package/dist/solver/pricing/fee-calculator.js.map +1 -0
- package/dist/solver/pricing/index.d.ts +7 -0
- package/dist/solver/pricing/index.d.ts.map +1 -0
- package/dist/solver/pricing/index.js +7 -0
- package/dist/solver/pricing/index.js.map +1 -0
- package/dist/solver/pricing/slippage-capture.d.ts +47 -0
- package/dist/solver/pricing/slippage-capture.d.ts.map +1 -0
- package/dist/solver/pricing/slippage-capture.js +63 -0
- package/dist/solver/pricing/slippage-capture.js.map +1 -0
- package/dist/solver/protocols/aggregators/lifi.d.ts +109 -0
- package/dist/solver/protocols/aggregators/lifi.d.ts.map +1 -0
- package/dist/solver/protocols/aggregators/lifi.js +110 -0
- package/dist/solver/protocols/aggregators/lifi.js.map +1 -0
- package/dist/solver/protocols/aggregators/swing.d.ts +67 -0
- package/dist/solver/protocols/aggregators/swing.d.ts.map +1 -0
- package/dist/solver/protocols/aggregators/swing.js +212 -0
- package/dist/solver/protocols/aggregators/swing.js.map +1 -0
- package/dist/solver/protocols/base-protocol.d.ts +42 -0
- package/dist/solver/protocols/base-protocol.d.ts.map +1 -0
- package/dist/solver/protocols/base-protocol.js +16 -0
- package/dist/solver/protocols/base-protocol.js.map +1 -0
- package/dist/solver/protocols/index.d.ts +10 -0
- package/dist/solver/protocols/index.d.ts.map +1 -0
- package/dist/solver/protocols/index.js +10 -0
- package/dist/solver/protocols/index.js.map +1 -0
- package/dist/solver/protocols/lending/aave.d.ts +51 -0
- package/dist/solver/protocols/lending/aave.d.ts.map +1 -0
- package/dist/solver/protocols/lending/aave.js +172 -0
- package/dist/solver/protocols/lending/aave.js.map +1 -0
- package/dist/solver/protocols/protocol-registry.d.ts +28 -0
- package/dist/solver/protocols/protocol-registry.d.ts.map +1 -0
- package/dist/solver/protocols/protocol-registry.js +40 -0
- package/dist/solver/protocols/protocol-registry.js.map +1 -0
- package/dist/solver/settlement/index.d.ts +7 -0
- package/dist/solver/settlement/index.d.ts.map +1 -0
- package/dist/solver/settlement/index.js +7 -0
- package/dist/solver/settlement/index.js.map +1 -0
- package/dist/solver/settlement/live-settlement-manager.d.ts +62 -0
- package/dist/solver/settlement/live-settlement-manager.d.ts.map +1 -0
- package/dist/solver/settlement/live-settlement-manager.js +68 -0
- package/dist/solver/settlement/live-settlement-manager.js.map +1 -0
- package/dist/solver/settlement/proof-generator.d.ts +48 -0
- package/dist/solver/settlement/proof-generator.d.ts.map +1 -0
- package/dist/solver/settlement/proof-generator.js +100 -0
- package/dist/solver/settlement/proof-generator.js.map +1 -0
- package/dist/solver/settlement/proof-verifier.d.ts +31 -0
- package/dist/solver/settlement/proof-verifier.d.ts.map +1 -0
- package/dist/solver/settlement/proof-verifier.js +46 -0
- package/dist/solver/settlement/proof-verifier.js.map +1 -0
- package/dist/solver/settlement/settlement-manager.d.ts +97 -0
- package/dist/solver/settlement/settlement-manager.d.ts.map +1 -0
- package/dist/solver/settlement/settlement-manager.js +220 -0
- package/dist/solver/settlement/settlement-manager.js.map +1 -0
- package/dist/solver/types/agent.d.ts +92 -0
- package/dist/solver/types/agent.d.ts.map +1 -0
- package/dist/solver/types/agent.js +8 -0
- package/dist/solver/types/agent.js.map +1 -0
- package/dist/solver/types/execution.d.ts +70 -0
- package/dist/solver/types/execution.d.ts.map +1 -0
- package/dist/solver/types/execution.js +7 -0
- package/dist/solver/types/execution.js.map +1 -0
- package/dist/solver/types/index.d.ts +13 -0
- package/dist/solver/types/index.d.ts.map +1 -0
- package/dist/solver/types/index.js +13 -0
- package/dist/solver/types/index.js.map +1 -0
- package/dist/solver/types/intent.d.ts +82 -0
- package/dist/solver/types/intent.d.ts.map +1 -0
- package/dist/solver/types/intent.js +33 -0
- package/dist/solver/types/intent.js.map +1 -0
- package/dist/solver/types/inventory.d.ts +83 -0
- package/dist/solver/types/inventory.d.ts.map +1 -0
- package/dist/solver/types/inventory.js +8 -0
- package/dist/solver/types/inventory.js.map +1 -0
- package/dist/solver/types/pricing.d.ts +59 -0
- package/dist/solver/types/pricing.d.ts.map +1 -0
- package/dist/solver/types/pricing.js +8 -0
- package/dist/solver/types/pricing.js.map +1 -0
- package/dist/solver/types/settlement.d.ts +98 -0
- package/dist/solver/types/settlement.d.ts.map +1 -0
- package/dist/solver/types/settlement.js +9 -0
- package/dist/solver/types/settlement.js.map +1 -0
- package/dist/types/chain.d.ts +66 -0
- package/dist/types/chain.d.ts.map +1 -0
- package/dist/types/chain.js +7 -0
- package/dist/types/chain.js.map +1 -0
- package/dist/types/common.d.ts +44 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +8 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/entities.d.ts +61 -0
- package/dist/types/entities.d.ts.map +1 -0
- package/dist/types/entities.js +2 -0
- package/dist/types/entities.js.map +1 -0
- package/dist/types/index.d.ts +44 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/intent.d.ts +70 -0
- package/dist/types/intent.d.ts.map +1 -0
- package/dist/types/intent.js +2 -0
- package/dist/types/intent.js.map +1 -0
- package/dist/types/templates.d.ts +18 -0
- package/dist/types/templates.d.ts.map +1 -0
- package/dist/types/templates.js +2 -0
- package/dist/types/templates.js.map +1 -0
- package/dist/types/token.d.ts +132 -0
- package/dist/types/token.d.ts.map +1 -0
- package/dist/types/token.js +8 -0
- package/dist/types/token.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swing Protocol Integration — Phase D (Live Integration)
|
|
3
|
+
*
|
|
4
|
+
* DEX/Bridge aggregator integration using Swing.xyz API.
|
|
5
|
+
* Provides quoting and transaction building for cross-chain inventory rebalancing.
|
|
6
|
+
*
|
|
7
|
+
* Phase D changes vs Phase I:
|
|
8
|
+
* - FetchHttpClient now handles HTTP 429 (rate limit) and 401 (auth) errors gracefully
|
|
9
|
+
* - Added getTokens(chainId) for on-chain token discovery from Swing API
|
|
10
|
+
* - quote() validates real Swing API v0 response shape more strictly
|
|
11
|
+
*/
|
|
12
|
+
import { BaseProtocol } from "../base-protocol";
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// HTTP Client
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
export class SwingAuthError extends Error {
|
|
17
|
+
constructor(message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = "SwingAuthError";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class SwingRateLimitError extends Error {
|
|
23
|
+
constructor(message) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = "SwingRateLimitError";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Default Fetch-based HTTP Client with Phase D error handling */
|
|
29
|
+
export class FetchHttpClient {
|
|
30
|
+
maxRetries;
|
|
31
|
+
constructor(maxRetries = 1) {
|
|
32
|
+
this.maxRetries = maxRetries;
|
|
33
|
+
}
|
|
34
|
+
async handleResponse(res, retryFn, attempt) {
|
|
35
|
+
if (res.status === 401) {
|
|
36
|
+
throw new SwingAuthError("Swing API key is invalid or missing. Please ensure your SWING_API_KEY is properly set.");
|
|
37
|
+
}
|
|
38
|
+
if (res.status === 429) {
|
|
39
|
+
if (attempt <= this.maxRetries) {
|
|
40
|
+
const retryAfter = res.headers.get("Retry-After");
|
|
41
|
+
const waitMs = retryAfter ? parseInt(retryAfter, 10) * 1000 : 2000;
|
|
42
|
+
console.warn(`[Swing] Rate limited (429). Retrying after ${waitMs}ms...`);
|
|
43
|
+
await new Promise(resolve => setTimeout(resolve, waitMs));
|
|
44
|
+
return retryFn();
|
|
45
|
+
}
|
|
46
|
+
throw new SwingRateLimitError("Swing API rate limit exceeded after maximum retries.");
|
|
47
|
+
}
|
|
48
|
+
if (!res.ok) {
|
|
49
|
+
let body = "";
|
|
50
|
+
try {
|
|
51
|
+
body = await res.text();
|
|
52
|
+
}
|
|
53
|
+
catch (e) { }
|
|
54
|
+
throw new Error(`HTTP Request failed: ${res.status} ${res.statusText} - ${body}`);
|
|
55
|
+
}
|
|
56
|
+
return res.json();
|
|
57
|
+
}
|
|
58
|
+
async get(url, headers, attempt = 1) {
|
|
59
|
+
const res = await fetch(url, { method: "GET", headers });
|
|
60
|
+
return this.handleResponse(res, () => this.get(url, headers, attempt + 1), attempt);
|
|
61
|
+
}
|
|
62
|
+
async post(url, body, headers, attempt = 1) {
|
|
63
|
+
const res = await fetch(url, {
|
|
64
|
+
method: "POST",
|
|
65
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
66
|
+
body: JSON.stringify(body),
|
|
67
|
+
});
|
|
68
|
+
return this.handleResponse(res, () => this.post(url, body, headers, attempt + 1), attempt);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
// SwingProtocol
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
export class SwingProtocol extends BaseProtocol {
|
|
75
|
+
apiKey;
|
|
76
|
+
httpClient;
|
|
77
|
+
baseUrl;
|
|
78
|
+
name = "swing";
|
|
79
|
+
type = "bridge";
|
|
80
|
+
// Currently supported common chains (1 = ETH, 137 = Polygon, 42161 = Arbitrum)
|
|
81
|
+
supportedChains = [1, 137, 42161, 10, 8453];
|
|
82
|
+
constructor(apiKey, httpClient = new FetchHttpClient(), baseUrl = "https://swap.prod.swing.xyz/v0") {
|
|
83
|
+
super();
|
|
84
|
+
this.apiKey = apiKey;
|
|
85
|
+
this.httpClient = httpClient;
|
|
86
|
+
this.baseUrl = baseUrl;
|
|
87
|
+
}
|
|
88
|
+
get headers() {
|
|
89
|
+
return {
|
|
90
|
+
"Accept": "application/json",
|
|
91
|
+
"x-swing-api-key": this.apiKey,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// -------------------------------------------------------------------------
|
|
95
|
+
// getTokens (NEW — Phase D)
|
|
96
|
+
// -------------------------------------------------------------------------
|
|
97
|
+
/**
|
|
98
|
+
* Fetch the list of tokens supported by Swing for a given chain.
|
|
99
|
+
*/
|
|
100
|
+
async getTokens(chainId) {
|
|
101
|
+
const url = `${this.baseUrl}/tokens?chain=${chainId}`;
|
|
102
|
+
try {
|
|
103
|
+
const data = await this.httpClient.get(url, this.headers);
|
|
104
|
+
// Note: Swing often returns an array directly, but sometimes it might be `{ tokens: [] }`
|
|
105
|
+
// Let's handle both dynamically
|
|
106
|
+
const items = Array.isArray(data) ? data : data.tokens;
|
|
107
|
+
if (!Array.isArray(items)) {
|
|
108
|
+
throw new Error(`Invalid response format from Swing tokens API for chain ${chainId}`);
|
|
109
|
+
}
|
|
110
|
+
return items.map((t) => ({
|
|
111
|
+
symbol: t.symbol,
|
|
112
|
+
address: t.address,
|
|
113
|
+
decimals: t.decimals,
|
|
114
|
+
name: t.name,
|
|
115
|
+
chainId: chainId,
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
if (error instanceof SwingAuthError || error instanceof SwingRateLimitError) {
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
throw new Error(`Failed to fetch tokens for chain ${chainId}: ${error.message}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// -------------------------------------------------------------------------
|
|
126
|
+
// quote
|
|
127
|
+
// -------------------------------------------------------------------------
|
|
128
|
+
/**
|
|
129
|
+
* Get a cross-chain quote from Swing API.
|
|
130
|
+
*/
|
|
131
|
+
async quote(params) {
|
|
132
|
+
const url = new URL(`${this.baseUrl}/transfer/quote`);
|
|
133
|
+
url.searchParams.append("fromChain", params.fromChain.toString());
|
|
134
|
+
url.searchParams.append("toChain", params.toChain.toString());
|
|
135
|
+
url.searchParams.append("fromToken", params.token);
|
|
136
|
+
url.searchParams.append("toToken", params.token);
|
|
137
|
+
url.searchParams.append("amount", params.amount.toString());
|
|
138
|
+
const data = await this.httpClient.get(url.toString(), this.headers);
|
|
139
|
+
// Validate response shape
|
|
140
|
+
if (!data.routes || data.routes.length === 0) {
|
|
141
|
+
throw new Error("No bridge routes found by Swing");
|
|
142
|
+
}
|
|
143
|
+
if (data.routes.length > 1) {
|
|
144
|
+
console.info(`[SwingProtocol] ${data.routes.length} routes available, using best route`);
|
|
145
|
+
}
|
|
146
|
+
const route = data.routes[0];
|
|
147
|
+
// Defensive: validate nested shape before accessing
|
|
148
|
+
if (!route?.quote?.integration) {
|
|
149
|
+
throw new Error("Swing API returned malformed route data (missing quote.integration)");
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
inputAmount: params.amount,
|
|
153
|
+
outputAmount: BigInt(route.quote.integration.amountOut || "0"),
|
|
154
|
+
fee: BigInt(route.quote.integration.fee || "0"),
|
|
155
|
+
estimatedTimeMs: (route.quote.integration.estimatedTime || 0) * 1000,
|
|
156
|
+
priceImpact: route.quote.integration.priceImpact || 0,
|
|
157
|
+
protocolName: this.name,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
// -------------------------------------------------------------------------
|
|
161
|
+
// buildTransaction
|
|
162
|
+
// -------------------------------------------------------------------------
|
|
163
|
+
/**
|
|
164
|
+
* Build the raw transaction (calldata) for the quoted route.
|
|
165
|
+
* Swing API typically returns the raw tx params we need to sign.
|
|
166
|
+
*/
|
|
167
|
+
async buildTransaction(quote, params) {
|
|
168
|
+
const body = {
|
|
169
|
+
fromChain: params.fromChain.toString(),
|
|
170
|
+
toChain: params.toChain.toString(),
|
|
171
|
+
fromToken: params.token,
|
|
172
|
+
toToken: params.token,
|
|
173
|
+
amount: params.amount.toString(),
|
|
174
|
+
fromUserAddress: params.recipient || "0x", // Required by Swing to build calldata
|
|
175
|
+
toUserAddress: params.recipient || "0x",
|
|
176
|
+
route: [
|
|
177
|
+
{
|
|
178
|
+
bridge: quote.protocolName, // Mock logic, usually from quote ID
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
};
|
|
182
|
+
const data = await this.httpClient.post(`${this.baseUrl}/transfer/send`, body, this.headers);
|
|
183
|
+
if (!data.tx) {
|
|
184
|
+
throw new Error("Swing API did not return transaction data");
|
|
185
|
+
}
|
|
186
|
+
return [
|
|
187
|
+
{
|
|
188
|
+
to: data.tx.to,
|
|
189
|
+
data: data.tx.data,
|
|
190
|
+
value: data.tx.value || "0",
|
|
191
|
+
chainId: params.fromChain,
|
|
192
|
+
gasLimit: data.tx.gas || "3000000",
|
|
193
|
+
}
|
|
194
|
+
];
|
|
195
|
+
}
|
|
196
|
+
// -------------------------------------------------------------------------
|
|
197
|
+
// getTransferStatus
|
|
198
|
+
// -------------------------------------------------------------------------
|
|
199
|
+
/**
|
|
200
|
+
* Get the status of an ongoing bridge transfer.
|
|
201
|
+
*/
|
|
202
|
+
async getTransferStatus(transferId) {
|
|
203
|
+
const data = await this.httpClient.get(`${this.baseUrl}/transfer/status/${transferId}`, this.headers);
|
|
204
|
+
const statusStr = data.status?.toLowerCase();
|
|
205
|
+
if (statusStr === "success" || statusStr === "done")
|
|
206
|
+
return "done";
|
|
207
|
+
if (statusStr === "failed" || statusStr === "error")
|
|
208
|
+
return "failed";
|
|
209
|
+
return "pending";
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=swing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swing.js","sourceRoot":"","sources":["../../../../src/solver/protocols/aggregators/swing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAA2D,MAAM,kBAAkB,CAAC;AAqBzG,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E,MAAM,OAAO,cAAe,SAAQ,KAAK;IACrC,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IACjC,CAAC;CACJ;AAED,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC1C,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACtC,CAAC;CACJ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for all protocol integrations (Swing, Aave, etc.).
|
|
5
|
+
* Provides uniform interface for the Rebalancer and other modules
|
|
6
|
+
* to interact with heterogeneous protocols.
|
|
7
|
+
*/
|
|
8
|
+
import type { Transaction } from "../types/execution";
|
|
9
|
+
export type ProtocolType = "bridge" | "lending" | "dex";
|
|
10
|
+
export interface ProtocolQuote {
|
|
11
|
+
inputAmount: bigint;
|
|
12
|
+
outputAmount: bigint;
|
|
13
|
+
fee: bigint;
|
|
14
|
+
estimatedTimeMs: number;
|
|
15
|
+
priceImpact?: number;
|
|
16
|
+
protocolName: string;
|
|
17
|
+
}
|
|
18
|
+
export interface QuoteParams {
|
|
19
|
+
fromChain: number;
|
|
20
|
+
toChain: number;
|
|
21
|
+
token: string;
|
|
22
|
+
amount: bigint;
|
|
23
|
+
recipient?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare abstract class BaseProtocol {
|
|
26
|
+
abstract readonly name: string;
|
|
27
|
+
abstract readonly type: ProtocolType;
|
|
28
|
+
abstract readonly supportedChains: number[];
|
|
29
|
+
/**
|
|
30
|
+
* Check if the protocol supports a given chainId.
|
|
31
|
+
*/
|
|
32
|
+
supports(chainId: number): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Get a price/route quote. Implementation depends on protocol type.
|
|
35
|
+
*/
|
|
36
|
+
abstract quote(params: QuoteParams): Promise<ProtocolQuote>;
|
|
37
|
+
/**
|
|
38
|
+
* Build one or more transactions to execute the quoted action.
|
|
39
|
+
*/
|
|
40
|
+
abstract buildTransaction(quote: ProtocolQuote, params: QuoteParams): Promise<Transaction[]>;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=base-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-protocol.d.ts","sourceRoot":"","sources":["../../../src/solver/protocols/base-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,SAAS,GAAG,KAAK,CAAC;AAExD,MAAM,WAAW,aAAa;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,8BAAsB,YAAY;IAC9B,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IACrC,QAAQ,CAAC,QAAQ,CAAC,eAAe,EAAE,MAAM,EAAE,CAAC;IAE5C;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIlC;;OAEG;IACH,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;IAE3D;;OAEG;IACH,QAAQ,CAAC,gBAAgB,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;CAC/F"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Protocol — Phase I
|
|
3
|
+
*
|
|
4
|
+
* Abstract base class for all protocol integrations (Swing, Aave, etc.).
|
|
5
|
+
* Provides uniform interface for the Rebalancer and other modules
|
|
6
|
+
* to interact with heterogeneous protocols.
|
|
7
|
+
*/
|
|
8
|
+
export class BaseProtocol {
|
|
9
|
+
/**
|
|
10
|
+
* Check if the protocol supports a given chainId.
|
|
11
|
+
*/
|
|
12
|
+
supports(chainId) {
|
|
13
|
+
return this.supportedChains.includes(chainId);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=base-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-protocol.js","sourceRoot":"","sources":["../../../src/solver/protocols/base-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAuBH,MAAM,OAAgB,YAAY;IAK9B;;OAEG;IACH,QAAQ,CAAC,OAAe;QACpB,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;CAWJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protocols Module — Phase I
|
|
3
|
+
*
|
|
4
|
+
* Exporting all protocol integrations and registry.
|
|
5
|
+
*/
|
|
6
|
+
export * from "./base-protocol";
|
|
7
|
+
export * from "./protocol-registry";
|
|
8
|
+
export * from "./aggregators/swing";
|
|
9
|
+
export * from "./lending/aave";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/solver/protocols/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protocols Module — Phase I
|
|
3
|
+
*
|
|
4
|
+
* Exporting all protocol integrations and registry.
|
|
5
|
+
*/
|
|
6
|
+
export * from "./base-protocol";
|
|
7
|
+
export * from "./protocol-registry";
|
|
8
|
+
export * from "./aggregators/swing";
|
|
9
|
+
export * from "./lending/aave";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/solver/protocols/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aave Protocol Integration — Phase I
|
|
3
|
+
*
|
|
4
|
+
* Lending protocol integration.
|
|
5
|
+
* Allows depositing idle inventory into Aave to earn APY, and withdrawing it
|
|
6
|
+
* when needed to fulfill intents.
|
|
7
|
+
*/
|
|
8
|
+
import { BaseProtocol, type ProtocolType, type ProtocolQuote, type QuoteParams } from "../base-protocol";
|
|
9
|
+
import type { Transaction } from "../../types/execution";
|
|
10
|
+
import type { RPCProviderManager } from "../../../shared/rpc/provider-manager";
|
|
11
|
+
import type { Address } from "../../../types/common";
|
|
12
|
+
export declare class AaveProtocol extends BaseProtocol {
|
|
13
|
+
/** Used for on-chain getReserveData calls to fetch APY */
|
|
14
|
+
private readonly rpcProviderManager;
|
|
15
|
+
/** Map of chainId -> Aave Pool contract address */
|
|
16
|
+
private readonly poolAddress;
|
|
17
|
+
/** Map of chainId -> Aave PoolDataProvider contract address */
|
|
18
|
+
private readonly dataProviderAddress;
|
|
19
|
+
readonly name = "aave";
|
|
20
|
+
readonly type: ProtocolType;
|
|
21
|
+
readonly supportedChains: number[];
|
|
22
|
+
constructor(
|
|
23
|
+
/** Used for on-chain getReserveData calls to fetch APY */
|
|
24
|
+
rpcProviderManager: RPCProviderManager,
|
|
25
|
+
/** Map of chainId -> Aave Pool contract address */
|
|
26
|
+
poolAddress: Record<number, Address>,
|
|
27
|
+
/** Map of chainId -> Aave PoolDataProvider contract address */
|
|
28
|
+
dataProviderAddress: Record<number, Address>);
|
|
29
|
+
/**
|
|
30
|
+
* Check if chain is supported and configured.
|
|
31
|
+
*/
|
|
32
|
+
supports(chainId: number): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Aave supply is 1:1, fee is just gas.
|
|
35
|
+
*/
|
|
36
|
+
quote(params: QuoteParams): Promise<ProtocolQuote>;
|
|
37
|
+
/**
|
|
38
|
+
* Build supply transaction(s).
|
|
39
|
+
* Retrieves two transactions: ERC-20 Approve + Aave supply()
|
|
40
|
+
*/
|
|
41
|
+
buildTransaction(quote: ProtocolQuote, params: QuoteParams): Promise<Transaction[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Query the current APY for supplying a specific token on a chain.
|
|
44
|
+
*/
|
|
45
|
+
getAPY(token: string, chainId: number): Promise<number>;
|
|
46
|
+
/**
|
|
47
|
+
* Helper to build a withdraw transaction.
|
|
48
|
+
*/
|
|
49
|
+
buildWithdraw(token: string, amount: bigint, chainId: number, toAddress: string): Promise<Transaction>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=aave.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aave.d.ts","sourceRoot":"","sources":["../../../../src/solver/protocols/lending/aave.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACzG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AA4BrD,qBAAa,YAAa,SAAQ,YAAY;IAMtC,0DAA0D;IAC1D,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,mDAAmD;IACnD,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,+DAA+D;IAC/D,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IAVxC,QAAQ,CAAC,IAAI,UAAU;IACvB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAa;IACxC,QAAQ,CAAC,eAAe,WAAmB;;IAGvC,0DAA0D;IACzC,kBAAkB,EAAE,kBAAkB;IACvD,mDAAmD;IAClC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACrD,+DAA+D;IAC9C,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAKjE;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIlC;;OAEG;IACG,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;IAWxD;;;OAGG;IACG,gBAAgB,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAmCzF;;OAEG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAwD7D;;OAEG;IACG,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAkB/G"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aave Protocol Integration — Phase I
|
|
3
|
+
*
|
|
4
|
+
* Lending protocol integration.
|
|
5
|
+
* Allows depositing idle inventory into Aave to earn APY, and withdrawing it
|
|
6
|
+
* when needed to fulfill intents.
|
|
7
|
+
*/
|
|
8
|
+
import { BaseProtocol } from "../base-protocol";
|
|
9
|
+
import { decodeFunctionResult } from "viem";
|
|
10
|
+
const ERC20_APPROVE_SIG = "0x095ea7b3"; // approve(address,uint256)
|
|
11
|
+
const AAVE_SUPPLY_SIG = "0x617ba037"; // supply(address,uint256,address,uint16)
|
|
12
|
+
const AAVE_WITHDRAW_SIG = "0x69328dec"; // withdraw(address,uint256,address)
|
|
13
|
+
const AAVE_DATA_PROVIDER_ABI = [{
|
|
14
|
+
"inputs": [{ "internalType": "address", "name": "asset", "type": "address" }],
|
|
15
|
+
"name": "getReserveData",
|
|
16
|
+
"outputs": [
|
|
17
|
+
{ "internalType": "uint256", "name": "unbacked", "type": "uint256" },
|
|
18
|
+
{ "internalType": "uint256", "name": "accruedToTreasuryScaled", "type": "uint256" },
|
|
19
|
+
{ "internalType": "uint256", "name": "totalAToken", "type": "uint256" },
|
|
20
|
+
{ "internalType": "uint256", "name": "totalStableDebt", "type": "uint256" },
|
|
21
|
+
{ "internalType": "uint256", "name": "totalVariableDebt", "type": "uint256" },
|
|
22
|
+
{ "internalType": "uint256", "name": "liquidityRate", "type": "uint256" },
|
|
23
|
+
{ "internalType": "uint256", "name": "variableBorrowRate", "type": "uint256" },
|
|
24
|
+
{ "internalType": "uint256", "name": "stableBorrowRate", "type": "uint256" },
|
|
25
|
+
{ "internalType": "uint256", "name": "averageStableBorrowRate", "type": "uint256" },
|
|
26
|
+
{ "internalType": "uint256", "name": "liquidityIndex", "type": "uint256" },
|
|
27
|
+
{ "internalType": "uint256", "name": "variableBorrowIndex", "type": "uint256" },
|
|
28
|
+
{ "internalType": "uint40", "name": "lastUpdateTimestamp", "type": "uint40" }
|
|
29
|
+
],
|
|
30
|
+
"stateMutability": "view",
|
|
31
|
+
"type": "function"
|
|
32
|
+
}];
|
|
33
|
+
export class AaveProtocol extends BaseProtocol {
|
|
34
|
+
rpcProviderManager;
|
|
35
|
+
poolAddress;
|
|
36
|
+
dataProviderAddress;
|
|
37
|
+
name = "aave";
|
|
38
|
+
type = "lending";
|
|
39
|
+
supportedChains = [1, 137, 42161]; // Aave v3 networks
|
|
40
|
+
constructor(
|
|
41
|
+
/** Used for on-chain getReserveData calls to fetch APY */
|
|
42
|
+
rpcProviderManager,
|
|
43
|
+
/** Map of chainId -> Aave Pool contract address */
|
|
44
|
+
poolAddress,
|
|
45
|
+
/** Map of chainId -> Aave PoolDataProvider contract address */
|
|
46
|
+
dataProviderAddress) {
|
|
47
|
+
super();
|
|
48
|
+
this.rpcProviderManager = rpcProviderManager;
|
|
49
|
+
this.poolAddress = poolAddress;
|
|
50
|
+
this.dataProviderAddress = dataProviderAddress;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if chain is supported and configured.
|
|
54
|
+
*/
|
|
55
|
+
supports(chainId) {
|
|
56
|
+
return this.supportedChains.includes(chainId) && !!this.poolAddress[chainId] && !!this.dataProviderAddress[chainId];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Aave supply is 1:1, fee is just gas.
|
|
60
|
+
*/
|
|
61
|
+
async quote(params) {
|
|
62
|
+
return {
|
|
63
|
+
inputAmount: params.amount,
|
|
64
|
+
outputAmount: params.amount,
|
|
65
|
+
fee: 0n, // Protocol fee is 0, user pays gas when executing Tx
|
|
66
|
+
estimatedTimeMs: 15_000,
|
|
67
|
+
priceImpact: 0,
|
|
68
|
+
protocolName: this.name,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Build supply transaction(s).
|
|
73
|
+
* Retrieves two transactions: ERC-20 Approve + Aave supply()
|
|
74
|
+
*/
|
|
75
|
+
async buildTransaction(quote, params) {
|
|
76
|
+
const chainId = params.fromChain;
|
|
77
|
+
const pool = this.poolAddress[chainId];
|
|
78
|
+
if (!pool)
|
|
79
|
+
throw new Error(`Aave not configured for chain ${chainId}`);
|
|
80
|
+
// Mocking ABI encoding for simplicity. In prod use ethers.Interface
|
|
81
|
+
const paddedAmt = params.amount.toString(16).padStart(64, "0");
|
|
82
|
+
const paddedPool = pool.replace("0x", "").padStart(64, "0");
|
|
83
|
+
const approveData = `${ERC20_APPROVE_SIG}${paddedPool}${paddedAmt}`;
|
|
84
|
+
const paddedAsset = params.token.replace("0x", "").padStart(64, "0");
|
|
85
|
+
const paddedOnBehalfOf = (params.recipient || "0x0000000000000000000000000000000000000000").replace("0x", "").padStart(64, "0");
|
|
86
|
+
const paddedReferral = "0".padStart(64, "0");
|
|
87
|
+
const supplyData = `${AAVE_SUPPLY_SIG}${paddedAsset}${paddedAmt}${paddedOnBehalfOf}${paddedReferral}`;
|
|
88
|
+
return [
|
|
89
|
+
{
|
|
90
|
+
to: params.token, // Target the ERC20 contract
|
|
91
|
+
data: approveData,
|
|
92
|
+
value: "0",
|
|
93
|
+
chainId,
|
|
94
|
+
gasLimit: "50000",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
to: pool, // Target the Aave Pool
|
|
98
|
+
data: supplyData,
|
|
99
|
+
value: "0",
|
|
100
|
+
chainId,
|
|
101
|
+
gasLimit: "250000",
|
|
102
|
+
}
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Query the current APY for supplying a specific token on a chain.
|
|
107
|
+
*/
|
|
108
|
+
async getAPY(token, chainId) {
|
|
109
|
+
if (!this.supports(chainId)) {
|
|
110
|
+
throw new Error(`Aave not supported/configured for chain ${chainId}`);
|
|
111
|
+
}
|
|
112
|
+
const dataProvider = this.dataProviderAddress[chainId];
|
|
113
|
+
const provider = this.rpcProviderManager.getProvider(chainId);
|
|
114
|
+
// Function signature: getReserveData(address asset) -> 0x35ea6a75
|
|
115
|
+
const functionSelector = "0x35ea6a75";
|
|
116
|
+
const paddedToken = token.toLowerCase().replace("0x", "").padStart(64, "0");
|
|
117
|
+
const calldata = `${functionSelector}${paddedToken}`;
|
|
118
|
+
try {
|
|
119
|
+
const result = await provider.call(dataProvider, calldata);
|
|
120
|
+
if (!result || result === "0x") {
|
|
121
|
+
// Token has no reserve data on Aave for this chain
|
|
122
|
+
throw new Error("Empty response from Aave Data Provider — probably unsupported token");
|
|
123
|
+
}
|
|
124
|
+
// Decode the massive tuple using viem
|
|
125
|
+
const decoded = decodeFunctionResult({
|
|
126
|
+
abi: AAVE_DATA_PROVIDER_ABI,
|
|
127
|
+
functionName: "getReserveData",
|
|
128
|
+
data: result,
|
|
129
|
+
});
|
|
130
|
+
// decoded is an array (or object if named) of the tuple.
|
|
131
|
+
// the 6th element (index 5) is liquidityRate (APR in ray) as per ABI outputs.
|
|
132
|
+
const liquidityRateRay = BigInt(decoded[5]);
|
|
133
|
+
if (liquidityRateRay === 0n)
|
|
134
|
+
return 0; // No liquidity
|
|
135
|
+
// Convert liquidityRate (APR in ray) to APY
|
|
136
|
+
const RAY = 1e27;
|
|
137
|
+
const SECONDS_PER_YEAR = 31536000;
|
|
138
|
+
const depositAPR = Number(liquidityRateRay) / RAY;
|
|
139
|
+
// Compound interest formula: APY = (1 + APR / SECONDS_PER_YEAR) ^ SECONDS_PER_YEAR - 1
|
|
140
|
+
const apy = (Math.pow(1 + depositAPR / SECONDS_PER_YEAR, SECONDS_PER_YEAR) - 1) * 100;
|
|
141
|
+
return apy;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
if (error.message.includes("execution reverted")) {
|
|
145
|
+
// Aave PoolDataProvider reverts if the token is not an active reserve
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
console.error(`[Aave] Failed to fetch APY for ${token} on chain ${chainId}:`, error.message);
|
|
149
|
+
throw new Error(`Failed to fetch APY from Aave: ${error.message}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Helper to build a withdraw transaction.
|
|
154
|
+
*/
|
|
155
|
+
async buildWithdraw(token, amount, chainId, toAddress) {
|
|
156
|
+
const pool = this.poolAddress[chainId];
|
|
157
|
+
if (!pool)
|
|
158
|
+
throw new Error(`Aave not configured for chain ${chainId}`);
|
|
159
|
+
const paddedAsset = token.replace("0x", "").padStart(64, "0");
|
|
160
|
+
const paddedAmt = amount.toString(16).padStart(64, "0");
|
|
161
|
+
const paddedTo = toAddress.replace("0x", "").padStart(64, "0");
|
|
162
|
+
const withdrawData = `${AAVE_WITHDRAW_SIG}${paddedAsset}${paddedAmt}${paddedTo}`;
|
|
163
|
+
return {
|
|
164
|
+
to: pool,
|
|
165
|
+
data: withdrawData,
|
|
166
|
+
value: "0",
|
|
167
|
+
chainId,
|
|
168
|
+
gasLimit: "250000",
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=aave.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aave.js","sourceRoot":"","sources":["../../../../src/solver/protocols/lending/aave.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAA2D,MAAM,kBAAkB,CAAC;AAIzG,OAAO,EAAE,oBAAoB,EAAE,MAAM,MAAM,CAAC;AAE5C,MAAM,iBAAiB,GAAG,YAAY,CAAC,CAAC,2BAA2B;AACnE,MAAM,eAAe,GAAG,YAAY,CAAC,CAAC,yCAAyC;AAC/E,MAAM,iBAAiB,GAAG,YAAY,CAAC,CAAC,oCAAoC;AAE5E,MAAM,sBAAsB,GAAG,CAAC;QAC5B,QAAQ,EAAE,CAAC,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAC7E,MAAM,EAAE,gBAAgB;QACxB,SAAS,EAAE;YACP,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE;YACpE,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,yBAAyB,EAAE,MAAM,EAAE,SAAS,EAAE;YACnF,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE;YACvE,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,EAAE;YAC3E,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE,SAAS,EAAE;YAC7E,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe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Aa,EAAE,MAAc,EAAE,OAAe,EAAE,SAAiB;QACjF,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,OAAO,EAAE,CAAC,CAAC;QAEvE,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;QAC9D,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;QACxD,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;QAE/D,MAAM,YAAY,GAAG,GAAG,iBAAiB,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,EAAE,CAAC;QAEjF,OAAO;YACH,EAAE,EAAE,IAAI;YACR,IAAI,EAAE,YAAY;YAClB,KAAK,EAAE,GAAG;YACV,OAAO;YACP,QAAQ,EAAE,QAAQ;SACrB,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protocol Registry — Phase I
|
|
3
|
+
*
|
|
4
|
+
* Central registry for looking up available protocol integrations.
|
|
5
|
+
* Used by the Rebalancer to find the best available bridge for a given route.
|
|
6
|
+
*/
|
|
7
|
+
import { BaseProtocol, type ProtocolType } from "./base-protocol";
|
|
8
|
+
export declare class ProtocolRegistry {
|
|
9
|
+
private protocols;
|
|
10
|
+
/**
|
|
11
|
+
* Register a new protocol instance.
|
|
12
|
+
*/
|
|
13
|
+
register(protocol: BaseProtocol): void;
|
|
14
|
+
/**
|
|
15
|
+
* Get a protocol by its unique name.
|
|
16
|
+
*/
|
|
17
|
+
get(name: string): BaseProtocol | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Get all registered protocols, optionally filtered by type.
|
|
20
|
+
*/
|
|
21
|
+
getAll(type?: ProtocolType): BaseProtocol[];
|
|
22
|
+
/**
|
|
23
|
+
* Find the first bridge protocol that supports both the source and target chains.
|
|
24
|
+
* Uses registration order as implicit priority.
|
|
25
|
+
*/
|
|
26
|
+
getBestBridge(fromChain: number, toChain: number): BaseProtocol | undefined;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=protocol-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-registry.d.ts","sourceRoot":"","sources":["../../../src/solver/protocols/protocol-registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAElE,qBAAa,gBAAgB;IACzB,OAAO,CAAC,SAAS,CAAwC;IAEzD;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI;IAItC;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAI3C;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,EAAE,YAAY,GAAG,YAAY,EAAE;IAQ3C;;;OAGG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAI9E"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protocol Registry — Phase I
|
|
3
|
+
*
|
|
4
|
+
* Central registry for looking up available protocol integrations.
|
|
5
|
+
* Used by the Rebalancer to find the best available bridge for a given route.
|
|
6
|
+
*/
|
|
7
|
+
export class ProtocolRegistry {
|
|
8
|
+
protocols = new Map();
|
|
9
|
+
/**
|
|
10
|
+
* Register a new protocol instance.
|
|
11
|
+
*/
|
|
12
|
+
register(protocol) {
|
|
13
|
+
this.protocols.set(protocol.name, protocol);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get a protocol by its unique name.
|
|
17
|
+
*/
|
|
18
|
+
get(name) {
|
|
19
|
+
return this.protocols.get(name);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get all registered protocols, optionally filtered by type.
|
|
23
|
+
*/
|
|
24
|
+
getAll(type) {
|
|
25
|
+
const all = Array.from(this.protocols.values());
|
|
26
|
+
if (type) {
|
|
27
|
+
return all.filter((p) => p.type === type);
|
|
28
|
+
}
|
|
29
|
+
return all;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Find the first bridge protocol that supports both the source and target chains.
|
|
33
|
+
* Uses registration order as implicit priority.
|
|
34
|
+
*/
|
|
35
|
+
getBestBridge(fromChain, toChain) {
|
|
36
|
+
const bridges = this.getAll("bridge");
|
|
37
|
+
return bridges.find((b) => b.supports(fromChain) && b.supports(toChain));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=protocol-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-registry.js","sourceRoot":"","sources":["../../../src/solver/protocols/protocol-registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,OAAO,gBAAgB;IACjB,SAAS,GAA8B,IAAI,GAAG,EAAE,CAAC;IAEzD;;OAEG;IACH,QAAQ,CAAC,QAAsB;QAC3B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,IAAY;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAmB;QACtB,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;QAChD,IAAI,IAAI,EAAE,CAAC;YACP,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IAED;;;OAGG;IACH,aAAa,CAAC,SAAiB,EAAE,OAAe;QAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACtC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7E,CAAC;CACJ"}
|