Skip to content

Commit

Permalink
Merge pull request #105 from rhinestonewtf/feature/update-omni-account
Browse files Browse the repository at this point in the history
feat: update omni account modules to latest
  • Loading branch information
kopy-kat authored Dec 6, 2024
2 parents 126de52 + 027f1a3 commit c44f250
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 110 deletions.
214 changes: 162 additions & 52 deletions src/module/omni-account/abis/accountLockerSourceExecutorAbi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,60 +36,180 @@ export const accountLockerSourceExecutorAbi = [
},
{
type: 'function',
name: 'depositToAcross',
name: 'handleAcross',
inputs: [
{
name: 'account',
type: 'address',
internalType: 'address',
},
{
name: 'userSignature',
type: 'bytes',
internalType: 'bytes',
},
{
name: 'orchestratorSignature',
type: 'bytes',
internalType: 'bytes',
},
{
name: 'order',
name: 'payload',
type: 'tuple',
internalType: 'struct CrossChainOrder',
internalType: 'struct OriginModulePayload',
components: [
{
name: 'settlementContract',
type: 'address',
internalType: 'address',
},
{
name: 'swapper',
type: 'address',
internalType: 'address',
name: 'order',
type: 'tuple',
internalType: 'struct Order',
components: [
{
name: 'settlement',
type: 'tuple',
internalType: 'struct Settlement',
components: [
{
name: 'orchestrator',
type: 'address',
internalType: 'address',
},
{
name: 'recipient',
type: 'address',
internalType: 'address',
},
{
name: 'settlementContract',
type: 'address',
internalType: 'address',
},
{
name: 'targetAccount',
type: 'address',
internalType: 'address',
},
{
name: 'targetChainId',
type: 'uint64',
internalType: 'uint64',
},
{
name: 'fillDeadline',
type: 'uint32',
internalType: 'uint32',
},
{
name: 'lastDepositId',
type: 'uint256',
internalType: 'uint256',
},
],
},
{
name: 'acrossTransfer',
type: 'tuple',
internalType: 'struct AcrossTransfer',
components: [
{
name: 'originModule',
type: 'address',
internalType: 'address',
},
{
name: 'originAccount',
type: 'address',
internalType: 'address',
},
{
name: 'originChainId',
type: 'uint64',
internalType: 'uint64',
},
{
name: 'initiateDeadline',
type: 'uint32',
internalType: 'uint32',
},
{
name: 'maxFee',
type: 'uint256',
internalType: 'uint256',
},
{
name: 'depositId',
type: 'uint256',
internalType: 'uint256',
},
{
name: 'originTransfer',
type: 'tuple',
internalType: 'struct TokenTransfer',
components: [
{
name: 'tokenAddress',
type: 'address',
internalType: 'address',
},
{
name: 'amount',
type: 'uint256',
internalType: 'uint256',
},
],
},
{
name: 'targetTransfer',
type: 'tuple',
internalType: 'struct TokenTransfer',
components: [
{
name: 'tokenAddress',
type: 'address',
internalType: 'address',
},
{
name: 'amount',
type: 'uint256',
internalType: 'uint256',
},
],
},
],
},
{
name: 'smartDigests',
type: 'tuple',
internalType: 'struct SmartDigest',
components: [
{
name: 'acrossTransferDigests',
type: 'tuple',
internalType: 'struct IndexChainDigest',
components: [
{
name: 'digestIndex',
type: 'uint256',
internalType: 'uint256',
},
{
name: 'chainDataDigests',
type: 'bytes32[]',
internalType: 'bytes32[]',
},
],
},
{
name: 'executionDigest',
type: 'bytes32',
internalType: 'bytes32',
},
{
name: 'userOpDigest',
type: 'bytes32',
internalType: 'bytes32',
},
],
},
{ name: 'userSig', type: 'bytes', internalType: 'bytes' },
],
},
{
name: 'nonce',
name: 'auctionFee',
type: 'uint256',
internalType: 'uint256',
},
{
name: 'originChainId',
type: 'uint32',
internalType: 'uint32',
},
{
name: 'initiateDeadline',
type: 'uint32',
internalType: 'uint32',
},
{
name: 'fillDeadline',
type: 'uint32',
internalType: 'uint32',
name: 'orchestratorSig',
type: 'bytes',
internalType: 'bytes',
},
{
name: 'orderData',
name: 'acrossMessagePayload',
type: 'bytes',
internalType: 'bytes',
},
Expand Down Expand Up @@ -256,18 +376,8 @@ export const accountLockerSourceExecutorAbi = [
},
{
type: 'function',
name: 'unlockFunds',
name: 'unlockFundsForAccount',
inputs: [
{
name: 'account',
type: 'address',
internalType: 'address',
},
{
name: 'userSignature',
type: 'bytes',
internalType: 'bytes',
},
{
name: 'orchestratorSignature',
type: 'bytes',
Expand Down
30 changes: 5 additions & 25 deletions src/module/omni-account/installation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,10 @@ export const getAccountLockerHook = (
return {
module: ACCOUNT_LOCKER_HOOK,
address: ACCOUNT_LOCKER_HOOK,
initData: isOmniMode
? encodeAbiParameters(
[
{ name: 'hookType', type: 'uint256' },
{ name: 'hookId', type: 'bytes4' },
{ name: 'data', type: 'bytes' },
],
[
0n,
'0x00000000',
encodeAbiParameters([{ name: 'value', type: 'bool' }], [true]),
],
)
: '0x',
initData: encodeAbiParameters(
[{ name: 'enableOmniLock', type: 'bool' }],
[isOmniMode],
),
deInitData: '0x',
additionalContext: '0x',
hook,
Expand Down Expand Up @@ -63,17 +53,7 @@ export const getAccountLockerTargetExecutor = (
return {
module: ACCOUNT_LOCKER_TARGET_EXECUTOR,
address: ACCOUNT_LOCKER_TARGET_EXECUTOR,
initData:
moduleType === 'executor'
? '0x'
: encodeAbiParameters(
[
{ name: 'selector', type: 'bytes4' },
{ name: 'flags', type: 'bytes1' },
{ name: 'data', type: 'bytes' },
],
['0x3a5be8cb', '0x00', '0x'],
),
initData: '0x',
deInitData: '0x',
additionalContext: '0x',
hook,
Expand Down
51 changes: 51 additions & 0 deletions src/module/omni-account/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,54 @@ export type ApprovalSpend = {
token: Address
amount: bigint
}

export type OriginModulePayload = {
order: Order
auctionFee: bigint
orchestratorSig: Hex
acrossMessagePayload: Hex
}

export type Order = {
settlement: Settlement
acrossTransfer: AcrossTransfer
smartDigests: SmartDigest
userSig: Hex
}

export type Settlement = {
orchestrator: Address
recipient: Address
settlementContract: Address
targetAccount: Address
targetChainId: number
fillDeadline: number
lastDepositId: bigint
}

export type TokenTransfer = {
tokenAddress: Address
amount: bigint
}

export type AcrossTransfer = {
originModule: Address
originAccount: Address
originChainId: number
initiateDeadline: number
maxFee: bigint
depositId: bigint
originTransfer: TokenTransfer
targetTransfer: TokenTransfer
}

export type SmartDigest = {
acrossTransferDigests: IndexChainDigest
executionDigest: Hex
userOpDigest: Hex
}

export type IndexChainDigest = {
digestIndex: bigint
chainDataDigests: Hex[]
}
26 changes: 8 additions & 18 deletions src/module/omni-account/usage.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { Address, encodeFunctionData, Hex } from 'viem'
import { encodeFunctionData, Hex } from 'viem'
import { accountLockerSourceExecutorAbi } from './abis'
import { ACCOUNT_LOCKER_SOURCE_EXECUTOR } from './constants'
import { ApprovalSpend, CrossChainOrder, WithdrawRequest } from './types'
import { ApprovalSpend, OriginModulePayload, WithdrawRequest } from './types'
import { Execution } from '../../account'

export const getUnlockFundsAction = ({
account,
userSignature,
orchestratorSignature,
request,
}: {
account: Address
userSignature: Hex
orchestratorSignature: Hex
request: WithdrawRequest
}): Execution => {
const data = encodeFunctionData({
functionName: 'unlockFunds',
functionName: 'unlockFundsForAccount',
abi: accountLockerSourceExecutorAbi,
args: [account, userSignature, orchestratorSignature, request],
args: [orchestratorSignature, request],
})

return {
Expand All @@ -31,20 +27,14 @@ export const getUnlockFundsAction = ({
}

export const getDepositToAcrossAction = ({
account,
userSignature,
orchestratorSignature,
order,
originModulePayload,
}: {
account: Address
userSignature: Hex
orchestratorSignature: Hex
order: CrossChainOrder
originModulePayload: OriginModulePayload
}): Execution => {
const data = encodeFunctionData({
functionName: 'depositToAcross',
functionName: 'handleAcross',
abi: accountLockerSourceExecutorAbi,
args: [account, userSignature, orchestratorSignature, order],
args: [originModulePayload],
})
return {
to: ACCOUNT_LOCKER_SOURCE_EXECUTOR,
Expand Down
Loading

0 comments on commit c44f250

Please sign in to comment.