-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
107 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
import { UniswapSwapActionCallDataBuilder } from './uniswap-swap/uniswap-swap-action'; | ||
|
||
export { UniswapSwapActionCallDataBuilder }; | ||
export { UniswapSwapActionCallDataBuilder } from './uniswap-swap/uniswap-swap-action'; | ||
export { MultiSenderAction } from './multisender/multisender'; |
77 changes: 77 additions & 0 deletions
77
packages/core/src/lib/workflow/actions/multisender/multisender.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { ethers } from 'ethers5'; | ||
import BigNumber from 'bignumber.js'; | ||
import { AlphaRouter, AlphaRouterParams, SwapType } from '@uniswap/smart-order-router'; | ||
import { CurrencyAmount, Percent, Token as UniswapToken, TradeType } from '@uniswap/sdk-core'; | ||
import VaultABI from '../../../blockchain/abi/VaultABI.json'; | ||
import Erc20TokenABI from '../../../blockchain/abi/Erc20TokenABI.json'; | ||
import { TokenLight, tokens } from '../../../blockchain/tokens'; | ||
import { Chain } from '../../../blockchain/chains/types'; | ||
import { | ||
CallData, | ||
CallDataBuilder, | ||
CallDataBuilderReturnData, | ||
CommonBuilderOptions, | ||
} from '../../builders/types'; | ||
import { isNativeToken, isAddressesEqual } from '../../../blockchain/tokens/utils'; | ||
import { DittoContractInterface, Erc20Token } from '../../../contracts/types'; | ||
import { Address } from '../../../types'; | ||
|
||
export type MultiSenderItem = { | ||
asset: Erc20Token | null; | ||
amount: bigint; | ||
to: Address; | ||
}; | ||
|
||
type ActionConfig = { | ||
items: MultiSenderItem[]; | ||
}; | ||
|
||
export class MultiSenderAction implements CallDataBuilder { | ||
constructor( | ||
protected readonly config: ActionConfig, | ||
protected readonly commonCallDataBuilderConfig: CommonBuilderOptions | ||
) {} | ||
|
||
public async build(): Promise<CallDataBuilderReturnData> { | ||
const callData = new Set<CallData>(); | ||
|
||
const vaultInterface = this.commonCallDataBuilderConfig.provider | ||
.getContractFactory() | ||
.getContractInterface(JSON.stringify(VaultABI)); | ||
const erc20Interface = this.commonCallDataBuilderConfig.provider | ||
.getContractFactory() | ||
.getContractInterface(JSON.stringify(Erc20TokenABI)); | ||
|
||
const { chainId } = this.commonCallDataBuilderConfig; | ||
|
||
for (const item of this.config.items) { | ||
if (!item.to || !item.amount) continue; | ||
|
||
const asset = item.asset || tokens.native[chainId]; | ||
const amount = item.amount // new BigNumber(item.amount).shiftedBy(asset.decimals).toFixed(0) | ||
|
||
const isTokenNative = isNativeToken( | ||
asset.address, | ||
this.commonCallDataBuilderConfig.chainId | ||
); | ||
|
||
if (isTokenNative) { | ||
callData.add({ | ||
to: this.commonCallDataBuilderConfig.vaultAddress, | ||
callData: vaultInterface.encodeFunctionData('withdrawNative', [item.to, amount]), | ||
}); | ||
} else { | ||
callData.add({ | ||
to: this.commonCallDataBuilderConfig.vaultAddress, | ||
callData: vaultInterface.encodeFunctionData('withdrawERC20', [ | ||
asset.address, | ||
item.to, | ||
amount, | ||
]), | ||
}); | ||
} | ||
} | ||
|
||
return { callData, value: BigInt(0) }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
import { WorkflowsFactory } from './factory'; | ||
import { PriceTrigger, TimeBasedTrigger, TimeScale } from './triggers'; | ||
import type { Execution } from './execution'; | ||
|
||
export { WorkflowsFactory, PriceTrigger, TimeBasedTrigger, TimeScale }; | ||
export type { Execution as WorkflowExecution }; | ||
export * from './factory'; | ||
export * from './actions'; | ||
export * from './triggers'; | ||
export type { Execution as WorkflowExecution } from './execution'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { PriceTrigger } from './price-trigger'; | ||
import { TimeBasedTrigger } from './time-based-trigger'; | ||
import { TimeScale } from './types'; | ||
import { InstantTrigger } from './instant-trigger'; | ||
|
||
export { PriceTrigger, TimeBasedTrigger, TimeScale }; | ||
export { PriceTrigger, TimeBasedTrigger, TimeScale, InstantTrigger }; |