@gibs/bridge-client 1.30.1 → 1.32.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/coinbase-accept-list/package.json +6 -0
- package/dist/cjs/client.d.ts +9 -1
- package/dist/cjs/client.js +8 -5
- package/dist/cjs/coinbase-accept-list.d.ts +101 -0
- package/dist/cjs/coinbase-accept-list.js +97 -0
- package/dist/cjs/crossing-decision.d.ts +166 -0
- package/dist/cjs/crossing-decision.js +169 -0
- package/dist/cjs/crossing-vector-guard.d.ts +45 -0
- package/dist/cjs/crossing-vector-guard.js +139 -0
- package/dist/cjs/exchange-deposit-board.d.ts +50 -0
- package/dist/cjs/exchange-deposit-board.js +70 -0
- package/dist/cjs/exchange-deposit-chain.d.ts +146 -0
- package/dist/cjs/exchange-deposit-chain.js +228 -0
- package/dist/cjs/exchange-deposit-constants.d.ts +10 -0
- package/dist/cjs/exchange-deposit-constants.js +6 -0
- package/dist/cjs/exchange-deposit-factory-calls.d.ts +245 -0
- package/dist/cjs/exchange-deposit-factory-calls.js +103 -0
- package/dist/cjs/exchange-deposit-factory.d.ts +87 -0
- package/dist/cjs/exchange-deposit-factory.js +110 -0
- package/dist/cjs/exchange-deposit-fake.d.ts +67 -0
- package/dist/cjs/exchange-deposit-fake.js +179 -0
- package/dist/cjs/exchange-deposit-index.d.ts +77 -0
- package/dist/cjs/exchange-deposit-index.js +40 -0
- package/dist/cjs/exchange-deposit-issuance.d.ts +327 -0
- package/dist/cjs/exchange-deposit-issuance.js +244 -0
- package/dist/cjs/exchange-deposit-path.d.ts +16 -0
- package/dist/cjs/exchange-deposit-path.js +15 -0
- package/dist/cjs/exchange-deposit-pow.d.ts +163 -0
- package/dist/cjs/exchange-deposit-pow.js +101 -0
- package/dist/cjs/exchange-deposit-recipient.d.ts +66 -0
- package/dist/cjs/exchange-deposit-recipient.js +35 -0
- package/dist/cjs/exchange-deposit-self-cross.d.ts +163 -0
- package/dist/cjs/exchange-deposit-self-cross.js +60 -0
- package/dist/cjs/exchange-deposit-signin.d.ts +275 -0
- package/dist/cjs/exchange-deposit-signin.js +166 -0
- package/dist/cjs/exchange-deposit-watch.d.ts +133 -0
- package/dist/cjs/exchange-deposit-watch.js +58 -0
- package/dist/cjs/exchange-deposit.d.ts +440 -0
- package/dist/cjs/exchange-deposit.js +154 -0
- package/dist/cjs/exchange-sender-guides.d.ts +29 -0
- package/dist/cjs/exchange-sender-guides.js +25 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +24 -1
- package/dist/cjs/kraken-accept-list.d.ts +70 -0
- package/dist/cjs/kraken-accept-list.js +24 -0
- package/dist/client.d.ts +9 -1
- package/dist/client.js +8 -5
- package/dist/coinbase-accept-list.d.ts +101 -0
- package/dist/coinbase-accept-list.js +89 -0
- package/dist/crossing-decision.d.ts +166 -0
- package/dist/crossing-decision.js +162 -0
- package/dist/crossing-vector-guard.d.ts +45 -0
- package/dist/crossing-vector-guard.js +134 -0
- package/dist/exchange-deposit-board.d.ts +50 -0
- package/dist/exchange-deposit-board.js +28 -0
- package/dist/exchange-deposit-chain.d.ts +146 -0
- package/dist/exchange-deposit-chain.js +218 -0
- package/dist/exchange-deposit-constants.d.ts +10 -0
- package/dist/exchange-deposit-constants.js +3 -0
- package/dist/exchange-deposit-factory-calls.d.ts +245 -0
- package/dist/exchange-deposit-factory-calls.js +97 -0
- package/dist/exchange-deposit-factory.d.ts +87 -0
- package/dist/exchange-deposit-factory.js +104 -0
- package/dist/exchange-deposit-fake.d.ts +67 -0
- package/dist/exchange-deposit-fake.js +171 -0
- package/dist/exchange-deposit-index.d.ts +77 -0
- package/dist/exchange-deposit-index.js +34 -0
- package/dist/exchange-deposit-issuance.d.ts +327 -0
- package/dist/exchange-deposit-issuance.js +224 -0
- package/dist/exchange-deposit-path.d.ts +16 -0
- package/dist/exchange-deposit-path.js +11 -0
- package/dist/exchange-deposit-pow.d.ts +163 -0
- package/dist/exchange-deposit-pow.js +93 -0
- package/dist/exchange-deposit-recipient.d.ts +66 -0
- package/dist/exchange-deposit-recipient.js +28 -0
- package/dist/exchange-deposit-self-cross.d.ts +163 -0
- package/dist/exchange-deposit-self-cross.js +46 -0
- package/dist/exchange-deposit-signin.d.ts +275 -0
- package/dist/exchange-deposit-signin.js +147 -0
- package/dist/exchange-deposit-watch.d.ts +133 -0
- package/dist/exchange-deposit-watch.js +44 -0
- package/dist/exchange-deposit.d.ts +440 -0
- package/dist/exchange-deposit.js +138 -0
- package/dist/exchange-sender-guides.d.ts +29 -0
- package/dist/exchange-sender-guides.js +21 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/kraken-accept-list.d.ts +70 -0
- package/dist/kraken-accept-list.js +17 -0
- package/exchange-deposit/package.json +6 -0
- package/exchange-deposit-board/package.json +6 -0
- package/exchange-deposit-chain/package.json +6 -0
- package/exchange-deposit-factory/package.json +6 -0
- package/exchange-deposit-fake/package.json +6 -0
- package/exchange-deposit-issuance/package.json +6 -0
- package/exchange-deposit-path/package.json +6 -0
- package/exchange-deposit-pow/package.json +6 -0
- package/exchange-deposit-recipient/package.json +6 -0
- package/exchange-deposit-self-cross/package.json +6 -0
- package/exchange-deposit-signin/package.json +6 -0
- package/exchange-deposit-watch/package.json +6 -0
- package/exchange-sender-guides/package.json +6 -0
- package/kraken-accept-list/package.json +6 -0
- package/package.json +429 -4
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exchangeDepositNeedsGasLimitWarning = exports.exchangeDepositAddressMatchesSelection = exports.preferredExchangeDepositToken = exports.feeRatePercent = exports.coverageOfAddress = exports.exchangeDepositStage = exports.crossingCoverage = exports.exchangeDepositGasTableOf = exports.EXCHANGE_DEPOSIT_GAS_TABLE_NAME_BY_CHAIN = exports.exchangeDepositSelectionReducer = exports.EXCHANGE_DEPOSIT_INITIAL_SELECTION = exports.assertFeeRatesWithinLimits = exports.feeRateOptionsOf = exports.EXCHANGE_DEPOSIT_FEE_LIMITS_UNREADABLE = exports.EXCHANGE_DEPOSIT_DEFAULT_FEE_RATE_E18 = exports.EXCHANGE_DEPOSIT_FEE_RATES = exports.FEE_RATE_SCALE = exports.WEI_PER_ETHER = exports.SEPOLIA_CHAIN_ID = exports.ETHEREUM_MAINNET_CHAIN_ID = void 0;
|
|
4
|
+
const exchange_deposit_constants_js_1 = require("./exchange-deposit-constants.js");
|
|
5
|
+
Object.defineProperty(exports, "ETHEREUM_MAINNET_CHAIN_ID", { enumerable: true, get: function () { return exchange_deposit_constants_js_1.ETHEREUM_MAINNET_CHAIN_ID; } });
|
|
6
|
+
Object.defineProperty(exports, "SEPOLIA_CHAIN_ID", { enumerable: true, get: function () { return exchange_deposit_constants_js_1.SEPOLIA_CHAIN_ID; } });
|
|
7
|
+
Object.defineProperty(exports, "WEI_PER_ETHER", { enumerable: true, get: function () { return exchange_deposit_constants_js_1.WEI_PER_ETHER; } });
|
|
8
|
+
const viem_1 = require("viem");
|
|
9
|
+
const crossing_decision_js_1 = require("./crossing-decision.js");
|
|
10
|
+
const exchange_deposit_factory_js_1 = require("./exchange-deposit-factory.js");
|
|
11
|
+
const exchange_deposit_index_js_1 = require("./exchange-deposit-index.js");
|
|
12
|
+
const exchange_deposit_recipient_js_1 = require("./exchange-deposit-recipient.js");
|
|
13
|
+
exports.FEE_RATE_SCALE = 10n ** 18n;
|
|
14
|
+
exports.EXCHANGE_DEPOSIT_FEE_RATES = [0n, 10n ** 16n, 5n * 10n ** 15n, 25n * 10n ** 14n];
|
|
15
|
+
exports.EXCHANGE_DEPOSIT_DEFAULT_FEE_RATE_E18 = 10n ** 16n;
|
|
16
|
+
exports.EXCHANGE_DEPOSIT_FEE_LIMITS_UNREADABLE = "The deposit factory's fee limits could not be read. No fee can be chosen and no address can be built until they can.";
|
|
17
|
+
const feeRateOptionsOf = ({ presets, limits, }) => {
|
|
18
|
+
if (limits === null)
|
|
19
|
+
return [];
|
|
20
|
+
return presets.filter((rate) => rate <= limits.maximumFeeRateE18);
|
|
21
|
+
};
|
|
22
|
+
exports.feeRateOptionsOf = feeRateOptionsOf;
|
|
23
|
+
const assertFeeRatesWithinLimits = ({ feeRateE18, partnerRateE18, limits, }) => {
|
|
24
|
+
if (limits === null)
|
|
25
|
+
throw new Error(exports.EXCHANGE_DEPOSIT_FEE_LIMITS_UNREADABLE);
|
|
26
|
+
if (feeRateE18 < 0n || feeRateE18 > limits.maximumFeeRateE18) {
|
|
27
|
+
throw new Error(`the fee rate must be 0 to ${limits.maximumFeeRateE18}, the factory maximum`);
|
|
28
|
+
}
|
|
29
|
+
if (partnerRateE18 < 0n || partnerRateE18 > limits.maximumPartnerRateE18) {
|
|
30
|
+
throw new Error(`the partner rate must be 0 to ${limits.maximumPartnerRateE18}, the factory maximum`);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.assertFeeRatesWithinLimits = assertFeeRatesWithinLimits;
|
|
34
|
+
const RATIO_SCALE = 10000n;
|
|
35
|
+
exports.EXCHANGE_DEPOSIT_INITIAL_SELECTION = {
|
|
36
|
+
tokenAddress: null,
|
|
37
|
+
feeRateE18: exports.EXCHANGE_DEPOSIT_DEFAULT_FEE_RATE_E18,
|
|
38
|
+
counter: null,
|
|
39
|
+
};
|
|
40
|
+
const exchangeDepositSelectionReducer = (selection, action) => {
|
|
41
|
+
if (action.kind === 'choose-token')
|
|
42
|
+
return { ...selection, tokenAddress: action.tokenAddress, counter: null };
|
|
43
|
+
if (action.kind === 'choose-fee')
|
|
44
|
+
return { ...selection, feeRateE18: action.feeRateE18, counter: null };
|
|
45
|
+
return { ...selection, counter: action.counter };
|
|
46
|
+
};
|
|
47
|
+
exports.exchangeDepositSelectionReducer = exchangeDepositSelectionReducer;
|
|
48
|
+
const LIMIT_WITHOUT_BRIDGE_READ = 2n ** 192n;
|
|
49
|
+
exports.EXCHANGE_DEPOSIT_GAS_TABLE_NAME_BY_CHAIN = new Map([
|
|
50
|
+
[exchange_deposit_constants_js_1.ETHEREUM_MAINNET_CHAIN_ID, 'ethereum-prague'],
|
|
51
|
+
[exchange_deposit_constants_js_1.SEPOLIA_CHAIN_ID, 'sepolia-glamsterdam'],
|
|
52
|
+
]);
|
|
53
|
+
const exchangeDepositGasTableOf = (chainId) => {
|
|
54
|
+
const name = exports.EXCHANGE_DEPOSIT_GAS_TABLE_NAME_BY_CHAIN.get(chainId);
|
|
55
|
+
if (name === undefined)
|
|
56
|
+
throw new Error(`no gas table is chosen for chain ${chainId}`);
|
|
57
|
+
return (0, crossing_decision_js_1.gasTableOf)(name, chainId);
|
|
58
|
+
};
|
|
59
|
+
exports.exchangeDepositGasTableOf = exchangeDepositGasTableOf;
|
|
60
|
+
const crossingCoverage = ({ token, waiting, feeRateE18, conditions }) => {
|
|
61
|
+
const minimumAmount = conditions.minimumPerTxByAddress[token.address.toLowerCase()] ?? null;
|
|
62
|
+
const decision = (0, crossing_decision_js_1.decideCrossing)({
|
|
63
|
+
specVersion: crossing_decision_js_1.CROSSING_SPEC_VERSION,
|
|
64
|
+
conditions: {
|
|
65
|
+
baseFeeWei: conditions.baseFeeWei,
|
|
66
|
+
priorityFeeWei: conditions.priorityFeeWei,
|
|
67
|
+
maximumBaseFeeWei: null,
|
|
68
|
+
safetyMultipleThousandths: conditions.multipleThousandths,
|
|
69
|
+
gasModel: conditions.gasTable.gasModel,
|
|
70
|
+
},
|
|
71
|
+
deposit: {
|
|
72
|
+
retired: false,
|
|
73
|
+
crossingInFlight: false,
|
|
74
|
+
feeRateE18,
|
|
75
|
+
token: token.address.toLowerCase(),
|
|
76
|
+
decimals: BigInt(token.decimals),
|
|
77
|
+
balance: waiting,
|
|
78
|
+
autoCrossAllowed: true,
|
|
79
|
+
weiPerWholeToken: conditions.weiPerWholeTokenByAddress[token.address.toLowerCase()] ?? null,
|
|
80
|
+
entryFeeWad: 0n,
|
|
81
|
+
minPerTx: minimumAmount,
|
|
82
|
+
maxPerTx: LIMIT_WITHOUT_BRIDGE_READ,
|
|
83
|
+
dailyRemaining: LIMIT_WITHOUT_BRIDGE_READ,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
const { thresholdAmount, costWei } = decision;
|
|
87
|
+
const covered = decision.outcome === 'execute';
|
|
88
|
+
const belowBridgeMinimum = minimumAmount !== null && waiting > 0n && waiting < minimumAmount;
|
|
89
|
+
return {
|
|
90
|
+
decision,
|
|
91
|
+
thresholdAmount,
|
|
92
|
+
waitingAmount: waiting,
|
|
93
|
+
ratio: ratioOf({ waiting, thresholdAmount }),
|
|
94
|
+
costInEther: costWei,
|
|
95
|
+
covered,
|
|
96
|
+
minimumAmount,
|
|
97
|
+
belowBridgeMinimum,
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
exports.crossingCoverage = crossingCoverage;
|
|
101
|
+
const ratioOf = ({ waiting, thresholdAmount }) => {
|
|
102
|
+
if (thresholdAmount === null)
|
|
103
|
+
return 0;
|
|
104
|
+
if (thresholdAmount === 0n)
|
|
105
|
+
return 1;
|
|
106
|
+
return Number((waiting * RATIO_SCALE) / thresholdAmount) / Number(RATIO_SCALE);
|
|
107
|
+
};
|
|
108
|
+
const exchangeDepositStage = ({ coverage, crossing, }) => {
|
|
109
|
+
if (crossing !== null)
|
|
110
|
+
return 'crossing';
|
|
111
|
+
if (coverage.waitingAmount === 0n)
|
|
112
|
+
return 'empty';
|
|
113
|
+
if (coverage.covered)
|
|
114
|
+
return 'ready';
|
|
115
|
+
return 'partway';
|
|
116
|
+
};
|
|
117
|
+
exports.exchangeDepositStage = exchangeDepositStage;
|
|
118
|
+
const coverageOfAddress = ({ address, conditions, }) => (0, exports.crossingCoverage)({
|
|
119
|
+
token: address.token,
|
|
120
|
+
waiting: address.waiting,
|
|
121
|
+
feeRateE18: address.settings.feeRateE18,
|
|
122
|
+
conditions,
|
|
123
|
+
});
|
|
124
|
+
exports.coverageOfAddress = coverageOfAddress;
|
|
125
|
+
const feeRatePercent = (feeRateE18) => Number(feeRateE18 / 10n ** 14n) / 100;
|
|
126
|
+
exports.feeRatePercent = feeRatePercent;
|
|
127
|
+
const preferredExchangeDepositToken = ({ tokens, preferredAddress, }) => {
|
|
128
|
+
if (preferredAddress === null)
|
|
129
|
+
return null;
|
|
130
|
+
const match = tokens.find((token) => token.address.toLowerCase() === preferredAddress.toLowerCase());
|
|
131
|
+
return match?.address ?? null;
|
|
132
|
+
};
|
|
133
|
+
exports.preferredExchangeDepositToken = preferredExchangeDepositToken;
|
|
134
|
+
const exchangeDepositAddressMatchesSelection = ({ address, recipient, tokenAddress, feeRateE18, counter, seed, }) => {
|
|
135
|
+
const { settings } = address;
|
|
136
|
+
if (!(0, exchange_deposit_recipient_js_1.sameAddress)(settings.recipient, recipient))
|
|
137
|
+
return false;
|
|
138
|
+
if (!(0, exchange_deposit_recipient_js_1.sameAddress)(settings.tokenAddress, tokenAddress))
|
|
139
|
+
return false;
|
|
140
|
+
if (settings.feeRateE18 !== feeRateE18)
|
|
141
|
+
return false;
|
|
142
|
+
if (settings.counter !== counter)
|
|
143
|
+
return false;
|
|
144
|
+
const expectedIndex = (0, exchange_deposit_index_js_1.factoryIndexOf)({ seed, tokenAddress: settings.tokenAddress, feeRateE18, counter });
|
|
145
|
+
return settings.index === expectedIndex;
|
|
146
|
+
};
|
|
147
|
+
exports.exchangeDepositAddressMatchesSelection = exchangeDepositAddressMatchesSelection;
|
|
148
|
+
const exchangeDepositNeedsGasLimitWarning = ({ token, chainId, factories = exchange_deposit_factory_js_1.EXCHANGE_DEPOSIT_FACTORY_BY_CHAIN, }) => {
|
|
149
|
+
const factory = factories.get(chainId);
|
|
150
|
+
if (factory === undefined)
|
|
151
|
+
throw new Error(`no deposit factory is configured for chain ${chainId}`);
|
|
152
|
+
return (0, exchange_deposit_recipient_js_1.sameAddress)(token.address, viem_1.zeroAddress) && factory.glamsterdamActive;
|
|
153
|
+
};
|
|
154
|
+
exports.exchangeDepositNeedsGasLimitWarning = exchangeDepositNeedsGasLimitWarning;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cheapest way to send from each exchange, as a dated table. Every figure lives here and nowhere in a view. A
|
|
3
|
+
* figure is a fact of the exchange's own page on the day named in its `feeAsOf`, so a reader can check it.
|
|
4
|
+
*/
|
|
5
|
+
/** One exchange's sending guide. */
|
|
6
|
+
export type ExchangeSenderGuide = {
|
|
7
|
+
/** A stable key for the exchange. */
|
|
8
|
+
readonly id: 'kraken' | 'coinbase';
|
|
9
|
+
/** The exchange's proper name. */
|
|
10
|
+
readonly name: string;
|
|
11
|
+
/** The network to choose on the exchange's send screen. */
|
|
12
|
+
readonly network: 'Ethereum';
|
|
13
|
+
/** The withdrawal fee figures, one per asset. An empty list means the exchange shows its fee on the send screen. */
|
|
14
|
+
readonly feeFigures: readonly string[];
|
|
15
|
+
/** The date the fee figures were last updated, as `YYYY-MM-DD`, or null when there are no figures. */
|
|
16
|
+
readonly feeAsOf: string | null;
|
|
17
|
+
/** The exchange's documented minimum withdrawal, or null when none is recorded here. */
|
|
18
|
+
readonly minimumNote: string | null;
|
|
19
|
+
/** The page the figures come from, or null when the exchange shows its fee on the send screen. */
|
|
20
|
+
readonly sourceUrl: string | null;
|
|
21
|
+
};
|
|
22
|
+
/** The exchange senders the deposit page names, in the order it lists them. */
|
|
23
|
+
export declare const EXCHANGE_SENDER_GUIDES: readonly ExchangeSenderGuide[];
|
|
24
|
+
/**
|
|
25
|
+
* The guide of one exchange, or null when the table has none.
|
|
26
|
+
*
|
|
27
|
+
* @param id - the exchange's key
|
|
28
|
+
*/
|
|
29
|
+
export declare const exchangeSenderGuideOf: (id: ExchangeSenderGuide["id"]) => ExchangeSenderGuide | null;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exchangeSenderGuideOf = exports.EXCHANGE_SENDER_GUIDES = void 0;
|
|
4
|
+
exports.EXCHANGE_SENDER_GUIDES = [
|
|
5
|
+
{
|
|
6
|
+
id: 'kraken',
|
|
7
|
+
name: 'Kraken',
|
|
8
|
+
network: 'Ethereum',
|
|
9
|
+
feeFigures: ['0.45 USDC', '0.00014 ETH', '0.4446 USDT'],
|
|
10
|
+
feeAsOf: '2025-12-31',
|
|
11
|
+
minimumNote: '0.000168 ETH, 0.54 USDC, or 0.53352 USDT (the fee is included)',
|
|
12
|
+
sourceUrl: 'https://support.kraken.com/articles/360000767986-cryptocurrency-withdrawal-fees-and-minimums',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: 'coinbase',
|
|
16
|
+
name: 'Coinbase',
|
|
17
|
+
network: 'Ethereum',
|
|
18
|
+
feeFigures: [],
|
|
19
|
+
feeAsOf: null,
|
|
20
|
+
minimumNote: null,
|
|
21
|
+
sourceUrl: null,
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
const exchangeSenderGuideOf = (id) => exports.EXCHANGE_SENDER_GUIDES.find((guide) => guide.id === id) ?? null;
|
|
25
|
+
exports.exchangeSenderGuideOf = exchangeSenderGuideOf;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export { Cache } from './cache.js';
|
|
|
18
18
|
export { checkAllowance, type ApprovalParameters } from './chain-read.js';
|
|
19
19
|
export { clientFromChain, rpcBatchSetting } from './client.js';
|
|
20
20
|
export { add, configureEndpoints, ENDPOINTS_STORAGE_KEY, entries, get, getSnapshot, hasDefault, key, parse, productionSeed, remove, restoreDefault, setEndpoints, stringify, subscribe, testnetSeed, update, type EndpointEntry, type EndpointStorage, } from './endpoints.js';
|
|
21
|
+
export { FEE_RATE_SCALE, coverageOfAddress, crossingCoverage, ETHEREUM_MAINNET_CHAIN_ID, EXCHANGE_DEPOSIT_DEFAULT_FEE_RATE_E18, EXCHANGE_DEPOSIT_FEE_LIMITS_UNREADABLE, EXCHANGE_DEPOSIT_FEE_RATES, EXCHANGE_DEPOSIT_INITIAL_SELECTION, EXCHANGE_DEPOSIT_GAS_TABLE_NAME_BY_CHAIN, exchangeDepositGasTableOf, exchangeDepositSelectionReducer, assertFeeRatesWithinLimits, exchangeDepositStage, feeRateOptionsOf, feeRatePercent, SEPOLIA_CHAIN_ID, WEI_PER_ETHER, type CrossingCoverage, type CrossingCoverageInput, type ExchangeDepositAddress, type ExchangeDepositAddressOrigin, type ExchangeDepositContractGroup, type ExchangeDepositCrossing, type ExchangeDepositCrossingConditions, type ExchangeDepositRequest, type ExchangeDepositSelection, type ExchangeDepositSelectionAction, type ExchangeDepositSettings, type ExchangeDepositFeeLimits, type ExchangeDepositSource, type ExchangeDepositStage, type ExchangeDepositToken, } from './exchange-deposit.js';
|
|
22
|
+
export { readRecipient, recipientIdenticon, sameAddress, type RecipientIdenticon, type RecipientReading, } from './exchange-deposit-recipient.js';
|
|
21
23
|
export { chainLogoUrl, relayChainIconUrl } from './image.js';
|
|
22
24
|
export { evmChains, evmChainsById, isSupportedEvmChain } from './networks.js';
|
|
23
25
|
export { getBridgeTokenMetadata, getStoreKey, getStoreSize, getTokenAddressFromBridge, getTokenChainIdFromBridge, getTokenMetadata, loadTokenMetadata, parseChainScopedAddress, parseTokenKey, type ChainScopedAddress, } from './token-metadata.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.evmChainsById = exports.evmChains = exports.relayChainIconUrl = exports.chainLogoUrl = exports.sameAddress = exports.recipientIdenticon = exports.readRecipient = exports.WEI_PER_ETHER = exports.SEPOLIA_CHAIN_ID = exports.feeRatePercent = exports.feeRateOptionsOf = exports.exchangeDepositStage = exports.assertFeeRatesWithinLimits = exports.exchangeDepositSelectionReducer = exports.exchangeDepositGasTableOf = exports.EXCHANGE_DEPOSIT_GAS_TABLE_NAME_BY_CHAIN = exports.EXCHANGE_DEPOSIT_INITIAL_SELECTION = exports.EXCHANGE_DEPOSIT_FEE_RATES = exports.EXCHANGE_DEPOSIT_FEE_LIMITS_UNREADABLE = exports.EXCHANGE_DEPOSIT_DEFAULT_FEE_RATE_E18 = exports.ETHEREUM_MAINNET_CHAIN_ID = exports.crossingCoverage = exports.coverageOfAddress = exports.FEE_RATE_SCALE = exports.update = exports.testnetSeed = exports.subscribe = exports.stringify = exports.setEndpoints = exports.restoreDefault = exports.remove = exports.productionSeed = exports.parse = exports.key = exports.hasDefault = exports.getSnapshot = exports.get = exports.entries = exports.ENDPOINTS_STORAGE_KEY = exports.configureEndpoints = exports.add = exports.rpcBatchSetting = exports.clientFromChain = exports.checkAllowance = exports.Cache = exports.MINIMUM_BLOCK_POLL_MS = exports.MAXIMUM_BLOCK_POLL_MS = exports.blockTimeMsByChainId = exports.blockPollIntervalMs = exports.blockPollIntervalForChain = void 0;
|
|
4
|
+
exports.readUnlistedToken = exports.parseTokenKey = exports.parseChainScopedAddress = exports.loadTokenMetadata = exports.getTokenMetadata = exports.getTokenChainIdFromBridge = exports.getTokenAddressFromBridge = exports.getStoreSize = exports.getStoreKey = exports.getBridgeTokenMetadata = exports.isSupportedEvmChain = void 0;
|
|
4
5
|
var block_polling_js_1 = require("./block-polling.js");
|
|
5
6
|
Object.defineProperty(exports, "blockPollIntervalForChain", { enumerable: true, get: function () { return block_polling_js_1.blockPollIntervalForChain; } });
|
|
6
7
|
Object.defineProperty(exports, "blockPollIntervalMs", { enumerable: true, get: function () { return block_polling_js_1.blockPollIntervalMs; } });
|
|
@@ -32,6 +33,28 @@ Object.defineProperty(exports, "stringify", { enumerable: true, get: function ()
|
|
|
32
33
|
Object.defineProperty(exports, "subscribe", { enumerable: true, get: function () { return endpoints_js_1.subscribe; } });
|
|
33
34
|
Object.defineProperty(exports, "testnetSeed", { enumerable: true, get: function () { return endpoints_js_1.testnetSeed; } });
|
|
34
35
|
Object.defineProperty(exports, "update", { enumerable: true, get: function () { return endpoints_js_1.update; } });
|
|
36
|
+
var exchange_deposit_js_1 = require("./exchange-deposit.js");
|
|
37
|
+
Object.defineProperty(exports, "FEE_RATE_SCALE", { enumerable: true, get: function () { return exchange_deposit_js_1.FEE_RATE_SCALE; } });
|
|
38
|
+
Object.defineProperty(exports, "coverageOfAddress", { enumerable: true, get: function () { return exchange_deposit_js_1.coverageOfAddress; } });
|
|
39
|
+
Object.defineProperty(exports, "crossingCoverage", { enumerable: true, get: function () { return exchange_deposit_js_1.crossingCoverage; } });
|
|
40
|
+
Object.defineProperty(exports, "ETHEREUM_MAINNET_CHAIN_ID", { enumerable: true, get: function () { return exchange_deposit_js_1.ETHEREUM_MAINNET_CHAIN_ID; } });
|
|
41
|
+
Object.defineProperty(exports, "EXCHANGE_DEPOSIT_DEFAULT_FEE_RATE_E18", { enumerable: true, get: function () { return exchange_deposit_js_1.EXCHANGE_DEPOSIT_DEFAULT_FEE_RATE_E18; } });
|
|
42
|
+
Object.defineProperty(exports, "EXCHANGE_DEPOSIT_FEE_LIMITS_UNREADABLE", { enumerable: true, get: function () { return exchange_deposit_js_1.EXCHANGE_DEPOSIT_FEE_LIMITS_UNREADABLE; } });
|
|
43
|
+
Object.defineProperty(exports, "EXCHANGE_DEPOSIT_FEE_RATES", { enumerable: true, get: function () { return exchange_deposit_js_1.EXCHANGE_DEPOSIT_FEE_RATES; } });
|
|
44
|
+
Object.defineProperty(exports, "EXCHANGE_DEPOSIT_INITIAL_SELECTION", { enumerable: true, get: function () { return exchange_deposit_js_1.EXCHANGE_DEPOSIT_INITIAL_SELECTION; } });
|
|
45
|
+
Object.defineProperty(exports, "EXCHANGE_DEPOSIT_GAS_TABLE_NAME_BY_CHAIN", { enumerable: true, get: function () { return exchange_deposit_js_1.EXCHANGE_DEPOSIT_GAS_TABLE_NAME_BY_CHAIN; } });
|
|
46
|
+
Object.defineProperty(exports, "exchangeDepositGasTableOf", { enumerable: true, get: function () { return exchange_deposit_js_1.exchangeDepositGasTableOf; } });
|
|
47
|
+
Object.defineProperty(exports, "exchangeDepositSelectionReducer", { enumerable: true, get: function () { return exchange_deposit_js_1.exchangeDepositSelectionReducer; } });
|
|
48
|
+
Object.defineProperty(exports, "assertFeeRatesWithinLimits", { enumerable: true, get: function () { return exchange_deposit_js_1.assertFeeRatesWithinLimits; } });
|
|
49
|
+
Object.defineProperty(exports, "exchangeDepositStage", { enumerable: true, get: function () { return exchange_deposit_js_1.exchangeDepositStage; } });
|
|
50
|
+
Object.defineProperty(exports, "feeRateOptionsOf", { enumerable: true, get: function () { return exchange_deposit_js_1.feeRateOptionsOf; } });
|
|
51
|
+
Object.defineProperty(exports, "feeRatePercent", { enumerable: true, get: function () { return exchange_deposit_js_1.feeRatePercent; } });
|
|
52
|
+
Object.defineProperty(exports, "SEPOLIA_CHAIN_ID", { enumerable: true, get: function () { return exchange_deposit_js_1.SEPOLIA_CHAIN_ID; } });
|
|
53
|
+
Object.defineProperty(exports, "WEI_PER_ETHER", { enumerable: true, get: function () { return exchange_deposit_js_1.WEI_PER_ETHER; } });
|
|
54
|
+
var exchange_deposit_recipient_js_1 = require("./exchange-deposit-recipient.js");
|
|
55
|
+
Object.defineProperty(exports, "readRecipient", { enumerable: true, get: function () { return exchange_deposit_recipient_js_1.readRecipient; } });
|
|
56
|
+
Object.defineProperty(exports, "recipientIdenticon", { enumerable: true, get: function () { return exchange_deposit_recipient_js_1.recipientIdenticon; } });
|
|
57
|
+
Object.defineProperty(exports, "sameAddress", { enumerable: true, get: function () { return exchange_deposit_recipient_js_1.sameAddress; } });
|
|
35
58
|
var image_js_1 = require("./image.js");
|
|
36
59
|
Object.defineProperty(exports, "chainLogoUrl", { enumerable: true, get: function () { return image_js_1.chainLogoUrl; } });
|
|
37
60
|
Object.defineProperty(exports, "relayChainIconUrl", { enumerable: true, get: function () { return image_js_1.relayChainIconUrl; } });
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Kraken deposit minimums this interface routes against. Kraken publishes no public, keyless list of the networks
|
|
3
|
+
* it credits (its account API needs a key), so this table is copied by hand from Kraken's deposit page. Every row is
|
|
4
|
+
* on that page. A route to an asset not on the page is refused.
|
|
5
|
+
*
|
|
6
|
+
* Source: https://support.kraken.com/articles/360000292886-cryptocurrency-deposit-fees-and-minimums
|
|
7
|
+
* Dated: the page reads "Last updated: September 3, 2026".
|
|
8
|
+
*/
|
|
9
|
+
export declare const KRAKEN_DEPOSIT_SOURCE_URL = "https://support.kraken.com/articles/360000292886-cryptocurrency-deposit-fees-and-minimums";
|
|
10
|
+
/** The "Last updated" date the source page prints. The table is only as current as this date. */
|
|
11
|
+
export declare const KRAKEN_DEPOSIT_SOURCE_DATE = "September 3, 2026";
|
|
12
|
+
/**
|
|
13
|
+
* One asset Kraken credits on one EVM chain, and the deposit minimum below which Kraken says the funds are permanently
|
|
14
|
+
* lost. `tokenAddress` is `null` for the chain's native coin. `minimumAmount` is a whole-token decimal string, the way
|
|
15
|
+
* Kraken prints it.
|
|
16
|
+
*/
|
|
17
|
+
export interface KrakenDepositRule {
|
|
18
|
+
readonly chainId: number;
|
|
19
|
+
readonly tokenAddress: string | null;
|
|
20
|
+
readonly symbol: string;
|
|
21
|
+
readonly minimumAmount: string;
|
|
22
|
+
}
|
|
23
|
+
/** The Kraken deposit rules from the source page above: Ethereum mainnet and Base only. */
|
|
24
|
+
export declare const KRAKEN_DEPOSIT_RULES: readonly KrakenDepositRule[];
|
|
25
|
+
/**
|
|
26
|
+
* Finds the Kraken rule for one asset on one chain. Matching is by chain and contract address, compared in lower case,
|
|
27
|
+
* never by symbol. A `null` address means the chain's native coin.
|
|
28
|
+
*
|
|
29
|
+
* @param target - The chain and token address (`null` for native).
|
|
30
|
+
* @returns The rule, or `null` when Kraken does not credit that asset on that chain.
|
|
31
|
+
*/
|
|
32
|
+
export declare const krakenDepositRuleFor: (target: {
|
|
33
|
+
readonly chainId: number;
|
|
34
|
+
readonly tokenAddress: string | null;
|
|
35
|
+
}) => KrakenDepositRule | null;
|
|
36
|
+
/**
|
|
37
|
+
* Says whether Kraken credits a route's final asset on the route's final chain.
|
|
38
|
+
*
|
|
39
|
+
* @param target - The chain and token address (`null` for native).
|
|
40
|
+
* @returns `true` only when the source page lists that asset on that chain.
|
|
41
|
+
*/
|
|
42
|
+
export declare const isKrakenAcceptedDestination: (target: {
|
|
43
|
+
readonly chainId: number;
|
|
44
|
+
readonly tokenAddress: string | null;
|
|
45
|
+
}) => boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The deposit minimum Kraken prints for an asset, as a whole-token decimal string, or `null` when Kraken does not
|
|
48
|
+
* credit that asset. A deposit below the minimum is lost, so the minimum is a refusal, not a warning.
|
|
49
|
+
*
|
|
50
|
+
* @param target - The chain and token address (`null` for native).
|
|
51
|
+
* @returns The minimum, such as `"2.5"`, or `null` when the asset is not on the table.
|
|
52
|
+
*/
|
|
53
|
+
export declare const krakenDepositMinimumFor: (target: {
|
|
54
|
+
readonly chainId: number;
|
|
55
|
+
readonly tokenAddress: string | null;
|
|
56
|
+
}) => string | null;
|
|
57
|
+
/**
|
|
58
|
+
* Says whether a delivered amount is strictly below an exchange's minimum. Both sides are compared in base units, so no
|
|
59
|
+
* floating point number is involved. viem rounds a minimum that has more decimal places than the token has.
|
|
60
|
+
*
|
|
61
|
+
* @param options.deliveredBaseUnits - The delivered amount in the token's base units.
|
|
62
|
+
* @param options.decimals - How many places the token divides into.
|
|
63
|
+
* @param options.minimumAmount - The minimum as a whole-token decimal string.
|
|
64
|
+
* @returns `true` only when the delivered amount is below the minimum. An amount exactly at the minimum passes.
|
|
65
|
+
*/
|
|
66
|
+
export declare const isBelowDepositMinimum: ({ deliveredBaseUnits, decimals, minimumAmount, }: {
|
|
67
|
+
readonly deliveredBaseUnits: bigint;
|
|
68
|
+
readonly decimals: number;
|
|
69
|
+
readonly minimumAmount: string;
|
|
70
|
+
}) => boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isBelowDepositMinimum = exports.krakenDepositMinimumFor = exports.isKrakenAcceptedDestination = exports.krakenDepositRuleFor = exports.KRAKEN_DEPOSIT_RULES = exports.KRAKEN_DEPOSIT_SOURCE_DATE = exports.KRAKEN_DEPOSIT_SOURCE_URL = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
exports.KRAKEN_DEPOSIT_SOURCE_URL = 'https://support.kraken.com/articles/360000292886-cryptocurrency-deposit-fees-and-minimums';
|
|
6
|
+
exports.KRAKEN_DEPOSIT_SOURCE_DATE = 'September 3, 2026';
|
|
7
|
+
exports.KRAKEN_DEPOSIT_RULES = [
|
|
8
|
+
{ chainId: 1, tokenAddress: null, symbol: 'ETH', minimumAmount: '0.004' },
|
|
9
|
+
{ chainId: 1, tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', symbol: 'USDC', minimumAmount: '2.5' },
|
|
10
|
+
{ chainId: 1, tokenAddress: '0xdAC17F958D2ee523a2206206994597C13D831ec7', symbol: 'USDT', minimumAmount: '2.5' },
|
|
11
|
+
{ chainId: 8453, tokenAddress: null, symbol: 'ETH', minimumAmount: '0.0025' },
|
|
12
|
+
{ chainId: 8453, tokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', symbol: 'USDC', minimumAmount: '2.5' },
|
|
13
|
+
];
|
|
14
|
+
const krakenDepositRuleFor = (target) => {
|
|
15
|
+
const lowerAddress = target.tokenAddress?.toLowerCase() ?? null;
|
|
16
|
+
return (exports.KRAKEN_DEPOSIT_RULES.find((rule) => rule.chainId === target.chainId && (rule.tokenAddress?.toLowerCase() ?? null) === lowerAddress) ?? null);
|
|
17
|
+
};
|
|
18
|
+
exports.krakenDepositRuleFor = krakenDepositRuleFor;
|
|
19
|
+
const isKrakenAcceptedDestination = (target) => (0, exports.krakenDepositRuleFor)(target) !== null;
|
|
20
|
+
exports.isKrakenAcceptedDestination = isKrakenAcceptedDestination;
|
|
21
|
+
const krakenDepositMinimumFor = (target) => (0, exports.krakenDepositRuleFor)(target)?.minimumAmount ?? null;
|
|
22
|
+
exports.krakenDepositMinimumFor = krakenDepositMinimumFor;
|
|
23
|
+
const isBelowDepositMinimum = ({ deliveredBaseUnits, decimals, minimumAmount, }) => deliveredBaseUnits < (0, viem_1.parseUnits)(minimumAmount, decimals);
|
|
24
|
+
exports.isBelowDepositMinimum = isBelowDepositMinimum;
|
package/dist/client.d.ts
CHANGED
|
@@ -14,6 +14,14 @@ import type { HttpTransportConfig, PublicClient } from 'viem';
|
|
|
14
14
|
* @returns `false` when batching must be disabled, otherwise the batch config
|
|
15
15
|
*/
|
|
16
16
|
export declare const rpcBatchSetting: (chainId: number) => HttpTransportConfig["batch"];
|
|
17
|
+
/** The options of {@link clientFromChain}. */
|
|
18
|
+
export interface ClientFromChainOptions {
|
|
19
|
+
/**
|
|
20
|
+
* The longest one endpoint may take to answer a request before the next endpoint is asked. A reader that must not
|
|
21
|
+
* wait on a dead endpoint sets it. The client is then cached apart from the shared one.
|
|
22
|
+
*/
|
|
23
|
+
readonly attemptTimeoutMs?: number;
|
|
24
|
+
}
|
|
17
25
|
/**
|
|
18
26
|
* Returns a viem {@link PublicClient} for a chain, reusing the cached instance
|
|
19
27
|
* while the chain's endpoint list is unchanged. The cache key is derived from the
|
|
@@ -30,4 +38,4 @@ export declare const rpcBatchSetting: (chainId: number) => HttpTransportConfig["
|
|
|
30
38
|
* @param chainId - the chain to build a client for
|
|
31
39
|
* @returns the cached or freshly built public client
|
|
32
40
|
*/
|
|
33
|
-
export declare const clientFromChain: (chainId: number) => PublicClient;
|
|
41
|
+
export declare const clientFromChain: (chainId: number, options?: ClientFromChainOptions) => PublicClient;
|
package/dist/client.js
CHANGED
|
@@ -22,18 +22,21 @@ const defaultUrlsFor = (chainId) => {
|
|
|
22
22
|
const { http } = chain.rpcUrls.default;
|
|
23
23
|
return [...(http ?? [])];
|
|
24
24
|
};
|
|
25
|
-
export const clientFromChain = (chainId) => {
|
|
25
|
+
export const clientFromChain = (chainId, options = {}) => {
|
|
26
26
|
const stored = endpoints.get(chainId);
|
|
27
27
|
const urls = (stored?.length ? stored : defaultUrlsFor(chainId)).filter((url) => Boolean(url));
|
|
28
28
|
const key = chainKey(chainId, urls);
|
|
29
|
-
const existing = clientCache.get(chainId);
|
|
30
|
-
if (existing && existing.key === key) {
|
|
31
|
-
return existing.client;
|
|
32
|
-
}
|
|
33
29
|
const chain = evmChainsById.get(chainId);
|
|
34
30
|
if (!chain) {
|
|
35
31
|
throw new Error(`Chain ${chainId} is not one of the supported networks.`);
|
|
36
32
|
}
|
|
33
|
+
if (options.attemptTimeoutMs !== undefined) {
|
|
34
|
+
return buildClient({ chain, urls, batch: rpcBatchSetting(chainId), attemptTimeoutMs: options.attemptTimeoutMs });
|
|
35
|
+
}
|
|
36
|
+
const existing = clientCache.get(chainId);
|
|
37
|
+
if (existing && existing.key === key) {
|
|
38
|
+
return existing.client;
|
|
39
|
+
}
|
|
37
40
|
const client = buildClient({ chain, urls, batch: rpcBatchSetting(chainId) });
|
|
38
41
|
clientCache.set(chainId, { key, client });
|
|
39
42
|
return client;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The public currency list of Coinbase's institutional exchange (not the retail Coinbase app). It needs no key and
|
|
3
|
+
* allows any origin. The list says which assets the exchange credits on which networks.
|
|
4
|
+
*/
|
|
5
|
+
export declare const COINBASE_EXCHANGE_CURRENCIES_URL = "https://api.exchange.coinbase.com/currencies";
|
|
6
|
+
/** How long a fetched accept list stays fresh, in milliseconds. */
|
|
7
|
+
export declare const COINBASE_ACCEPT_LIST_TIME_TO_LIVE_MILLISECONDS: number;
|
|
8
|
+
/**
|
|
9
|
+
* One Coinbase exchange network id mapped to the EVM chain it names, and to the currency id that is that chain's
|
|
10
|
+
* gas asset. Only networks checked by hand belong here. Any other network is refused.
|
|
11
|
+
*/
|
|
12
|
+
export interface CoinbaseExchangeNetworkMapping {
|
|
13
|
+
readonly chainId: number;
|
|
14
|
+
readonly nativeCurrencyId: string | null;
|
|
15
|
+
}
|
|
16
|
+
/** The verified Coinbase exchange network ids. Chain 369 (PulseChain) is absent on purpose: the exchange does not list it. */
|
|
17
|
+
export declare const COINBASE_EXCHANGE_NETWORK_MAPPINGS: Readonly<Record<string, CoinbaseExchangeNetworkMapping>>;
|
|
18
|
+
/** One network entry inside a Coinbase exchange currency. Only the fields this module reads are typed. */
|
|
19
|
+
export interface CoinbaseExchangeNetwork {
|
|
20
|
+
readonly id: string;
|
|
21
|
+
readonly status: string;
|
|
22
|
+
readonly contract_address: string | null;
|
|
23
|
+
readonly is_evm_network: boolean;
|
|
24
|
+
readonly destination_tag_regex: string | null;
|
|
25
|
+
}
|
|
26
|
+
/** One currency from the Coinbase exchange currency list. */
|
|
27
|
+
export interface CoinbaseExchangeCurrency {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly status: string;
|
|
30
|
+
readonly supported_networks: readonly CoinbaseExchangeNetwork[];
|
|
31
|
+
}
|
|
32
|
+
/** An asset the exchange credits on one EVM chain. A native asset has no contract address. */
|
|
33
|
+
export type CoinbaseAcceptedAsset = {
|
|
34
|
+
readonly kind: 'native';
|
|
35
|
+
readonly chainId: number;
|
|
36
|
+
readonly currencyId: string;
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: 'token';
|
|
39
|
+
readonly chainId: number;
|
|
40
|
+
readonly currencyId: string;
|
|
41
|
+
/** The contract address in lower case. Matching is by this address, never by symbol. */
|
|
42
|
+
readonly address: string;
|
|
43
|
+
};
|
|
44
|
+
/** The accept list: every asset the exchange credits on a network this interface can route to. */
|
|
45
|
+
export interface CoinbaseAcceptList {
|
|
46
|
+
readonly assets: readonly CoinbaseAcceptedAsset[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Turns one network of one currency into an accepted asset, or `null` when the exchange does not credit it on a
|
|
50
|
+
* network we can route to. Every refusal is a guard clause, in this order: unknown network, non-EVM network, network
|
|
51
|
+
* or currency not online, destination tag required, and an empty address on a currency that is not the chain's gas
|
|
52
|
+
* asset (USDC on Base reports an empty address, but it is an ERC-20 and has no address this module can match).
|
|
53
|
+
*
|
|
54
|
+
* @param currency - One currency from the exchange list.
|
|
55
|
+
* @param network - One network entry of that currency.
|
|
56
|
+
* @returns The accepted asset, or `null` when refused.
|
|
57
|
+
*/
|
|
58
|
+
export declare const acceptedAssetFromExchangeNetwork: (currency: CoinbaseExchangeCurrency, network: CoinbaseExchangeNetwork) => CoinbaseAcceptedAsset | null;
|
|
59
|
+
/**
|
|
60
|
+
* Builds the accept list from a parsed exchange currency list.
|
|
61
|
+
*
|
|
62
|
+
* @param currencies - The currencies from the exchange list.
|
|
63
|
+
* @returns The accept list with every accepted asset.
|
|
64
|
+
*/
|
|
65
|
+
export declare const buildCoinbaseAcceptList: (currencies: readonly CoinbaseExchangeCurrency[]) => CoinbaseAcceptList;
|
|
66
|
+
/**
|
|
67
|
+
* Says whether the exchange credits a route's final asset. The asset is named by chain and contract address, never by
|
|
68
|
+
* symbol. A `null` address means the chain's native asset.
|
|
69
|
+
*
|
|
70
|
+
* @param acceptList - The accept list.
|
|
71
|
+
* @param target - The route's final chain and token address (`null` for native).
|
|
72
|
+
* @returns `true` when the exchange credits exactly that asset on that chain.
|
|
73
|
+
*/
|
|
74
|
+
export declare const isCoinbaseAcceptedDestination: (acceptList: CoinbaseAcceptList, target: {
|
|
75
|
+
readonly chainId: number;
|
|
76
|
+
readonly tokenAddress: string | null;
|
|
77
|
+
}) => boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Reads the exchange response body. It must be an array; anything else throws.
|
|
80
|
+
*
|
|
81
|
+
* @param body - The parsed JSON body.
|
|
82
|
+
* @returns The currency list.
|
|
83
|
+
*/
|
|
84
|
+
export declare const parseCoinbaseExchangeCurrencies: (body: unknown) => readonly CoinbaseExchangeCurrency[];
|
|
85
|
+
/** Options for {@link createCoinbaseAcceptListLoader}. */
|
|
86
|
+
export interface CoinbaseAcceptListLoaderOptions {
|
|
87
|
+
/** The fetch to use. Defaults to the global `fetch`. */
|
|
88
|
+
readonly fetchImplementation?: typeof fetch;
|
|
89
|
+
/** How long a loaded list stays fresh. Defaults to {@link COINBASE_ACCEPT_LIST_TIME_TO_LIVE_MILLISECONDS}. */
|
|
90
|
+
readonly timeToLiveMilliseconds?: number;
|
|
91
|
+
/** The clock. Defaults to `Date.now`. */
|
|
92
|
+
readonly now?: () => number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Makes a loader that fetches the accept list once, then reuses it until it goes stale. Concurrent calls share one
|
|
96
|
+
* request. A failed request is not cached, so the next call retries.
|
|
97
|
+
*
|
|
98
|
+
* @param options - The fetch, the time to live, and the clock.
|
|
99
|
+
* @returns A function that resolves the accept list.
|
|
100
|
+
*/
|
|
101
|
+
export declare const createCoinbaseAcceptListLoader: (options?: CoinbaseAcceptListLoaderOptions) => () => Promise<CoinbaseAcceptList>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { isAddress } from 'viem';
|
|
2
|
+
export const COINBASE_EXCHANGE_CURRENCIES_URL = 'https://api.exchange.coinbase.com/currencies';
|
|
3
|
+
export const COINBASE_ACCEPT_LIST_TIME_TO_LIVE_MILLISECONDS = 10 * 60 * 1000;
|
|
4
|
+
export const COINBASE_EXCHANGE_NETWORK_MAPPINGS = {
|
|
5
|
+
ethereum: { chainId: 1, nativeCurrencyId: 'ETH' },
|
|
6
|
+
optimism: { chainId: 10, nativeCurrencyId: 'ETH' },
|
|
7
|
+
bsc: { chainId: 56, nativeCurrencyId: 'BNB' },
|
|
8
|
+
polygon: { chainId: 137, nativeCurrencyId: null },
|
|
9
|
+
base: { chainId: 8453, nativeCurrencyId: 'ETH' },
|
|
10
|
+
arbitrum: { chainId: 42161, nativeCurrencyId: 'ETH' },
|
|
11
|
+
};
|
|
12
|
+
export const acceptedAssetFromExchangeNetwork = (currency, network) => {
|
|
13
|
+
const mapping = COINBASE_EXCHANGE_NETWORK_MAPPINGS[network.id];
|
|
14
|
+
if (mapping === undefined)
|
|
15
|
+
return null;
|
|
16
|
+
if (!network.is_evm_network)
|
|
17
|
+
return null;
|
|
18
|
+
if (network.status !== 'online' || currency.status !== 'online')
|
|
19
|
+
return null;
|
|
20
|
+
if (network.destination_tag_regex)
|
|
21
|
+
return null;
|
|
22
|
+
const rawAddress = (network.contract_address ?? '').trim();
|
|
23
|
+
const isGasCurrency = mapping.nativeCurrencyId === currency.id;
|
|
24
|
+
if (rawAddress === '') {
|
|
25
|
+
if (!isGasCurrency)
|
|
26
|
+
return null;
|
|
27
|
+
return { kind: 'native', chainId: mapping.chainId, currencyId: currency.id };
|
|
28
|
+
}
|
|
29
|
+
if (!isAddress(rawAddress, { strict: false }))
|
|
30
|
+
return null;
|
|
31
|
+
return {
|
|
32
|
+
kind: 'token',
|
|
33
|
+
chainId: mapping.chainId,
|
|
34
|
+
currencyId: currency.id,
|
|
35
|
+
address: rawAddress.toLowerCase(),
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export const buildCoinbaseAcceptList = (currencies) => ({
|
|
39
|
+
assets: currencies.flatMap((currency) => currency.supported_networks.flatMap((network) => {
|
|
40
|
+
const asset = acceptedAssetFromExchangeNetwork(currency, network);
|
|
41
|
+
return asset === null ? [] : [asset];
|
|
42
|
+
})),
|
|
43
|
+
});
|
|
44
|
+
export const isCoinbaseAcceptedDestination = (acceptList, target) => {
|
|
45
|
+
const lowerAddress = target.tokenAddress?.toLowerCase() ?? null;
|
|
46
|
+
return acceptList.assets.some((asset) => {
|
|
47
|
+
if (asset.chainId !== target.chainId)
|
|
48
|
+
return false;
|
|
49
|
+
if (lowerAddress === null)
|
|
50
|
+
return asset.kind === 'native';
|
|
51
|
+
return asset.kind === 'token' && asset.address === lowerAddress;
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
export const parseCoinbaseExchangeCurrencies = (body) => {
|
|
55
|
+
if (!Array.isArray(body))
|
|
56
|
+
throw new Error('Coinbase exchange currency list is not an array');
|
|
57
|
+
return body;
|
|
58
|
+
};
|
|
59
|
+
export const createCoinbaseAcceptListLoader = (options = {}) => {
|
|
60
|
+
const fetchImplementation = options.fetchImplementation ?? fetch;
|
|
61
|
+
const timeToLiveMilliseconds = options.timeToLiveMilliseconds ?? COINBASE_ACCEPT_LIST_TIME_TO_LIVE_MILLISECONDS;
|
|
62
|
+
const now = options.now ?? Date.now;
|
|
63
|
+
let cached = null;
|
|
64
|
+
let inFlight = null;
|
|
65
|
+
const fetchAcceptList = async () => {
|
|
66
|
+
const response = await fetchImplementation(COINBASE_EXCHANGE_CURRENCIES_URL, {
|
|
67
|
+
headers: { accept: 'application/json' },
|
|
68
|
+
});
|
|
69
|
+
if (!response.ok)
|
|
70
|
+
throw new Error(`Coinbase exchange currency list returned ${response.status}`);
|
|
71
|
+
const currencies = parseCoinbaseExchangeCurrencies(await response.json());
|
|
72
|
+
return buildCoinbaseAcceptList(currencies);
|
|
73
|
+
};
|
|
74
|
+
return async () => {
|
|
75
|
+
if (cached !== null && now() - cached.loadedAt < timeToLiveMilliseconds)
|
|
76
|
+
return cached.acceptList;
|
|
77
|
+
if (inFlight !== null)
|
|
78
|
+
return inFlight;
|
|
79
|
+
inFlight = fetchAcceptList().then((acceptList) => {
|
|
80
|
+
cached = { loadedAt: now(), acceptList };
|
|
81
|
+
inFlight = null;
|
|
82
|
+
return acceptList;
|
|
83
|
+
}, (error) => {
|
|
84
|
+
inFlight = null;
|
|
85
|
+
throw error;
|
|
86
|
+
});
|
|
87
|
+
return inFlight;
|
|
88
|
+
};
|
|
89
|
+
};
|