Skip to content

Commit

Permalink
chore: update prepareCalls request
Browse files Browse the repository at this point in the history
  • Loading branch information
o-az committed Jan 25, 2025
1 parent ee812d6 commit d3bf2f8
Show file tree
Hide file tree
Showing 2 changed files with 198 additions and 18 deletions.
184 changes: 184 additions & 0 deletions examples/offline/server/src/contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
export const ExperimentERC20 = {
abi: [
{ type: 'fallback', stateMutability: 'payable' },
{ type: 'receive', stateMutability: 'payable' },
{
type: 'function',
name: 'DOMAIN_SEPARATOR',
inputs: [],
outputs: [{ name: 'result', type: 'bytes32' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'allowance',
inputs: [
{ name: 'owner', type: 'address' },
{ name: 'spender', type: 'address' },
],
outputs: [{ name: 'result', type: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'approve',
inputs: [
{ name: 'spender', type: 'address' },
{ name: 'amount', type: 'uint256' },
],
outputs: [{ name: '', type: 'bool' }],
stateMutability: 'nonpayable',
},
{
type: 'function',
name: 'balanceOf',
inputs: [{ name: 'owner', type: 'address' }],
outputs: [{ name: 'result', type: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'burnForEther',
inputs: [{ name: 'amount', type: 'uint256' }],
outputs: [],
stateMutability: 'nonpayable',
},
{
type: 'function',
name: 'decimals',
inputs: [],
outputs: [{ name: '', type: 'uint8' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'mint',
inputs: [
{ name: 'to', type: 'address' },
{ name: 'value', type: 'uint256' },
],
outputs: [],
stateMutability: 'nonpayable',
},
{
type: 'function',
name: 'mintForEther',
inputs: [],
outputs: [],
stateMutability: 'payable',
},
{
type: 'function',
name: 'name',
inputs: [],
outputs: [{ name: '', type: 'string' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'nonces',
inputs: [{ name: 'owner', type: 'address' }],
outputs: [{ name: 'result', type: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'permit',
inputs: [
{ name: 'owner', type: 'address' },
{ name: 'spender', type: 'address' },
{ name: 'value', type: 'uint256' },
{ name: 'deadline', type: 'uint256' },
{ name: 'v', type: 'uint8' },
{ name: 'r', type: 'bytes32' },
{ name: 's', type: 'bytes32' },
],
outputs: [],
stateMutability: 'nonpayable',
},
{
type: 'function',
name: 'symbol',
inputs: [],
outputs: [{ name: '', type: 'string' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'totalSupply',
inputs: [],
outputs: [{ name: 'result', type: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'transfer',
inputs: [
{ name: 'to', type: 'address' },
{ name: 'amount', type: 'uint256' },
],
outputs: [{ name: '', type: 'bool' }],
stateMutability: 'nonpayable',
},
{
type: 'function',
name: 'transferFrom',
inputs: [
{ name: 'from', type: 'address' },
{ name: 'to', type: 'address' },
{ name: 'amount', type: 'uint256' },
],
outputs: [{ name: '', type: 'bool' }],
stateMutability: 'nonpayable',
},
{
type: 'event',
name: 'Approval',
inputs: [
{
name: 'owner',
type: 'address',
indexed: true,
},
{
name: 'spender',
type: 'address',
indexed: true,
},
{
name: 'amount',
type: 'uint256',
indexed: false,
},
],
anonymous: false,
},
{
type: 'event',
name: 'Transfer',
inputs: [
{
name: 'from',
type: 'address',
indexed: true,
},
{ name: 'to', type: 'address', indexed: true },
{
name: 'amount',
type: 'uint256',
indexed: false,
},
],
anonymous: false,
},
{ type: 'error', name: 'AllowanceOverflow', inputs: [] },
{ type: 'error', name: 'AllowanceUnderflow', inputs: [] },
{ type: 'error', name: 'InsufficientAllowance', inputs: [] },
{ type: 'error', name: 'InsufficientBalance', inputs: [] },
{ type: 'error', name: 'InvalidPermit', inputs: [] },
{ type: 'error', name: 'Permit2AllowanceIsFixedAtInfinity', inputs: [] },
{ type: 'error', name: 'PermitExpired', inputs: [] },
{ type: 'error', name: 'TotalSupplyOverflow', inputs: [] },
],
address: '0x238c8CD93ee9F8c7Edf395548eF60c0d2e46665E',
} as const
32 changes: 14 additions & 18 deletions src/core/internal/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import * as RpcResponse from 'ox/RpcResponse'

import type * as Chains from '../Chains.js'
import * as Porto from '../Porto.js'
import * as Call from './call.js'
import * as Account from './account.js'
import type * as Call from './call.js'
import * as Key from './key.js'
import type * as Schema from './rpcSchema.js'

Expand Down Expand Up @@ -506,34 +507,29 @@ export function from<
}

case 'experimental_prepareCalls': {
if (state.accounts.length === 0)
throw new ox_Provider.DisconnectedError()

const [parameters] = request.params

const { chainId, from } = parameters

const account = state.accounts.find((account) =>
Address.isEqual(account.address, from),
)
if (!account) throw new ox_Provider.UnauthorizedError()

const client = getClient(chainId)

const { signPayloads, request: _prepareExecuteRequest } =
if (chainId && Hex.toNumber(chainId) !== client.chain.id)
throw new ox_Provider.ChainDisconnectedError()

const calls = parameters.calls.map((x) => {
requireParameter(x, 'to')
return x
}) as Call.Call[]

const { signPayloads, request: prepareExecuteRequest } =
await implementation.actions.prepareExecute({
calls,
client,
account,
request,
calls: parameters.calls.map((x) => ({
...x,
to: x.to ?? Call.self,
value: x.value ? BigInt(x.value) : 0n,
})),
account: Account.from({ address: from }),
})

return {
context: request,
context: prepareExecuteRequest,
signPayload: signPayloads.at(0)!,
} satisfies RpcSchema.ExtractReturnType<
Schema.Schema,
Expand Down

0 comments on commit d3bf2f8

Please sign in to comment.