Commit 205ac4a8 authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge branch 'develop' into jg/properly_init_api_server_logger

parents 1b4c9d2a 922041eb
---
'@eth-optimism/atst': minor
---
Update readAttestations and prepareWriteAttestation to handle keys longer than 32 bytes
...@@ -76,6 +76,35 @@ describe(getEvents.name, () => { ...@@ -76,6 +76,35 @@ describe(getEvents.name, () => {
"transactionHash": "0x61f59bd4dfe54272d9369effe3ae57a0ef2584161fcf2bbd55f5596002e759bd", "transactionHash": "0x61f59bd4dfe54272d9369effe3ae57a0ef2584161fcf2bbd55f5596002e759bd",
"transactionIndex": 1, "transactionIndex": 1,
}, },
{
"address": "0xEE36eaaD94d1Cc1d0eccaDb55C38bFfB6Be06C77",
"args": [
"0xBCf86Fd70a0183433763ab0c14E7a760194f3a9F",
"0x00000000000000000000000000000000000060A7",
"0x616e696d616c6661726d2e7363686f6f6c2e617474656e646564000000000000",
"0x01",
],
"blockHash": "0x4870baaac6d7195952dc25e5dc0109ea324f819f8152d2889c7b4ad64040a9bf",
"blockNumber": 6278428,
"data": "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010100000000000000000000000000000000000000000000000000000000000000",
"decode": [Function],
"event": "AttestationCreated",
"eventSignature": "AttestationCreated(address,address,bytes32,bytes)",
"getBlock": [Function],
"getTransaction": [Function],
"getTransactionReceipt": [Function],
"logIndex": 0,
"removeListener": [Function],
"removed": false,
"topics": [
"0x28710dfecab43d1e29e02aa56b2e1e610c0bae19135c9cf7a83a1adb6df96d85",
"0x000000000000000000000000bcf86fd70a0183433763ab0c14e7a760194f3a9f",
"0x00000000000000000000000000000000000000000000000000000000000060a7",
"0x616e696d616c6661726d2e7363686f6f6c2e617474656e646564000000000000",
],
"transactionHash": "0x4e836b74c51a370375efa374297524d9b0f6eacdd699c30556680ae7dc9a14ea",
"transactionIndex": 1,
},
] ]
`) `)
}) })
......
...@@ -43,7 +43,7 @@ describe(prepareWriteAttestation.name, () => { ...@@ -43,7 +43,7 @@ describe(prepareWriteAttestation.name, () => {
expect(result.address).toMatchInlineSnapshot( expect(result.address).toMatchInlineSnapshot(
'"0xEE36eaaD94d1Cc1d0eccaDb55C38bFfB6Be06C77"' '"0xEE36eaaD94d1Cc1d0eccaDb55C38bFfB6Be06C77"'
) )
expect(result.chainId).toMatchInlineSnapshot('10') expect(result.chainId).toMatchInlineSnapshot('undefined')
expect(result.functionName).toMatchInlineSnapshot('"attest"') expect(result.functionName).toMatchInlineSnapshot('"attest"')
expect(result.mode).toMatchInlineSnapshot('"prepared"') expect(result.mode).toMatchInlineSnapshot('"prepared"')
expect(result.request.gasLimit).toMatchInlineSnapshot(` expect(result.request.gasLimit).toMatchInlineSnapshot(`
...@@ -54,18 +54,16 @@ describe(prepareWriteAttestation.name, () => { ...@@ -54,18 +54,16 @@ describe(prepareWriteAttestation.name, () => {
`) `)
}) })
it('should throw an error if key is longer than 32 bytes', async () => { it('should work for key longer than 32 bytes', async () => {
const dataType = 'string' const dataType = 'string'
await expect( expect(
readAttestation( await readAttestation(
creator, creator,
about, about,
'this is a key that is way longer than 32 bytes so this key should throw an error matching the inline snapshot', 'this is a key that is way longer than 32 bytes so this key should throw an error matching the inline snapshot',
dataType dataType
) )
).rejects.toThrowErrorMatchingInlineSnapshot( ).toMatchInlineSnapshot('""')
'"Key is longer than the max length of 32 for attestation keys"'
)
}) })
}) })
import { Address, prepareWriteContract } from '@wagmi/core' import { Address, prepareWriteContract } from '@wagmi/core'
import { formatBytes32String } from 'ethers/lib/utils.js'
import { ATTESTATION_STATION_ADDRESS } from '../constants/attestationStationAddress' import { ATTESTATION_STATION_ADDRESS } from '../constants/attestationStationAddress'
import { WagmiBytes } from '../types/WagmiBytes' import { WagmiBytes } from '../types/WagmiBytes'
import { abi } from './abi' import { abi } from './abi'
import { createKey } from './createKey'
import { createValue } from './createValue' import { createValue } from './createValue'
export const prepareWriteAttestation = async ( export const prepareWriteAttestation = async (
...@@ -13,15 +13,7 @@ export const prepareWriteAttestation = async ( ...@@ -13,15 +13,7 @@ export const prepareWriteAttestation = async (
chainId: number | undefined = undefined, chainId: number | undefined = undefined,
contractAddress: Address = ATTESTATION_STATION_ADDRESS contractAddress: Address = ATTESTATION_STATION_ADDRESS
) => { ) => {
let formattedKey: WagmiBytes const formattedKey = createKey(key) as WagmiBytes
try {
formattedKey = formatBytes32String(key) as WagmiBytes
} catch (e) {
console.error(e)
throw new Error(
`key is longer than 32 bytes: ${key}. Try using a shorter key or using 'encodeRawKey' to encode the key into 32 bytes first`
)
}
return prepareWriteContract({ return prepareWriteContract({
address: contractAddress, address: contractAddress,
abi, abi,
......
...@@ -49,7 +49,7 @@ describe(prepareWriteAttestations.name, () => { ...@@ -49,7 +49,7 @@ describe(prepareWriteAttestations.name, () => {
expect(result.address).toMatchInlineSnapshot( expect(result.address).toMatchInlineSnapshot(
'"0xEE36eaaD94d1Cc1d0eccaDb55C38bFfB6Be06C77"' '"0xEE36eaaD94d1Cc1d0eccaDb55C38bFfB6Be06C77"'
) )
expect(result.chainId).toMatchInlineSnapshot('10') expect(result.chainId).toMatchInlineSnapshot('undefined')
expect(result.functionName).toMatchInlineSnapshot('"attest"') expect(result.functionName).toMatchInlineSnapshot('"attest"')
expect(result.mode).toMatchInlineSnapshot('"prepared"') expect(result.mode).toMatchInlineSnapshot('"prepared"')
expect(result.request.gasLimit).toMatchInlineSnapshot(` expect(result.request.gasLimit).toMatchInlineSnapshot(`
...@@ -60,18 +60,16 @@ describe(prepareWriteAttestations.name, () => { ...@@ -60,18 +60,16 @@ describe(prepareWriteAttestations.name, () => {
`) `)
}) })
it('should throw an error if key is longer than 32 bytes', async () => { it('should work if key is longer than 32 bytes', async () => {
const dataType = 'string' const dataType = 'string'
await expect( expect(
readAttestation( await readAttestation(
creator, creator,
about, about,
'this is a key that is way longer than 32 bytes so this key should throw an error matching the inline snapshot', 'this is a key that is way longer than 32 bytes so this key should throw an error matching the inline snapshot',
dataType dataType
) )
).rejects.toThrowErrorMatchingInlineSnapshot( ).toMatchInlineSnapshot('""')
'"Key is longer than the max length of 32 for attestation keys"'
)
}) })
}) })
...@@ -26,16 +26,14 @@ describe(readAttestation.name, () => { ...@@ -26,16 +26,14 @@ describe(readAttestation.name, () => {
) )
}) })
it('should throw an error if key is longer than 32 bytes', async () => { it('should work if key is longer than 32 bytes', async () => {
await expect( expect(
readAttestation( await readAttestation(
creator, creator,
about, about,
'this is a key that is way longer than 32 bytes so this key should throw an error matching the inline snapshot', 'this is a key that is way longer than 32 bytes so this key should throw an error matching the inline snapshot',
dataType dataType
) )
).rejects.toThrowErrorMatchingInlineSnapshot( ).toMatchInlineSnapshot('""')
'"Key is longer than the max length of 32 for attestation keys"'
)
}) })
}) })
import { readContracts } from '@wagmi/core' import { readContracts } from '@wagmi/core'
import { formatBytes32String } from 'ethers/lib/utils.js'
import { ATTESTATION_STATION_ADDRESS } from '../constants/attestationStationAddress' import { ATTESTATION_STATION_ADDRESS } from '../constants/attestationStationAddress'
import type { AttestationReadParams } from '../types/AttestationReadParams' import type { AttestationReadParams } from '../types/AttestationReadParams'
import { DEFAULT_DATA_TYPE } from '../types/DataTypeOption' import { DEFAULT_DATA_TYPE } from '../types/DataTypeOption'
import type { WagmiBytes } from '../types/WagmiBytes' import type { WagmiBytes } from '../types/WagmiBytes'
import { abi } from './abi' import { abi } from './abi'
import { createKey } from './createKey'
import { parseAttestationBytes } from './parseAttestationBytes' import { parseAttestationBytes } from './parseAttestationBytes'
/** /**
...@@ -39,16 +39,11 @@ export const readAttestations = async ( ...@@ -39,16 +39,11 @@ export const readAttestations = async (
key, key,
contractAddress = ATTESTATION_STATION_ADDRESS, contractAddress = ATTESTATION_STATION_ADDRESS,
} = attestation } = attestation
if (key.length > 32) {
throw new Error(
'Key is longer than the max length of 32 for attestation keys'
)
}
return { return {
address: contractAddress, address: contractAddress,
abi, abi,
functionName: 'attestations', functionName: 'attestations',
args: [creator, about, formatBytes32String(key) as WagmiBytes], args: [creator, about, createKey(key) as WagmiBytes],
} as const } as const
}) })
......
# TeleportrDeposit
> TeleportrDeposit Shout out to 0xclem for providing the inspiration for this contract: https://github.com/0xclem/teleportr/blob/main/contracts/BridgeDeposit.sol
## Methods
### maxBalance
```solidity
function maxBalance() external view returns (uint256)
```
The maximum balance the contract can hold after a receive.
#### Returns
| Name | Type | Description |
|---|---|---|
| _0 | uint256 | undefined
### maxDepositAmount
```solidity
function maxDepositAmount() external view returns (uint256)
```
The maximum amount that be deposited in a receive.
#### Returns
| Name | Type | Description |
|---|---|---|
| _0 | uint256 | undefined
### minDepositAmount
```solidity
function minDepositAmount() external view returns (uint256)
```
The minimum amount that be deposited in a receive.
#### Returns
| Name | Type | Description |
|---|---|---|
| _0 | uint256 | undefined
### owner
```solidity
function owner() external view returns (address)
```
*Returns the address of the current owner.*
#### Returns
| Name | Type | Description |
|---|---|---|
| _0 | address | undefined
### renounceOwnership
```solidity
function renounceOwnership() external nonpayable
```
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.*
### setMaxAmount
```solidity
function setMaxAmount(uint256 _maxDepositAmount) external nonpayable
```
Sets the maximum amount that can be deposited in a receive.
#### Parameters
| Name | Type | Description |
|---|---|---|
| _maxDepositAmount | uint256 | The new maximum deposit amount.
### setMaxBalance
```solidity
function setMaxBalance(uint256 _maxBalance) external nonpayable
```
Sets the maximum balance the contract can hold after a receive.
#### Parameters
| Name | Type | Description |
|---|---|---|
| _maxBalance | uint256 | The new maximum contract balance.
### setMinAmount
```solidity
function setMinAmount(uint256 _minDepositAmount) external nonpayable
```
Sets the minimum amount that can be deposited in a receive.
#### Parameters
| Name | Type | Description |
|---|---|---|
| _minDepositAmount | uint256 | The new minimum deposit amount.
### totalDeposits
```solidity
function totalDeposits() external view returns (uint256)
```
The total number of successful deposits received.
#### Returns
| Name | Type | Description |
|---|---|---|
| _0 | uint256 | undefined
### transferOwnership
```solidity
function transferOwnership(address newOwner) external nonpayable
```
*Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner.*
#### Parameters
| Name | Type | Description |
|---|---|---|
| newOwner | address | undefined
### withdrawBalance
```solidity
function withdrawBalance() external nonpayable
```
Sends the contract's current balance to the owner.
## Events
### BalanceWithdrawn
```solidity
event BalanceWithdrawn(address indexed owner, uint256 balance)
```
Emitted any time the balance is withdrawn by the owner.
#### Parameters
| Name | Type | Description |
|---|---|---|
| owner `indexed` | address | The current owner and recipient of the funds. |
| balance | uint256 | The current contract balance paid to the owner. |
### EtherReceived
```solidity
event EtherReceived(uint256 indexed depositId, address indexed emitter, uint256 indexed amount)
```
Emitted any time a successful deposit is received.
#### Parameters
| Name | Type | Description |
|---|---|---|
| depositId `indexed` | uint256 | A unique sequencer number identifying the deposit. |
| emitter `indexed` | address | The sending address of the payer. |
| amount `indexed` | uint256 | The amount deposited by the payer. |
### MaxBalanceSet
```solidity
event MaxBalanceSet(uint256 previousBalance, uint256 newBalance)
```
Emitted any time the contract maximum balance is set.
#### Parameters
| Name | Type | Description |
|---|---|---|
| previousBalance | uint256 | The previous maximum contract balance. |
| newBalance | uint256 | The new maximum contract balance. |
### MaxDepositAmountSet
```solidity
event MaxDepositAmountSet(uint256 previousAmount, uint256 newAmount)
```
Emitted any time the maximum deposit amount is set.
#### Parameters
| Name | Type | Description |
|---|---|---|
| previousAmount | uint256 | The previous maximum deposit amount. |
| newAmount | uint256 | The new maximum deposit amount. |
### MinDepositAmountSet
```solidity
event MinDepositAmountSet(uint256 previousAmount, uint256 newAmount)
```
Emitted any time the minimum deposit amount is set.
#### Parameters
| Name | Type | Description |
|---|---|---|
| previousAmount | uint256 | The previous minimum deposit amount. |
| newAmount | uint256 | The new minimum deposit amount. |
### OwnershipTransferred
```solidity
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)
```
#### Parameters
| Name | Type | Description |
|---|---|---|
| previousOwner `indexed` | address | undefined |
| newOwner `indexed` | address | undefined |
# TeleportrDisburser
> TeleportrDisburser
## Methods
### disburse
```solidity
function disburse(uint256 _nextDepositId, TeleportrDisburser.Disbursement[] _disbursements) external payable
```
Accepts a list of Disbursements and forwards the amount paid to the contract to each recipient. The method reverts if there are zero disbursements, the total amount to forward differs from the amount sent in the transaction, or the _nextDepositId is unexpected. Failed disbursements will not cause the method to revert, but will instead be held by the contract and available for the owner to withdraw.
#### Parameters
| Name | Type | Description |
|---|---|---|
| _nextDepositId | uint256 | The depositId of the first Dispursement.
| _disbursements | TeleportrDisburser.Disbursement[] | A list of Disbursements to process.
### owner
```solidity
function owner() external view returns (address)
```
*Returns the address of the current owner.*
#### Returns
| Name | Type | Description |
|---|---|---|
| _0 | address | undefined
### renounceOwnership
```solidity
function renounceOwnership() external nonpayable
```
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.*
### totalDisbursements
```solidity
function totalDisbursements() external view returns (uint256)
```
The total number of disbursements processed.
#### Returns
| Name | Type | Description |
|---|---|---|
| _0 | uint256 | undefined
### transferOwnership
```solidity
function transferOwnership(address newOwner) external nonpayable
```
*Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner.*
#### Parameters
| Name | Type | Description |
|---|---|---|
| newOwner | address | undefined
### withdrawBalance
```solidity
function withdrawBalance() external nonpayable
```
Sends the contract's current balance to the owner.
## Events
### BalanceWithdrawn
```solidity
event BalanceWithdrawn(address indexed owner, uint256 balance)
```
Emitted any time the balance is withdrawn by the owner.
#### Parameters
| Name | Type | Description |
|---|---|---|
| owner `indexed` | address | The current owner and recipient of the funds. |
| balance | uint256 | The current contract balance paid to the owner. |
### DisbursementFailed
```solidity
event DisbursementFailed(uint256 indexed depositId, address indexed to, uint256 amount)
```
Emitted any time a disbursement fails to send.
#### Parameters
| Name | Type | Description |
|---|---|---|
| depositId `indexed` | uint256 | The unique sequence number identifying the deposit. |
| to `indexed` | address | The intended recipient of the disbursement. |
| amount | uint256 | The amount intended to be sent to the recipient. |
### DisbursementSuccess
```solidity
event DisbursementSuccess(uint256 indexed depositId, address indexed to, uint256 amount)
```
Emitted any time a disbursement is successfuly sent.
#### Parameters
| Name | Type | Description |
|---|---|---|
| depositId `indexed` | uint256 | The unique sequence number identifying the deposit. |
| to `indexed` | address | The recipient of the disbursement. |
| amount | uint256 | The amount sent to the recipient. |
### OwnershipTransferred
```solidity
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)
```
#### Parameters
| Name | Type | Description |
|---|---|---|
| previousOwner `indexed` | address | undefined |
| newOwner `indexed` | address | undefined |
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment