|
| 1 | +import * as RequestModel from './request-model.js' |
| 2 | +import { Effect } from 'effect' |
| 3 | +import { Abi } from 'viem' |
| 4 | +const AA_ABIS: Record<string, Abi> = { |
| 5 | + '0xabc5345e': [ |
| 6 | + { |
| 7 | + name: 'executeBySender', |
| 8 | + type: 'function', |
| 9 | + stateMutability: 'nonpayable', |
| 10 | + inputs: [ |
| 11 | + { |
| 12 | + name: 'calls', |
| 13 | + type: 'tuple[]', |
| 14 | + components: [ |
| 15 | + { name: 'target', type: 'address' }, |
| 16 | + { name: 'value', type: 'uint256' }, |
| 17 | + { name: 'data', type: 'bytes' }, |
| 18 | + ], |
| 19 | + }, |
| 20 | + ], |
| 21 | + outputs: [], |
| 22 | + }, |
| 23 | + ], |
| 24 | + '0x34fcd5be': [ |
| 25 | + { |
| 26 | + inputs: [ |
| 27 | + { |
| 28 | + components: [ |
| 29 | + { name: 'target', type: 'address' }, |
| 30 | + { name: 'value', type: 'uint256' }, |
| 31 | + { name: 'data', type: 'bytes' }, |
| 32 | + ], |
| 33 | + name: 'calls', |
| 34 | + type: 'tuple[]', |
| 35 | + }, |
| 36 | + ], |
| 37 | + name: 'executeBatch', |
| 38 | + outputs: [], |
| 39 | + stateMutability: 'payable', |
| 40 | + type: 'function', |
| 41 | + }, |
| 42 | + ], |
| 43 | + '0x9e5d4c49': [ |
| 44 | + { |
| 45 | + type: 'function', |
| 46 | + inputs: [ |
| 47 | + { name: 'to', internalType: 'address', type: 'address' }, |
| 48 | + { name: 'value', internalType: 'uint256', type: 'uint256' }, |
| 49 | + { name: 'data', internalType: 'bytes', type: 'bytes' }, |
| 50 | + ], |
| 51 | + name: 'executeCall', |
| 52 | + outputs: [ |
| 53 | + { name: 'success', internalType: 'bool', type: 'bool' }, |
| 54 | + { name: 'returnData', internalType: 'bytes', type: 'bytes' }, |
| 55 | + ], |
| 56 | + stateMutability: 'nonpayable', |
| 57 | + }, |
| 58 | + ], |
| 59 | + '0x912ccaa3': [ |
| 60 | + { |
| 61 | + inputs: [ |
| 62 | + { |
| 63 | + name: 'target', |
| 64 | + type: 'address[]', |
| 65 | + }, |
| 66 | + { |
| 67 | + name: 'value', |
| 68 | + type: 'uint256[]', |
| 69 | + }, |
| 70 | + { |
| 71 | + name: 'targetCallData', |
| 72 | + type: 'bytes[]', |
| 73 | + }, |
| 74 | + ], |
| 75 | + name: 'executeBatchCall', |
| 76 | + outputs: [], |
| 77 | + stateMutability: 'nonpayable', |
| 78 | + type: 'function', |
| 79 | + }, |
| 80 | + ], |
| 81 | + '0x18dfb3c7': [ |
| 82 | + { |
| 83 | + name: 'execute', |
| 84 | + type: 'function', |
| 85 | + inputs: [ |
| 86 | + { |
| 87 | + name: 'target', |
| 88 | + type: 'address[]', |
| 89 | + }, |
| 90 | + { |
| 91 | + name: 'callData', |
| 92 | + type: 'bytes[]', |
| 93 | + }, |
| 94 | + ], |
| 95 | + outputs: [], |
| 96 | + stateMutability: 'nonpayable', |
| 97 | + }, |
| 98 | + ], |
| 99 | + '0xb61d27f6': [ |
| 100 | + { |
| 101 | + name: 'execute', |
| 102 | + type: 'function', |
| 103 | + inputs: [ |
| 104 | + { |
| 105 | + name: 'target', |
| 106 | + type: 'address', |
| 107 | + }, |
| 108 | + { |
| 109 | + name: 'value', |
| 110 | + type: 'uint256', |
| 111 | + }, |
| 112 | + { |
| 113 | + name: 'data', |
| 114 | + type: 'bytes', |
| 115 | + }, |
| 116 | + ], |
| 117 | + outputs: [], |
| 118 | + stateMutability: 'nonpayable', |
| 119 | + }, |
| 120 | + ], |
| 121 | + '0x51945447': [ |
| 122 | + { |
| 123 | + type: 'function', |
| 124 | + inputs: [ |
| 125 | + { name: 'to', internalType: 'address', type: 'address' }, |
| 126 | + { name: 'value', internalType: 'uint256', type: 'uint256' }, |
| 127 | + { name: 'data', internalType: 'bytes', type: 'bytes' }, |
| 128 | + { name: 'operation', internalType: 'enum Operation', type: 'uint8' }, |
| 129 | + ], |
| 130 | + name: 'execute', |
| 131 | + outputs: [], |
| 132 | + stateMutability: 'payable', |
| 133 | + }, |
| 134 | + ], |
| 135 | + '0xf34308ef': [ |
| 136 | + { |
| 137 | + name: 'execTransactionFromEntrypoint', |
| 138 | + type: 'function', |
| 139 | + stateMutability: 'payable', |
| 140 | + inputs: [ |
| 141 | + { name: 'to', type: 'address' }, |
| 142 | + { name: 'value', type: 'uint256' }, |
| 143 | + { name: 'data', type: 'bytes' }, |
| 144 | + ], |
| 145 | + outputs: [], |
| 146 | + }, |
| 147 | + ], |
| 148 | + '0x541d63c8': [ |
| 149 | + { |
| 150 | + name: 'executeUserOpWithErrorString', |
| 151 | + type: 'function', |
| 152 | + stateMutability: 'nonpayable', |
| 153 | + inputs: [ |
| 154 | + { name: 'to', type: 'address' }, |
| 155 | + { name: 'value', type: 'uint256' }, |
| 156 | + { name: 'data', type: 'bytes' }, |
| 157 | + { name: 'operation', type: 'uint8' }, |
| 158 | + ], |
| 159 | + outputs: [], |
| 160 | + }, |
| 161 | + ], |
| 162 | +} |
| 163 | + |
| 164 | +const getLocalFragments = ({ address, chainId, signature }: RequestModel.GetContractABIStrategyParams) => |
| 165 | + Effect.gen(function* () { |
| 166 | + if (signature == null) { |
| 167 | + return yield* Effect.fail(new RequestModel.ResolveStrategyABIError('local-strategy', address, chainId)) |
| 168 | + } |
| 169 | + |
| 170 | + const abi = AA_ABIS[signature] |
| 171 | + |
| 172 | + if (abi == null) { |
| 173 | + return yield* Effect.fail(new RequestModel.ResolveStrategyABIError('local-strategy', address, chainId)) |
| 174 | + } |
| 175 | + |
| 176 | + return [ |
| 177 | + { |
| 178 | + type: 'address', |
| 179 | + address, |
| 180 | + chainID: chainId, |
| 181 | + abi: JSON.stringify(abi), |
| 182 | + }, |
| 183 | + ] as RequestModel.ContractABI[] |
| 184 | + }) |
| 185 | + |
| 186 | +export const AccountAbstractionStrategyResolver = (): RequestModel.ContractAbiResolverStrategy => { |
| 187 | + return { |
| 188 | + id: 'account-abstraction-strategy', |
| 189 | + type: 'address', |
| 190 | + resolver: (req: RequestModel.GetContractABIStrategyParams) => |
| 191 | + Effect.withSpan(getLocalFragments(req), 'AbiStrategy.AccountAbstractionStrategyResolver', { |
| 192 | + attributes: { chainId: req.chainId, address: req.address }, |
| 193 | + }), |
| 194 | + } |
| 195 | +} |
0 commit comments