@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,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fee Calculator
|
|
3
|
+
*
|
|
4
|
+
* Menghitung total biaya yang dikenakan solver kepada user.
|
|
5
|
+
* Fee terdiri dari tiga komponen:
|
|
6
|
+
*
|
|
7
|
+
* 1. BASE FEE — persentase dari amount (default 0.5%)
|
|
8
|
+
* 2. GAS COST — estimasi biaya gas dalam token (USDC)
|
|
9
|
+
* 3. SLIPPAGE CAPTURE — bagian dari max slippage user yang solver ambil
|
|
10
|
+
*
|
|
11
|
+
* FORMULA:
|
|
12
|
+
* totalFee = baseFee + gasCost + slippageCapture
|
|
13
|
+
* userReceives = amount - totalFee
|
|
14
|
+
* solverProfit = totalFee - gasCost
|
|
15
|
+
*
|
|
16
|
+
* EXAMPLE (1000 USDC, ETH→Polygon):
|
|
17
|
+
* baseFee = 5 USDC (0.5%)
|
|
18
|
+
* gasCost = 3 USDC (ETH mainnet involved)
|
|
19
|
+
* slippageCapture = 5 USDC (50% of 1% max slippage on 1000 USDC)
|
|
20
|
+
* totalFee = 13 USDC
|
|
21
|
+
* solverProfit = 10 USDC
|
|
22
|
+
*/
|
|
23
|
+
import { SlippageCapture } from "./slippage-capture";
|
|
24
|
+
// Chain ID constants untuk mencegah magic numbers
|
|
25
|
+
const ETHEREUM_MAINNET_ID = 1;
|
|
26
|
+
export class FeeCalculator {
|
|
27
|
+
config;
|
|
28
|
+
slippageCapture;
|
|
29
|
+
constructor(config) {
|
|
30
|
+
this.config = config;
|
|
31
|
+
this.slippageCapture = new SlippageCapture(config);
|
|
32
|
+
}
|
|
33
|
+
// ─────────────────────────────────────────────
|
|
34
|
+
// Public API
|
|
35
|
+
// ─────────────────────────────────────────────
|
|
36
|
+
/**
|
|
37
|
+
* Hitung full fee breakdown untuk sebuah bridge intent.
|
|
38
|
+
*
|
|
39
|
+
* Langkah:
|
|
40
|
+
* 1. Hitung base fee dari `amount * baseFeePercent`, clamp ke [minFee, maxFee]
|
|
41
|
+
* 2. Estimasi gas cost via `estimateGasCost()`
|
|
42
|
+
* 3. Hitung slippage capture via `SlippageCapture.calculate()`
|
|
43
|
+
* 4. Gabungkan menjadi PricingResult
|
|
44
|
+
*
|
|
45
|
+
* @param params - FeeCalculationParams
|
|
46
|
+
* @returns PricingResult dengan semua fee breakdown
|
|
47
|
+
*/
|
|
48
|
+
calculate(params) {
|
|
49
|
+
// 1. Base Fee
|
|
50
|
+
const tokenDecimals = params.tokenDecimals ?? 6;
|
|
51
|
+
const baseFee = this.calculateBaseFee(params.amount, tokenDecimals);
|
|
52
|
+
// 2. Gas Cost
|
|
53
|
+
const gasCost = this.estimateGasCost(params.sourceChain, params.targetChain);
|
|
54
|
+
// 3. Slippage Capture — delegasi ke SlippageCapture
|
|
55
|
+
const slippageCapture = this.slippageCapture.calculate(params.amount, params.maxSlippageBps);
|
|
56
|
+
// 4. Totals
|
|
57
|
+
const totalFee = baseFee + gasCost + slippageCapture;
|
|
58
|
+
let userReceives = params.amount - totalFee;
|
|
59
|
+
if (userReceives < 0n)
|
|
60
|
+
userReceives = 0n;
|
|
61
|
+
const solverProfit = totalFee - gasCost;
|
|
62
|
+
return {
|
|
63
|
+
baseFee: baseFee.toString(),
|
|
64
|
+
gasCost: gasCost.toString(),
|
|
65
|
+
slippageCapture: slippageCapture.toString(),
|
|
66
|
+
totalFee: totalFee.toString(),
|
|
67
|
+
userPays: params.amount.toString(),
|
|
68
|
+
userReceives: userReceives.toString(),
|
|
69
|
+
solverProfit: solverProfit.toString(),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Hitung base fee saja dari sebuah amount.
|
|
74
|
+
*
|
|
75
|
+
* Berguna untuk quick check profitabilitas tanpa full pricing.
|
|
76
|
+
*
|
|
77
|
+
* @param amount - Amount dalam token's smallest unit
|
|
78
|
+
* @param tokenDecimals - Jumlah desimal token (default 6 untuk USDC)
|
|
79
|
+
* @returns Base fee dalam token's smallest unit (bigint)
|
|
80
|
+
*/
|
|
81
|
+
calculateBaseFee(amount, tokenDecimals = 6) {
|
|
82
|
+
// config.baseFeePercent is e.g. 0.005. Convert to BPS: 0.005 * 10000 = 50.
|
|
83
|
+
const baseFeeBps = BigInt(Math.round(this.config.baseFeePercent * 10000));
|
|
84
|
+
const fee = (amount * baseFeeBps) / 10000n;
|
|
85
|
+
// Min Fee: $1 * 10^decimals. Assumes 1 USDC = $1 (stablecoin-centric for now).
|
|
86
|
+
const minFee = BigInt(Math.floor(this.config.minFeeUSD)) * (10n ** BigInt(tokenDecimals));
|
|
87
|
+
// Max Fee cap: prevent excessive fees on very large transfers
|
|
88
|
+
const maxFeeBps = BigInt(Math.floor(this.config.maxFeePercent * 10000));
|
|
89
|
+
const maxFee = (amount * maxFeeBps) / 10000n;
|
|
90
|
+
// minFeeUSD is a hard floor — takes priority over maxFeePercent for tiny amounts.
|
|
91
|
+
// This is intentional: fixed operational costs must be covered regardless of %.
|
|
92
|
+
if (fee < minFee)
|
|
93
|
+
return minFee;
|
|
94
|
+
if (fee > maxFee)
|
|
95
|
+
return maxFee;
|
|
96
|
+
return fee;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Estimasi biaya gas dalam token equivalent (USDC).
|
|
100
|
+
*
|
|
101
|
+
* Logika:
|
|
102
|
+
* - Cross-chain (sourceChain !== targetChain) jauh lebih mahal dari single-chain
|
|
103
|
+
* - Ethereum mainnet memiliki gas cost tertinggi karena konsensus proof-of-stake
|
|
104
|
+
* dan tingginya demand block space
|
|
105
|
+
* - L2 (Polygon, Arbitrum) jauh lebih murah
|
|
106
|
+
*
|
|
107
|
+
* Gunakan hardcoded baseline yang akan diganti real gas oracle di Phase I.
|
|
108
|
+
*
|
|
109
|
+
* @param sourceChain - Chain ID asal
|
|
110
|
+
* @param targetChain - Chain ID tujuan (opsional, untuk cross-chain estimate)
|
|
111
|
+
* @returns Gas cost estimasi dalam USDC (6 decimals, bigint)
|
|
112
|
+
*/
|
|
113
|
+
estimateGasCost(sourceChain, targetChain) {
|
|
114
|
+
const USDC_UNIT = 10000n; // 1 USDC = 1_000_000 (6 decimals)
|
|
115
|
+
// Single chain — cheap (e.g. same-chain swap)
|
|
116
|
+
if (targetChain && sourceChain === targetChain) {
|
|
117
|
+
return (50n * USDC_UNIT) / 100n; // 0.50 USDC
|
|
118
|
+
}
|
|
119
|
+
// Cross-chain path involving Ethereum Mainnet is significantly more expensive
|
|
120
|
+
const involvesEth = sourceChain === ETHEREUM_MAINNET_ID || targetChain === ETHEREUM_MAINNET_ID;
|
|
121
|
+
if (involvesEth) {
|
|
122
|
+
return 3n * USDC_UNIT; // $3.00 — ETH L1 gas premium
|
|
123
|
+
}
|
|
124
|
+
// L2 to L2 (e.g., Polygon ↔ Arbitrum) — cheap
|
|
125
|
+
return 1n * USDC_UNIT; // $1.00 baseline
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Cek apakah sebuah intent worth solving (profitable setelah fee).
|
|
129
|
+
*
|
|
130
|
+
* Intent tidak worth solving jika:
|
|
131
|
+
* - Amount terlalu kecil sehingga fee > amount
|
|
132
|
+
* - Cross-chain gas cost > baseFee (loss scenario)
|
|
133
|
+
*
|
|
134
|
+
* Note: Slippage capture diabaikan di sini (conservative check).
|
|
135
|
+
*
|
|
136
|
+
* @param amount - Amount dalam token's smallest unit
|
|
137
|
+
* @param sourceChain - Chain ID asal
|
|
138
|
+
* @param targetChain - Chain ID tujuan
|
|
139
|
+
* @returns true jika worth solving, false jika tidak
|
|
140
|
+
*/
|
|
141
|
+
isWorthSolving(amount, sourceChain, targetChain) {
|
|
142
|
+
const baseFee = this.calculateBaseFee(amount);
|
|
143
|
+
const gasCost = this.estimateGasCost(sourceChain, targetChain);
|
|
144
|
+
// Base fee alone must cover gas cost (conservative, ignores slippage capture profit)
|
|
145
|
+
const solverProfit = baseFee - gasCost;
|
|
146
|
+
return solverProfit >= 0n;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=fee-calculator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fee-calculator.js","sourceRoot":"","sources":["../../../src/solver/pricing/fee-calculator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,kDAAkD;AAClD,MAAM,mBAAmB,GAAY,CAAC,CAAC;AAyBvC,MAAM,OAAO,aAAa;IAID;IAHJ,eAAe,CAAkB;IAElD,YACqB,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;QAEtC,IAAI,C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ED,8CAA8C;QAC9C,OAAO,EAAE,GAAG,SAAS,CAAC,CAAC,iBAAiB;IAC5C,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,cAAc,CAAC,MAAc,EAAE,WAAoB,EAAE,WAAoB;QACrE,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;QAC9C,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QAE/D,qFAAqF;QACrF,MAAM,YAAY,GAAG,OAAO,GAAG,OAAO,CAAC;QAEvC,OAAO,YAAY,IAAI,EAAE,CAAC;IAC9B,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/solver/pricing/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/solver/pricing/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slippage Capture
|
|
3
|
+
*
|
|
4
|
+
* Menghitung "slippage profit" — keuntungan tambahan solver
|
|
5
|
+
* dari selisih antara max slippage yang diizinkan user dan
|
|
6
|
+
* slippage aktual yang terjadi di market.
|
|
7
|
+
*
|
|
8
|
+
* KONSEP:
|
|
9
|
+
* User mengizinkan max 1% slippage untuk bridge 1000 USDC.
|
|
10
|
+
* Solver hanya butuh 0% slippage (karena punya inventory pre-funded).
|
|
11
|
+
* Maka solver dapat capture 50% dari 1% = 0.5% = 5 USDC profit.
|
|
12
|
+
*
|
|
13
|
+
* FORMULA:
|
|
14
|
+
* captureAmount = amount × (maxSlippageBps / 10_000) × slippageSharePercent
|
|
15
|
+
* userEffectiveOutput = amount - captureAmount
|
|
16
|
+
*
|
|
17
|
+
* EXAMPLE:
|
|
18
|
+
* amount = 1_000_000_000 (1000 USDC, 6 decimals)
|
|
19
|
+
* maxSlippageBps = 100 (1%)
|
|
20
|
+
* sharePercent = 0.5 (50%)
|
|
21
|
+
* captureAmount = 1000 × 0.01 × 0.5 = 5 USDC = 5_000_000
|
|
22
|
+
*/
|
|
23
|
+
import type { PricingConfig } from "../types/pricing";
|
|
24
|
+
export declare class SlippageCapture {
|
|
25
|
+
private readonly config;
|
|
26
|
+
constructor(config: PricingConfig);
|
|
27
|
+
/**
|
|
28
|
+
* Hitung berapa banyak slippage yang bisa di-capture solver.
|
|
29
|
+
*
|
|
30
|
+
* Gunakan integer math sepenuhnya untuk menghindari floating point error.
|
|
31
|
+
* Basis point (1/10000) digunakan untuk semua perhitungan persentase.
|
|
32
|
+
*
|
|
33
|
+
* @param amount - Amount yang di-bridge dalam token smallest unit
|
|
34
|
+
* @param maxSlippageBps - Max slippage yang diizinkan user dalam basis points (100 = 1%)
|
|
35
|
+
* @returns Jumlah slippage yang di-capture, dalam token smallest unit (bigint)
|
|
36
|
+
*/
|
|
37
|
+
calculate(amount: bigint, maxSlippageBps: number): bigint;
|
|
38
|
+
/**
|
|
39
|
+
* Hitung output efektif yang diterima user setelah slippage capture.
|
|
40
|
+
*
|
|
41
|
+
* @param amount - Amount asli yang di-bridge (sebelum fees)
|
|
42
|
+
* @param captureAmount - Slippage yang di-capture (hasil dari calculate())
|
|
43
|
+
* @returns Amount yang diterima user, clamped ke 0 jika negative
|
|
44
|
+
*/
|
|
45
|
+
getEffectiveUserOutput(amount: bigint, captureAmount: bigint): bigint;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=slippage-capture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slippage-capture.d.ts","sourceRoot":"","sources":["../../../src/solver/pricing/slippage-capture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,qBAAa,eAAe;IAEpB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAO1C;;;;;;;;;OASG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM;IAazD;;;;;;OAMG;IACH,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM;CAIxE"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slippage Capture
|
|
3
|
+
*
|
|
4
|
+
* Menghitung "slippage profit" — keuntungan tambahan solver
|
|
5
|
+
* dari selisih antara max slippage yang diizinkan user dan
|
|
6
|
+
* slippage aktual yang terjadi di market.
|
|
7
|
+
*
|
|
8
|
+
* KONSEP:
|
|
9
|
+
* User mengizinkan max 1% slippage untuk bridge 1000 USDC.
|
|
10
|
+
* Solver hanya butuh 0% slippage (karena punya inventory pre-funded).
|
|
11
|
+
* Maka solver dapat capture 50% dari 1% = 0.5% = 5 USDC profit.
|
|
12
|
+
*
|
|
13
|
+
* FORMULA:
|
|
14
|
+
* captureAmount = amount × (maxSlippageBps / 10_000) × slippageSharePercent
|
|
15
|
+
* userEffectiveOutput = amount - captureAmount
|
|
16
|
+
*
|
|
17
|
+
* EXAMPLE:
|
|
18
|
+
* amount = 1_000_000_000 (1000 USDC, 6 decimals)
|
|
19
|
+
* maxSlippageBps = 100 (1%)
|
|
20
|
+
* sharePercent = 0.5 (50%)
|
|
21
|
+
* captureAmount = 1000 × 0.01 × 0.5 = 5 USDC = 5_000_000
|
|
22
|
+
*/
|
|
23
|
+
export class SlippageCapture {
|
|
24
|
+
config;
|
|
25
|
+
constructor(config) {
|
|
26
|
+
this.config = config;
|
|
27
|
+
}
|
|
28
|
+
// ─────────────────────────────────────────────
|
|
29
|
+
// Public API
|
|
30
|
+
// ─────────────────────────────────────────────
|
|
31
|
+
/**
|
|
32
|
+
* Hitung berapa banyak slippage yang bisa di-capture solver.
|
|
33
|
+
*
|
|
34
|
+
* Gunakan integer math sepenuhnya untuk menghindari floating point error.
|
|
35
|
+
* Basis point (1/10000) digunakan untuk semua perhitungan persentase.
|
|
36
|
+
*
|
|
37
|
+
* @param amount - Amount yang di-bridge dalam token smallest unit
|
|
38
|
+
* @param maxSlippageBps - Max slippage yang diizinkan user dalam basis points (100 = 1%)
|
|
39
|
+
* @returns Jumlah slippage yang di-capture, dalam token smallest unit (bigint)
|
|
40
|
+
*/
|
|
41
|
+
calculate(amount, maxSlippageBps) {
|
|
42
|
+
if (maxSlippageBps <= 0)
|
|
43
|
+
return 0n;
|
|
44
|
+
// Clamp ke 100% tanpa mutate parameter asli
|
|
45
|
+
const effectiveSlippageBps = Math.min(maxSlippageBps, 10000);
|
|
46
|
+
const shareBps = BigInt(Math.floor(this.config.slippageSharePercent * 10000));
|
|
47
|
+
const slippageBps = BigInt(effectiveSlippageBps);
|
|
48
|
+
// amount * (maxSlippage / 10000) * (share / 10000)
|
|
49
|
+
return (amount * slippageBps * shareBps) / (10000n * 10000n);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Hitung output efektif yang diterima user setelah slippage capture.
|
|
53
|
+
*
|
|
54
|
+
* @param amount - Amount asli yang di-bridge (sebelum fees)
|
|
55
|
+
* @param captureAmount - Slippage yang di-capture (hasil dari calculate())
|
|
56
|
+
* @returns Amount yang diterima user, clamped ke 0 jika negative
|
|
57
|
+
*/
|
|
58
|
+
getEffectiveUserOutput(amount, captureAmount) {
|
|
59
|
+
const result = amount - captureAmount;
|
|
60
|
+
return result > 0n ? result : 0n;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=slippage-capture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slippage-capture.js","sourceRoot":"","sources":["../../../src/solver/pricing/slippage-capture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,MAAM,OAAO,eAAe;IAEH;IADrB,YACqB,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IACtC,CAAC;IAEL,gDAAgD;IAChD,aAAa;IACb,gDAAgD;IAEhD;;;;;;;;;OASG;IACH,SAAS,CAAC,MAAc,EAAE,cAAsB;QAC5C,IAAI,cAAc,IAAI,CAAC;YAAE,OAAO,EAAE,CAAC;QAEnC,4CAA4C;QAC5C,MAAM,oBAAoB,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;QAE7D,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,oBAAoB,GAAG,KAAK,CAAC,CAAC,CAAC;QAC9E,MAAM,WAAW,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;QAEjD,mDAAmD;QACnD,OAAO,CAAC,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IACjE,CAAC;IAED;;;;;;OAMG;IACH,sBAAsB,CAAC,MAAc,EAAE,aAAqB;QACxD,MAAM,MAAM,GAAG,MAAM,GAAG,aAAa,CAAC;QACtC,OAAO,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACrC,CAAC;CACJ"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Li.Fi Protocol Integration — Phase D (Live Integration)
|
|
3
|
+
*
|
|
4
|
+
* DEX/Bridge aggregator integration using Li.Fi API (https://li.quest/v1/)
|
|
5
|
+
* Provides quoting and transaction building for cross-chain inventory rebalancing
|
|
6
|
+
* WITHOUT requiring an API Key.
|
|
7
|
+
*/
|
|
8
|
+
import { BaseProtocol, type ProtocolQuote, type QuoteParams } from "../base-protocol";
|
|
9
|
+
import type { Transaction, ExecutionResult } from "../../types/execution";
|
|
10
|
+
import type { IBridgeProtocol } from "../../inventory/rebalancer";
|
|
11
|
+
import { type IHttpClient } from "./swing";
|
|
12
|
+
export interface LiFiQuoteRequest {
|
|
13
|
+
fromChain: string;
|
|
14
|
+
toChain: string;
|
|
15
|
+
fromToken: string;
|
|
16
|
+
toToken: string;
|
|
17
|
+
fromAmount: string;
|
|
18
|
+
fromAddress: string;
|
|
19
|
+
toAddress?: string;
|
|
20
|
+
slippage?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface LiFiQuoteResponse {
|
|
23
|
+
type: string;
|
|
24
|
+
id: string;
|
|
25
|
+
tool: string;
|
|
26
|
+
action: {
|
|
27
|
+
fromChainId: number;
|
|
28
|
+
toChainId: number;
|
|
29
|
+
fromToken: any;
|
|
30
|
+
toToken: any;
|
|
31
|
+
fromAmount: string;
|
|
32
|
+
slippage: number;
|
|
33
|
+
};
|
|
34
|
+
estimate: {
|
|
35
|
+
tool: string;
|
|
36
|
+
approvalAddress: string;
|
|
37
|
+
toAmount: string;
|
|
38
|
+
toAmountMin: string;
|
|
39
|
+
fromAmountUSD: string;
|
|
40
|
+
toAmountUSD: string;
|
|
41
|
+
executionDuration: number;
|
|
42
|
+
feeCosts: Array<{
|
|
43
|
+
name: string;
|
|
44
|
+
description: string;
|
|
45
|
+
amount: string;
|
|
46
|
+
amountUSD: string;
|
|
47
|
+
token: any;
|
|
48
|
+
}>;
|
|
49
|
+
gasCosts: Array<{
|
|
50
|
+
type: string;
|
|
51
|
+
amount: string;
|
|
52
|
+
amountUSD: string;
|
|
53
|
+
estimate: string;
|
|
54
|
+
limit: string;
|
|
55
|
+
token: any;
|
|
56
|
+
}>;
|
|
57
|
+
};
|
|
58
|
+
transactionRequest?: {
|
|
59
|
+
data: string;
|
|
60
|
+
to: string;
|
|
61
|
+
value: string;
|
|
62
|
+
from: string;
|
|
63
|
+
chainId: number;
|
|
64
|
+
gasLimit: string;
|
|
65
|
+
gasPrice: string;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export declare class LiFiProtocol extends BaseProtocol implements IBridgeProtocol {
|
|
69
|
+
readonly name = "Li.Fi";
|
|
70
|
+
readonly type = "bridge";
|
|
71
|
+
readonly supportedChains: number[];
|
|
72
|
+
private readonly baseUrl;
|
|
73
|
+
private readonly httpClient;
|
|
74
|
+
private readonly defaultHeaders;
|
|
75
|
+
constructor(httpClient?: IHttpClient);
|
|
76
|
+
/**
|
|
77
|
+
* Get a cross-chain quote using Li.Fi API.
|
|
78
|
+
*
|
|
79
|
+
* Li.Fi REQUIRES `fromAddress` even for a simple quote.
|
|
80
|
+
*/
|
|
81
|
+
quote(params: QuoteParams & {
|
|
82
|
+
slippagePercent?: number;
|
|
83
|
+
fromAddress?: string;
|
|
84
|
+
}): Promise<ProtocolQuote & {
|
|
85
|
+
rawResponse?: any;
|
|
86
|
+
}>;
|
|
87
|
+
/**
|
|
88
|
+
* Build the raw transaction data for execution.
|
|
89
|
+
* Li.Fi already provides the `transactionRequest` inside the `/quote` response
|
|
90
|
+
* if `fromAddress` was provided. So we can just extract it.
|
|
91
|
+
*/
|
|
92
|
+
buildTransaction(quote: ProtocolQuote & {
|
|
93
|
+
rawResponse?: any;
|
|
94
|
+
}, params: QuoteParams & {
|
|
95
|
+
fromAddress?: string;
|
|
96
|
+
}): Promise<Transaction[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Implementing IBridgeProtocol for Rebalancer.
|
|
99
|
+
* Note: Rebalancer uses slightly different signatures than BaseProtocol.
|
|
100
|
+
*/
|
|
101
|
+
bridge(params: {
|
|
102
|
+
fromChain: number;
|
|
103
|
+
toChain: number;
|
|
104
|
+
token: string;
|
|
105
|
+
amount: bigint;
|
|
106
|
+
recipient: string;
|
|
107
|
+
}): Promise<ExecutionResult>;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=lifi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifi.d.ts","sourceRoot":"","sources":["../../../../src/solver/protocols/aggregators/lifi.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,KAAK,WAAW,EAAmB,MAAM,SAAS,CAAC;AAM5D,MAAM,WAAW,gBAAgB;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QACJ,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,GAAG,CAAC;QACf,OAAO,EAAE,GAAG,CAAC;QACb,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,QAAQ,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,eAAe,EAAE,MAAM,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;QACpB,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,E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G,CAAA;KAAE,CAAC;IA6CrI;;;;OAIG;IACG,gBAAgB,CAAC,KAAK,EAAE,aAAa,GAAG;QAAE,WAAW,CAAC,EAAE,GAAG,CAAA;KAAE,EAAE,MAAM,EAAE,WAAW,GAAG;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAwB5I;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,eAAe,CAAC;CAM/B"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Li.Fi Protocol Integration — Phase D (Live Integration)
|
|
3
|
+
*
|
|
4
|
+
* DEX/Bridge aggregator integration using Li.Fi API (https://li.quest/v1/)
|
|
5
|
+
* Provides quoting and transaction building for cross-chain inventory rebalancing
|
|
6
|
+
* WITHOUT requiring an API Key.
|
|
7
|
+
*/
|
|
8
|
+
import { BaseProtocol } from "../base-protocol";
|
|
9
|
+
import { FetchHttpClient } from "./swing"; // Reusing the HTTP Client
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// LiFiProtocol
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
export class LiFiProtocol extends BaseProtocol {
|
|
14
|
+
name = "Li.Fi";
|
|
15
|
+
type = "bridge";
|
|
16
|
+
supportedChains = [1, 10, 56, 137, 42161, 43114]; // Common EVM chains
|
|
17
|
+
baseUrl = "https://li.quest/v1";
|
|
18
|
+
httpClient;
|
|
19
|
+
defaultHeaders;
|
|
20
|
+
constructor(httpClient) {
|
|
21
|
+
super();
|
|
22
|
+
this.httpClient = httpClient || new FetchHttpClient(2);
|
|
23
|
+
this.defaultHeaders = {
|
|
24
|
+
"Accept": "application/json",
|
|
25
|
+
"x-lifi-integrator": "intent-parser-sdk" // Good practice to identify traffic
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get a cross-chain quote using Li.Fi API.
|
|
30
|
+
*
|
|
31
|
+
* Li.Fi REQUIRES `fromAddress` even for a simple quote.
|
|
32
|
+
*/
|
|
33
|
+
async quote(params) {
|
|
34
|
+
const url = new URL(`${this.baseUrl}/quote`);
|
|
35
|
+
url.searchParams.append("fromChain", params.fromChain.toString());
|
|
36
|
+
url.searchParams.append("toChain", params.toChain.toString());
|
|
37
|
+
url.searchParams.append("fromToken", params.token);
|
|
38
|
+
url.searchParams.append("toToken", params.token);
|
|
39
|
+
url.searchParams.append("fromAmount", params.amount.toString());
|
|
40
|
+
// Slippage is 0.03 = 3% by default in LiFi, we can pass it as decimal
|
|
41
|
+
if (params.slippagePercent !== undefined) {
|
|
42
|
+
url.searchParams.append("slippage", (params.slippagePercent / 100).toString());
|
|
43
|
+
}
|
|
44
|
+
// Li.Fi requires a fromAddress. If none provided, use a dummy active address (Vitalik's) to get an estimate
|
|
45
|
+
const fromAddress = params.fromAddress || "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
46
|
+
url.searchParams.append("fromAddress", fromAddress);
|
|
47
|
+
let data;
|
|
48
|
+
try {
|
|
49
|
+
data = await this.httpClient.get(url.toString(), this.defaultHeaders);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
throw new Error(`Li.Fi API Error: ${error.message}`);
|
|
53
|
+
}
|
|
54
|
+
// Extract total fees (gas + protocol fees) in smallest unit of the toToken
|
|
55
|
+
// For simplicity in this SDK phase, we sum them up if they exist, but usually they are paid in native gas
|
|
56
|
+
let totalFeeStr = "0";
|
|
57
|
+
if (data.estimate.feeCosts && data.estimate.feeCosts.length > 0) {
|
|
58
|
+
totalFeeStr = data.estimate.feeCosts.reduce((acc, curr) => {
|
|
59
|
+
return (BigInt(acc) + BigInt(curr.amount)).toString();
|
|
60
|
+
}, "0");
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
inputAmount: params.amount,
|
|
64
|
+
outputAmount: BigInt(data.estimate.toAmount),
|
|
65
|
+
fee: BigInt(totalFeeStr), // This is an approximation
|
|
66
|
+
estimatedTimeMs: data.estimate.executionDuration * 1000,
|
|
67
|
+
priceImpact: 0, // Not explicitly provided as a single field
|
|
68
|
+
protocolName: this.name,
|
|
69
|
+
// Store the raw transaction request so buildTransaction can use it
|
|
70
|
+
rawResponse: data.transactionRequest
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Build the raw transaction data for execution.
|
|
75
|
+
* Li.Fi already provides the `transactionRequest` inside the `/quote` response
|
|
76
|
+
* if `fromAddress` was provided. So we can just extract it.
|
|
77
|
+
*/
|
|
78
|
+
async buildTransaction(quote, params) {
|
|
79
|
+
// We call quote again but guarantee fromAddress is passed if not already present
|
|
80
|
+
let finalQuote = quote;
|
|
81
|
+
if (!finalQuote.rawResponse) {
|
|
82
|
+
if (!params.fromAddress) {
|
|
83
|
+
throw new Error("Li.Fi did not return transaction data. Ensure fromAddress is provided.");
|
|
84
|
+
}
|
|
85
|
+
finalQuote = await this.quote(params);
|
|
86
|
+
if (!finalQuote.rawResponse) {
|
|
87
|
+
throw new Error("Li.Fi did not return transaction data even after retry.");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const txRequest = finalQuote.rawResponse;
|
|
91
|
+
return [{
|
|
92
|
+
to: txRequest.to,
|
|
93
|
+
data: txRequest.data,
|
|
94
|
+
value: BigInt(txRequest.value).toString(),
|
|
95
|
+
chainId: txRequest.chainId,
|
|
96
|
+
gasLimit: BigInt(txRequest.gasLimit || "500000").toString(),
|
|
97
|
+
}];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Implementing IBridgeProtocol for Rebalancer.
|
|
101
|
+
* Note: Rebalancer uses slightly different signatures than BaseProtocol.
|
|
102
|
+
*/
|
|
103
|
+
async bridge(params) {
|
|
104
|
+
return {
|
|
105
|
+
success: false,
|
|
106
|
+
error: "Bridge execution should be done via wallet manager in LiquidityAgent, not directly in protocol class."
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=lifi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifi.js","sourceRoot":"","sources":["../../../../src/solver/protocols/aggregators/lifi.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAwC,MAAM,kBAAkB,CAAC;AAGtF,OAAO,EAAoB,eAAe,EAAE,MAAM,SAAS,CAAC,CAAC,0BAA0B;AAgEvF,8EAA8E;AAC9E,eAAe;AACf,8EAA8E;AAE9E,MAAM,OAAO,YAAa,SAAQ,YAAY;IACjC,IAAI,GAAG,OAAO,CAAC;IACf,IAAI,GAAG,QAAQ,CAAC;IAChB,eAAe,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,oBAAoB;IAE9D,OAAO,GAAG,qBAAqB,CAAC;IAChC,UAAU,CAAc;IACxB,cAAc,CAAyB;IAExD,YACI,UAAwB;QAExB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,UAAU,IAAI,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC;QACvD,IAAI,CAAC,cAAc,GAAG;YAClB,QAAQ,EAAE,kBAAkB;YAC5B,mBAAmB,EAAE,mBAAmB,CAAC,oCAAoC;SAChF,CAAC;IACN,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAK,CAAC,MAAwE;QAChF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,QAAQ,CAAC,CAAC;QAC7C,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,SA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,EAAE,SAAS,CAAC,EAAmB;gBACjC,IAAI,EAAE,SAAS,CAAC,IAAqB;gBACrC,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;gBACzC,OAAO,EAAE,SAAS,CAAC,OAAO;gBAC1B,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,IAAI,QAAQ,CAAC,CAAC,QAAQ,EAAE;aAC9D,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,MAMZ;QACG,OAAO;YACH,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,uGAAuG;SACjH,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,67 @@
|
|
|
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, type ProtocolType, type ProtocolQuote, type QuoteParams } from "../base-protocol";
|
|
13
|
+
import type { Transaction } from "../../types/execution";
|
|
14
|
+
export interface IHttpClient {
|
|
15
|
+
get(url: string, headers?: Record<string, string>): Promise<any>;
|
|
16
|
+
post(url: string, body: any, headers?: Record<string, string>): Promise<any>;
|
|
17
|
+
}
|
|
18
|
+
/** Token info returned by Swing /tokens endpoint */
|
|
19
|
+
export interface SwingToken {
|
|
20
|
+
symbol: string;
|
|
21
|
+
address: string;
|
|
22
|
+
decimals: number;
|
|
23
|
+
name: string;
|
|
24
|
+
chainId: number;
|
|
25
|
+
}
|
|
26
|
+
export declare class SwingAuthError extends Error {
|
|
27
|
+
constructor(message: string);
|
|
28
|
+
}
|
|
29
|
+
export declare class SwingRateLimitError extends Error {
|
|
30
|
+
constructor(message: string);
|
|
31
|
+
}
|
|
32
|
+
/** Default Fetch-based HTTP Client with Phase D error handling */
|
|
33
|
+
export declare class FetchHttpClient implements IHttpClient {
|
|
34
|
+
private readonly maxRetries;
|
|
35
|
+
constructor(maxRetries?: number);
|
|
36
|
+
private handleResponse;
|
|
37
|
+
get(url: string, headers?: Record<string, string>, attempt?: number): Promise<any>;
|
|
38
|
+
post(url: string, body: any, headers?: Record<string, string>, attempt?: number): Promise<any>;
|
|
39
|
+
}
|
|
40
|
+
export declare class SwingProtocol extends BaseProtocol {
|
|
41
|
+
private readonly apiKey;
|
|
42
|
+
private readonly httpClient;
|
|
43
|
+
private readonly baseUrl;
|
|
44
|
+
readonly name = "swing";
|
|
45
|
+
readonly type: ProtocolType;
|
|
46
|
+
readonly supportedChains: number[];
|
|
47
|
+
constructor(apiKey: string, httpClient?: IHttpClient, baseUrl?: string);
|
|
48
|
+
private get headers();
|
|
49
|
+
/**
|
|
50
|
+
* Fetch the list of tokens supported by Swing for a given chain.
|
|
51
|
+
*/
|
|
52
|
+
getTokens(chainId: number): Promise<SwingToken[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Get a cross-chain quote from Swing API.
|
|
55
|
+
*/
|
|
56
|
+
quote(params: QuoteParams): Promise<ProtocolQuote>;
|
|
57
|
+
/**
|
|
58
|
+
* Build the raw transaction (calldata) for the quoted route.
|
|
59
|
+
* Swing API typically returns the raw tx params we need to sign.
|
|
60
|
+
*/
|
|
61
|
+
buildTransaction(quote: ProtocolQuote, params: QuoteParams): Promise<Transaction[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Get the status of an ongoing bridge transfer.
|
|
64
|
+
*/
|
|
65
|
+
getTransferStatus(transferId: string): Promise<"pending" | "done" | "failed">;
|
|
66
|
+
}
|
|
67
|
+
//# s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