Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: prepare release #941

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/api-kit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@safe-global/api-kit",
"version": "2.4.3",
"version": "2.4.4",
"description": "SDK that facilitates the interaction with the Safe Transaction Service API",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
Expand Down Expand Up @@ -59,7 +59,7 @@
"yargs": "^17.7.2"
},
"dependencies": {
"@safe-global/protocol-kit": "^4.0.3",
"@safe-global/protocol-kit": "^4.0.4",
"@safe-global/safe-core-sdk-types": "^5.0.3",
"ethers": "^6.13.1",
"node-fetch": "^2.7.0"
Expand Down
49 changes: 39 additions & 10 deletions packages/api-kit/tests/e2e/confirmTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import Safe, {
SigningMethod,
buildContractSignature
} from '@safe-global/protocol-kit'
import { SafeTransactionDataPartial } from '@safe-global/safe-core-sdk-types'
import {
SafeMultisigConfirmationResponse,
SafeTransactionDataPartial
} from '@safe-global/safe-core-sdk-types'
import SafeApiKit from '@safe-global/api-kit/index'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { toBytes, toHex } from 'viem'
import { getKits } from '../utils/setupKits'

chai.use(chaiAsPromised)

const PRIVATE_KEY_1 = '0x83a415ca62e11f5fa5567e98450d0f82ae19ff36ef876c10a8d448c788a53676'
const PRIVATE_KEY_2 = '0xb88ad5789871315d0dab6fc5961d6714f24f35a6393f13a6f426dfecfc00ab44'
const PRIVATE_KEY_1 = '0x83a415ca62e11f5fa5567e98450d0f82ae19ff36ef876c10a8d448c788a53676' // Address: 0x56e2C102c664De6DfD7315d12c0178b61D16F171
const PRIVATE_KEY_2 = '0xb88ad5789871315d0dab6fc5961d6714f24f35a6393f13a6f426dfecfc00ab44' // Address: 0x9ccbde03edd71074ea9c49e413fa9cdff16d263b

let safeApiKit: SafeApiKit
let protocolKit: Safe
Expand All @@ -32,8 +36,9 @@ describe('proposeTransaction', () => {
it('should allow to create and confirm transactions signature using a Safe signer', async () => {
const safeTransactionData: SafeTransactionDataPartial = {
to: safeAddress,
value: '100000000000000000', // 0.01 ETH
data: '0x'
value: '10000000000000000', // 0.01 ETH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment on the right-hand side still correct? You could use the viem#parseEther and remove the comment altogether.

// We generate unique data from the current timestamp to receive a different tx hash each time
data: toHex(toBytes(Date.now()))
}

let tx = await protocolKit.createTransaction({ transactions: [safeTransactionData] })
Expand Down Expand Up @@ -90,14 +95,38 @@ describe('proposeTransaction', () => {
safeAddress
})

const isValidSignature = await protocolKit.isValidSignature(txHash, [ethSig, signerSafeSig])
console.log('- isValidSignature(txHash, signature) = ', isValidSignature)
// chai.expect(isValidSignature).to.be.true

const contractSig = buildSignatureBytes([signerSafeSig])

await chai.expect(safeApiKit.confirmTransaction(txHash, contractSig)).to.be.fulfilled

const confirmedMessage = await safeApiKit.getTransaction(txHash)
chai.expect(confirmedMessage?.confirmations?.length).to.eq(2)

chai.expect(confirmedMessage.confirmations?.length).to.eq(2)

const [confirmation1, confirmation2] = confirmedMessage!.confirmations as [
a: SafeMultisigConfirmationResponse,
b: SafeMultisigConfirmationResponse
]

// Check that the submission date is within the last minute
chai.expect(Date.now() - new Date(confirmation1.submissionDate).valueOf()).lte(60000)
chai.expect(Date.now() - new Date(confirmation2.submissionDate).valueOf()).lte(60000)

chai.expect(confirmedMessage.confirmations).to.deep.eq([
{
owner: signerAddress,
submissionDate: confirmation1.submissionDate,
transactionHash: null,
signature: ethSig.data,
signatureType: 'EOA'
},
{
owner: signerSafeAddress,
submissionDate: confirmation2.submissionDate,
transactionHash: null,
signature: contractSig.toLowerCase(),
signatureType: 'CONTRACT_SIGNATURE'
}
])
})
})
12 changes: 6 additions & 6 deletions packages/api-kit/tests/e2e/getMultisigTransactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ describe('getMultisigTransactions', () => {
})

it('should return the list of multisig transactions', async () => {
const safeAddress = '0xF8ef84392f7542576F6b9d1b140334144930Ac78' // Safe with multisig transactions
const safeAddress = '0xCa2f5A815b642c79FC530B60BC15Aee4eF6252b3' // Safe with multisig transactions
const safeMultisigTransactionListResponse =
await safeApiKit.getMultisigTransactions(safeAddress)
chai.expect(safeMultisigTransactionListResponse.count).to.be.equal(22)
chai.expect(safeMultisigTransactionListResponse.results.length).to.be.equal(22)
chai.expect(safeMultisigTransactionListResponse.count).to.be.equal(10)
chai.expect(safeMultisigTransactionListResponse.results.length).to.be.equal(10)
safeMultisigTransactionListResponse.results.map((transaction) => {
chai.expect(transaction.safe).to.be.equal(safeAddress)
})
})

it('should return the list of multisig transactions EIP-3770', async () => {
const safeAddress = '0xF8ef84392f7542576F6b9d1b140334144930Ac78' // Safe with multisig transactions
const safeAddress = '0xCa2f5A815b642c79FC530B60BC15Aee4eF6252b3' // Safe with multisig transactions
const eip3770SafeAddress = `${config.EIP_3770_PREFIX}:${safeAddress}`
const safeMultisigTransactionListResponse =
await safeApiKit.getMultisigTransactions(eip3770SafeAddress)
chai.expect(safeMultisigTransactionListResponse.count).to.be.equal(22)
chai.expect(safeMultisigTransactionListResponse.results.length).to.be.equal(22)
chai.expect(safeMultisigTransactionListResponse.count).to.be.equal(10)
chai.expect(safeMultisigTransactionListResponse.results.length).to.be.equal(10)
safeMultisigTransactionListResponse.results.map((transaction) => {
chai.expect(transaction.safe).to.be.equal(safeAddress)
})
Expand Down
12 changes: 6 additions & 6 deletions packages/api-kit/tests/e2e/getPendingTransactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ describe('getPendingTransactions', () => {
})

it('should return the the transaction list', async () => {
const safeAddress = '0xF8ef84392f7542576F6b9d1b140334144930Ac78' // Safe with pending transaction
const safeAddress = '0xCa2f5A815b642c79FC530B60BC15Aee4eF6252b3' // Safe with pending transaction
const transactionList = await safeApiKit.getPendingTransactions(safeAddress)
chai.expect(transactionList.count).to.be.equal(3)
chai.expect(transactionList.results.length).to.be.equal(3)
chai.expect(transactionList.count).to.be.equal(10)
chai.expect(transactionList.results.length).to.be.equal(10)
})

it('should return the the transaction list EIP-3770', async () => {
const safeAddress = '0xF8ef84392f7542576F6b9d1b140334144930Ac78' // Safe with pending transaction
const safeAddress = '0xCa2f5A815b642c79FC530B60BC15Aee4eF6252b3' // Safe with pending transaction
const eip3770SafeAddress = `${config.EIP_3770_PREFIX}:${safeAddress}`
const transactionList = await safeApiKit.getPendingTransactions(eip3770SafeAddress)
chai.expect(transactionList.count).to.be.equal(3)
chai.expect(transactionList.results.length).to.be.equal(3)
chai.expect(transactionList.count).to.be.equal(10)
chai.expect(transactionList.results.length).to.be.equal(10)
})
})
4 changes: 2 additions & 2 deletions packages/auth-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"react-dom": "^18.2.0"
},
"dependencies": {
"@safe-global/api-kit": "^2.4.3",
"@safe-global/protocol-kit": "^4.0.3",
"@safe-global/api-kit": "^2.4.4",
"@safe-global/protocol-kit": "^4.0.4",
"@web3auth/safeauth-embed": "^0.0.0",
"ethers": "^6.13.1"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/onramp-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
},
"dependencies": {
"@monerium/sdk": "^2.12.0",
"@safe-global/api-kit": "^2.4.3",
"@safe-global/protocol-kit": "^4.0.3",
"@safe-global/api-kit": "^2.4.4",
"@safe-global/protocol-kit": "^4.0.4",
"@safe-global/safe-core-sdk-types": "^5.0.3",
"@stripe/crypto": "^0.0.4",
"@stripe/stripe-js": "^1.54.2",
Expand Down
10 changes: 6 additions & 4 deletions packages/protocol-kit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@safe-global/protocol-kit",
"version": "4.0.3",
"version": "4.0.4",
"description": "SDK that facilitates the interaction with Safe Smart Accounts",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand All @@ -12,7 +12,9 @@
"SDK"
],
"scripts": {
"safe-deployments": "ts-node scripts/checkSafeDeployments.ts",
"check-safe-deployments": "ts-node scripts/safe-deployments/checkSafeDeployments.ts",
"update-safe-deployments": "ts-node scripts/safe-deployments/updateLocalNetworks.ts",
"check-short-name-integrity": "ts-node scripts/safe-deployments/checkShortNameIntegrity.ts",
"test": "mocha -r ts-node/register -r tsconfig-paths/register tests/unit/**/*.ts",
"test:hardhat:web3:v1.0.0": "export TEST_NETWORK=hardhat && export ETH_LIB=web3 && export SAFE_VERSION=1.0.0 && hardhat deploy && nyc hardhat test",
"test:hardhat:web3:v1.1.1": "export TEST_NETWORK=hardhat && export ETH_LIB=web3 && export SAFE_VERSION=1.1.1 && hardhat deploy && nyc hardhat test",
Expand All @@ -33,7 +35,7 @@
"format:check": "prettier --check \"*/**/*.{js,json,md,ts}\"",
"format": "prettier --write \"*/**/*.{js,json,md,ts}\"",
"unbuild": "rimraf dist artifacts deployments cache .nyc_output *.tsbuildinfo",
"build": "yarn unbuild && hardhat compile && yarn safe-deployments && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json"
"build": "yarn unbuild && hardhat compile && yarn check-safe-deployments && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -74,7 +76,7 @@
"dependencies": {
"@noble/hashes": "^1.3.3",
"@safe-global/safe-core-sdk-types": "^5.0.3",
"@safe-global/safe-deployments": "^1.37.1",
"@safe-global/safe-deployments": "^1.37.3",
"abitype": "^1.0.2",
"ethereumjs-util": "^7.1.5",
"ethers": "^6.13.1",
Expand Down
48 changes: 0 additions & 48 deletions packages/protocol-kit/scripts/checkSafeDeployments.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { getLocalNetworksConfig, getSafeDeploymentNetworks } from './utils'

/**
* Checks if there are any differences between the local EIP-3770 network configurations and the safe deployment networks.
*
* @function checkConfigDiff
* @returns {void} - nothing, just throws an error if there are any discrepancies
*/
function checkConfigDiff() {
const safeDeployments = getSafeDeploymentNetworks()
const localNetworks = getLocalNetworksConfig()

const chainIdsMissing = safeDeployments.filter((chainId) => !localNetworks.includes(chainId))
if (chainIdsMissing.length > 0) {
const errorMessage = `EIP-3770 local config is missing chainIds: ${chainIdsMissing}\nPlease run 'yarn workspace @safe-global/protocol-kit update-safe-deployments`
throw new Error(errorMessage)
}

const chainIdsExtra = localNetworks.filter((chainId) => !safeDeployments.includes(chainId))
if (chainIdsExtra.length > 0) {
const errorMessage = `EIP-3770 local config has not required chainIds: ${chainIdsExtra}`
throw new Error(errorMessage)
}
}

checkConfigDiff()
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getChainShortName } from './utils'
import { networks } from '../../src/utils/eip-3770/config'

/**
* Checks the short names of local EIP-3770 networks to match their corresponding chain short names.
*
* @async
* @function checkShortNameIntegrity
* @returns {void} - nothing, just prints those chains where the name is not the same.
*/
async function checkShortNameIntegrity() {
for (const network of networks) {
try {
const shortName = await getChainShortName(network.chainId.toString())
if (network.shortName !== shortName) {
// It just prints the chain that is not aligned so we can check if manual action is necessary.
console.log(`Update ${network.chainId} from '${network.shortName}' to '${shortName}'`)
}
} catch (error) {
console.log(`EIP-3770 Failed to retrieve chain name for ${network.chainId}`)
}
}

console.log('Local network configuration checked successfully!')
}

checkShortNameIntegrity()
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import fs from 'fs'
import { getChainShortName, getLocalNetworksConfig, getSafeDeploymentNetworks } from './utils'
import { networks } from '../../src/utils/eip-3770/config'

interface NetworkShortName {
shortName: string
chainId: bigint
}

/**
* Updates the local networks array in the configuration file.
*
* @param {NetworkShortName[]} networks - The full list of networks.
*/

function updateLocalNetworks(networks: NetworkShortName[]) {
const path = 'src/utils/eip-3770/config.ts'

fs.readFile(path, (err, data) => {
if (err) {
console.error(err)
return
}

const content = data.toString()
const startIndex =
content.indexOf('export const networks: NetworkShortName[] = [') +
'export const networks: NetworkShortName[] = ['.length
const endIndex = content.indexOf(']\n\nif (process.env.TEST_NETWORK ===')

const sortedNetworks = networks
.sort((a, b) => Number(a.chainId - b.chainId))
.map(
(network, index) =>
` { chainId: ${network.chainId}n, shortName: '${network.shortName}' }${index === networks.length - 1 ? '' : ','}`
Copy link
Contributor

@leonardotc leonardotc Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this thing is that, because we are assembling bits of content in different statements, its hard to understand the outgoing structure. Life would be much kinder to us if it looked more like "stuffing" a template (if possible)... e.g.:

`
    export const networks: NetworkShortName[] = [
        ${sortedNetworks.map(network => `
        {
            chainId: '${network.name}',
            shortName: '${network.shortName}'
        }`).join(',')}
    ]
`

)
.join('\n')

fs.writeFile(
path,
`${content.substring(0, startIndex)}\n${sortedNetworks}\n${content.substring(endIndex)}`,
(err) => {
if (err) {
console.error(err)
} else {
console.log('Networks array updated successfully!')
}
}
)
})
}

/**
* Checks and updates the local networks configuration file.
*/
async function checkAndUpdate() {
const safeDeployments = getSafeDeploymentNetworks()
const localNetworks = getLocalNetworksConfig()

const chainIdsMissing = safeDeployments.filter((chainId) => !localNetworks.includes(chainId))
if (chainIdsMissing.length > 0) {
const updateNetworks = [...networks]
for (const chainId of chainIdsMissing) {
try {
const shortName = await getChainShortName(chainId)
console.log(`Adding ${chainId} with shortName ${shortName}`)
updateNetworks.push({ chainId: BigInt(chainId), shortName: shortName })
} catch (error) {
throw new Error(`EIP-3770 Failed to retrieve chain name for ${chainId}`)
}
}

updateLocalNetworks(updateNetworks)
}
}

checkAndUpdate()
Loading
Loading