Files
orionprotocol-sdk/src/utils/getAvailableFundsSources.ts
Oleg Nechiporenko c2a4084158 feat: update ethers@6
fix: bigint errors

fix: TS errors

fix: gasLimit fetch

fix: review comments

fix: contracts errors

chore: bump rc version

fix: revert wrong fix

fix: ts config

fix: ts config

fix: ts config

feat: update signer
2023-09-28 11:43:27 +02:00

20 lines
846 B
TypeScript

import { ethers } from 'ethers';
import type { Source } from '../types.js';
export default function getAvailableFundsSources(
expenseType: 'amount' | 'network_fee' | 'service_fee',
assetAddress: string,
route: 'aggregator' | 'pool',
): Source[] {
switch (route) {
case 'aggregator':
if (assetAddress === ethers.ZeroAddress) return ['exchange']; // We can't take native crypto from wallet
return ['exchange', 'wallet']; // We can take any token amount from exchange + wallet. Order is important!
case 'pool':
if (expenseType === 'network_fee') return ['wallet']; // Network fee is always taken from wallet
return ['exchange', 'wallet']; // We can take any token amount from exchange + wallet (specify 'value' for 'pool'). Order is important!
default:
throw new Error('Unknown route item');
}
}