Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion e2e/get-owned-safes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('getOwnedSages tests', () => {
const data = await getOwnedSafes(config.baseUrl, '4', '0x661E1CF4aAAf6a95C89EA8c81D120E6c62adDFf9')

expect(data).toEqual({
safes: ['0x9B5dc27B104356516B05b02F6166a54F6D74e40B', '0xb3b83bf204C458B461de9B0CD2739DB152b4fa5A'],
safes: ['0xb3b83bf204C458B461de9B0CD2739DB152b4fa5A', '0x9B5dc27B104356516B05b02F6166a54F6D74e40B'],
})
})

Expand Down
16 changes: 16 additions & 0 deletions e2e/post-safe-gas-estimation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { postSafeGasEstimation } from '../src'
import config from './config'

describe('postSafeGasEstimation tests', () => {
it('should post a safe gas estimation', async () => {
const result = await postSafeGasEstimation(config.baseUrl, '4', '0x4f9BD57BCC68Bf7770429F137922B3afD23d83E7', {
to: '0x4f9BD57BCC68Bf7770429F137922B3afD23d83E7',
value: '1',
data: '0x',
operation: 0,
})
console.log(result)
expect(result.safeTxGas).toBe('43663')
Copy link
Member

Choose a reason for hiding this comment

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

Is this deterministic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While doing the exact same operation tt should be deterministic at least until the smart contract is updated

expect(result.latestNonce).toBe(1)
})
})
2 changes: 1 addition & 1 deletion e2e/safes-read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('getSafeInfo tests', () => {

expect(data.address.value).toBe(address)
expect(data.guard).toBe(null)
expect(data.nonce).toBe(3)
expect(data.nonce).toBe(4)
expect(data.owners).toEqual([
{
value: '0x21D62C6894741DE97944D7844ED44D7782C66ABC',
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
"@babel/preset-env": "^7.15.0",
"@babel/preset-typescript": "^7.15.0",
"@types/jest": "^27.0.1",
"@typescript-eslint/eslint-plugin": "^4.29.0",
"@typescript-eslint/parser": "^4.29.0",
"babel-jest": "^27.0.6",
"@typescript-eslint/eslint-plugin": "^4.31.0",
"@typescript-eslint/parser": "^4.31.0",
"babel-jest": "^27.2.0",
"copy-webpack-plugin": "^9.0.1",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.0",
"eslint-plugin-prettier": "^3.4.0",
"husky": "^7.0.1",
"jest": "^27.0.6",
"prettier": "^2.3.2",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.2",
"jest": "^27.2.0",
"prettier": "^2.4.0",
"ts-loader": "^9.2.5",
"typescript": "^4.3.5",
"typescript": "^4.4.3",
"webpack": "^5.49.0",
"webpack-cli": "^4.7.2"
},
Expand Down
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ export function getTransactionDetails(baseUrl: string, chainId: string, transact
})
}

export function postSafeGasEstimation(
baseUrl: string,
chainId: string,
address: string,
body: operations['post_safe_gas_estimation']['parameters']['body'],
) {
return callEndpoint(baseUrl, '/chains/{chainId}/safes/{safe_address}/multisig-transactions/estimations', {
path: { chainId, safe_address: address },
body,
})
}

export function proposeTransaction(
baseUrl: string,
chainId: string,
Expand Down
38 changes: 37 additions & 1 deletion src/types/gateway.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { TokenType, TransactionListItem, MultisigTransactionRequest, TransactionDetails } from './transactions'
import {
MultisigTransactionRequest,
TokenType,
TransactionDetails,
TransactionListItem,
SafeTransactionEstimation,
SafeTransactionEstimationRequest,
} from './transactions'

export interface paths {
'/chains/{chainId}/safes/{address}/': {
Expand Down Expand Up @@ -62,6 +69,16 @@ export interface paths {
}
}
}
'/chains/{chainId}/safes/{safe_address}/multisig-transactions/estimations': {
/** This is actually supposed to be POST but it breaks our type paradise */
get: operations['post_safe_gas_estimation']
parameters: {
path: {
chainId: string
safe_address: string
}
}
}
'/chains/{chainId}/transactions/{safe_address}/propose': {
/** This is actually supposed to be POST but it breaks our type paradise */
get: operations['propose_transaction']
Expand Down Expand Up @@ -142,6 +159,7 @@ export interface definitions {
metadata: { [key: string]: string }
}

SafeTransactionEstimation: SafeTransactionEstimation
TransactionListItem: TransactionListItem
TransactionListPage: Page<TransactionListItem>
TransactionDetails: TransactionDetails
Expand Down Expand Up @@ -273,6 +291,24 @@ export interface operations {
}
}
}
post_safe_gas_estimation: {
parameters: {
path: {
chainId: string
safe_address: string
}
body: SafeTransactionEstimationRequest
}
responses: {
200: {
schema: definitions['SafeTransactionEstimation']
}
/** Safe not found */
404: unknown
/** Safe address checksum not valid */
422: unknown
}
}
propose_transaction: {
parameters: {
path: {
Expand Down
16 changes: 16 additions & 0 deletions src/types/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,19 @@ export type TransactionDetails = {
}

/* Transaction details types end */

/* Transaction estimation types */

export type SafeTransactionEstimationRequest = {
to: string
value: string
data: string
operation: Operation
}

export type SafeTransactionEstimation = {
latestNonce: number
safeTxGas: string
}

/* Transaction estimation types end */
27 changes: 15 additions & 12 deletions tests/endpoint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,71 +14,74 @@ jest.mock('../src/utils', () => {
describe('callEndpoint', () => {
it('should accept just a path', async () => {
await expect(
callEndpoint('https://safe-client.xdai.staging.gnosisdev.com/v1', '/balances/supported-fiat-codes'),
Copy link
Member

Choose a reason for hiding this comment

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

Wow, how did this work before? 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While the not unified version is online this would work, but, as we already switched to the unified version better to update this just in case 😉

Copy link
Member

Choose a reason for hiding this comment

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

Ah, because it's not TypeScript. It didn't detect that this endpoint doesn't exist.

callEndpoint('https://safe-client.staging.gnosisdev.com/v1', '/chains/100/balances/supported-fiat-codes'),
).resolves.toEqual({ success: true })

expect(fetchData).toHaveBeenCalledWith(
'https://safe-client.xdai.staging.gnosisdev.com/v1/balances/supported-fiat-codes',
'https://safe-client.staging.gnosisdev.com/v1/chains/100/balances/supported-fiat-codes',
undefined,
)
})

it('should accept a path param', async () => {
await expect(
callEndpoint('https://safe-client.rinkeby.staging.gnosisdev.com/v1', '/safe/{address}', {
callEndpoint('https://safe-client.staging.gnosisdev.com/v1', '/chains/4/safe/{address}', {
path: { address: '0x123' },
}),
).resolves.toEqual({ success: true })

expect(fetchData).toHaveBeenCalledWith('https://safe-client.rinkeby.staging.gnosisdev.com/v1/safe/0x123', undefined)
expect(fetchData).toHaveBeenCalledWith(
'https://safe-client.staging.gnosisdev.com/v1/chains/4/safe/0x123',
undefined,
)
})

it('should accept several path params', async () => {
await expect(
callEndpoint('https://safe-client.rinkeby.staging.gnosisdev.com/v1', '/balances/{address}/{currency}', {
callEndpoint('https://safe-client.staging.gnosisdev.com/v1', '/chains/4/balances/{address}/{currency}', {
path: { address: '0x123', currency: 'usd' },
}),
).resolves.toEqual({ success: true })

expect(fetchData).toHaveBeenCalledWith(
'https://safe-client.rinkeby.staging.gnosisdev.com/v1/balances/0x123/usd',
'https://safe-client.staging.gnosisdev.com/v1/chains/4/balances/0x123/usd',
undefined,
)
})

it('should accept query params', async () => {
await expect(
callEndpoint('https://safe-client.rinkeby.staging.gnosisdev.com/v1', '/balances/{address}/{currency}', {
callEndpoint('https://safe-client.staging.gnosisdev.com/v1', '/chains/4/balances/{address}/{currency}', {
path: { address: '0x123', currency: 'usd' },
query: { exclude_spam: true },
}),
).resolves.toEqual({ success: true })

expect(fetchData).toHaveBeenCalledWith(
'https://safe-client.rinkeby.staging.gnosisdev.com/v1/balances/0x123/usd?exclude_spam=true',
'https://safe-client.staging.gnosisdev.com/v1/chains/4/balances/0x123/usd?exclude_spam=true',
undefined,
)
})

it('should accept body', async () => {
await expect(
callEndpoint('https://safe-client.rinkeby.staging.gnosisdev.com/v1', '/transactions/{safe_address}/propose', {
callEndpoint('https://safe-client.staging.gnosisdev.com/v1', '/chains/4/transactions/{safe_address}/propose', {
path: { safe_address: '0x123' },
body: { test: 'test' },
}),
).resolves.toEqual({ success: true })

expect(fetchData).toHaveBeenCalledWith(
'https://safe-client.rinkeby.staging.gnosisdev.com/v1/transactions/0x123/propose',
'https://safe-client.staging.gnosisdev.com/v1/chains/4/transactions/0x123/propose',
{ test: 'test' },
)
})

it('should accept a raw URL', async () => {
await expect(
callEndpoint(
'https://safe-client.rinkeby.staging.gnosisdev.com/v1',
'/balances/{address}/{currency}',
'https://safe-client.staging.gnosisdev.com/v1',
'/chains/4/balances/{address}/{currency}',
{ path: { address: '0x123', currency: 'usd' }, query: { exclude_spam: true } },
'/test-url?raw=true',
),
Expand Down
Loading