-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunction.ts
More file actions
48 lines (39 loc) · 1.64 KB
/
Copy pathfunction.ts
File metadata and controls
48 lines (39 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {
Address,
BigInt,
Bytes,
ERC20Token,
EvmCallBuilder,
IntentBuilder,
SwapBuilder,
TokenAmount,
TransferBuilder,
} from '@mimicprotocol/lib-ts'
import { inputs } from './types'
export default function main(): void {
// Token definitions
const chainId = inputs.chainId
const USDC = ERC20Token.fromString('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', chainId, 6, 'USDC')
const WBTC = ERC20Token.fromString('0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', chainId, 8, 'WBTC')
// Call without bytes (optional field)
const target = Address.fromString('0x0000000000000000000000000000000000000001')
const bytes = Bytes.fromI32(123)
const callFee = TokenAmount.fromI32(USDC, 10)
const evmcall = EvmCallBuilder.forChain(chainId).addCall(target).addCall(target, bytes)
evmcall.send(callFee)
// Normal swap
const minAmountOut = BigInt.fromI32(inputs.amount).times(BigInt.fromI32(inputs.slippage)).div(BigInt.fromI32(100))
const tokenIn = TokenAmount.fromI32(USDC, inputs.amount)
const tokenOut = TokenAmount.fromStringDecimal(WBTC, minAmountOut.toString())
const swap = SwapBuilder.forChains(chainId, chainId)
.addTokenInFromTokenAmount(tokenIn)
.addTokenOutFromTokenAmount(tokenOut, target)
swap.send()
// Normal Transfer
const tokenAmount = TokenAmount.fromI32(USDC, inputs.amount)
const transferFee = TokenAmount.fromI32(USDC, 10)
const transfer = TransferBuilder.forChain(chainId).addTransferFromTokenAmount(tokenAmount, target)
transfer.send(transferFee)
// Same operations grouped in a single intent
new IntentBuilder().addMaxFee(callFee).addOperationsBuilders([evmcall, swap, transfer]).send()
}