Skip to content

Commit

Permalink
revert unnecessary Viem changes in api-kit playground
Browse files Browse the repository at this point in the history
  • Loading branch information
dasanra committed Aug 8, 2024
1 parent eeeeb84 commit 1c7dfb4
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 18 deletions.
12 changes: 6 additions & 6 deletions playground/api-kit/confirm-transaction.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Chain } from 'viem'
import { sepolia } from 'viem/chains'
import Safe from '@safe-global/protocol-kit'
import SafeApiKit from '@safe-global/api-kit'

// This file can be used to play around with the Safe Core SDK

interface Config {
CHAIN: Chain
CHAIN_ID: bigint
RPC_URL: string
SIGNER_ADDRESS_PRIVATE_KEY: string
SAFE_ADDRESS: string
SAFE_TX_HASH: string
}

const config: Config = {
CHAIN: sepolia,
CHAIN_ID: 11155111n,
RPC_URL: 'https://sepolia.gateway.tenderly.co',
SIGNER_ADDRESS_PRIVATE_KEY: '<SIGNER_ADDRESS_PRIVATE_KEY>',
SAFE_ADDRESS: '<SAFE_ADDRESS>',
SAFE_TX_HASH: '<SAFE_TX_HASH>'
Expand All @@ -22,14 +22,14 @@ const config: Config = {
async function main() {
// Create Safe instance
const protocolKit = await Safe.init({
provider: config.CHAIN.rpcUrls.default.http[0],
provider: config.RPC_URL,
signer: config.SIGNER_ADDRESS_PRIVATE_KEY,
safeAddress: config.SAFE_ADDRESS
})

// Create Safe API Kit instance
const apiKit = new SafeApiKit({
chainId: BigInt(config.CHAIN.id)
chainId: config.CHAIN_ID
})

// Get the transaction
Expand Down
13 changes: 7 additions & 6 deletions playground/api-kit/execute-transaction.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { Chain, Hash } from 'viem'
import { Hash } from 'viem'
import { waitForTransactionReceipt } from 'viem/actions'
import { sepolia } from 'viem/chains'
import Safe from '@safe-global/protocol-kit'
import SafeApiKit from '@safe-global/api-kit'

// This file can be used to play around with the Safe Core SDK

interface Config {
CHAIN: Chain
CHAIN_ID: bigint
RPC_URL: string
SIGNER_ADDRESS_PRIVATE_KEY: string
SAFE_ADDRESS: string
SAFE_TX_HASH: string
}

const config: Config = {
CHAIN: sepolia,
CHAIN_ID: 11155111n,
RPC_URL: 'https://sepolia.gateway.tenderly.co',
SIGNER_ADDRESS_PRIVATE_KEY: '<SIGNER_ADDRESS_PRIVATE_KEY>',
SAFE_ADDRESS: '<SAFE_ADDRESS>',
SAFE_TX_HASH: '<SAFE_TX_HASH>'
Expand All @@ -23,14 +24,14 @@ const config: Config = {
async function main() {
// Create Safe instance
const protocolKit = await Safe.init({
provider: config.CHAIN.rpcUrls.default.http[0],
provider: config.RPC_URL,
signer: config.SIGNER_ADDRESS_PRIVATE_KEY,
safeAddress: config.SAFE_ADDRESS
})

// Create Safe API Kit instance
const apiKit = new SafeApiKit({
chainId: BigInt(config.CHAIN.id)
chainId: config.CHAIN_ID
})

// Get the transaction
Expand Down
12 changes: 6 additions & 6 deletions playground/api-kit/propose-transaction.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import { Chain } from 'viem'
import { sepolia } from 'viem/chains'
import Safe from '@safe-global/protocol-kit'
import SafeApiKit from '@safe-global/api-kit'
import { OperationType, SafeTransactionDataPartial } from '@safe-global/safe-core-sdk-types'

// This file can be used to play around with the Safe Core SDK

interface Config {
CHAIN: Chain
CHAIN_ID: bigint
RPC_URL: string
SIGNER_ADDRESS_PRIVATE_KEY: string
SAFE_ADDRESS: string
}

const config: Config = {
CHAIN: sepolia,
CHAIN_ID: 11155111n,
RPC_URL: 'https://sepolia.gateway.tenderly.co',
SIGNER_ADDRESS_PRIVATE_KEY: '<SIGNER_ADDRESS_PRIVATE_KEY>',
SAFE_ADDRESS: '<SAFE_ADDRESS>'
}

async function main() {
// Create Safe instance
const protocolKit = await Safe.init({
provider: config.CHAIN.rpcUrls.default.http[0],
provider: config.RPC_URL,
signer: config.SIGNER_ADDRESS_PRIVATE_KEY,
safeAddress: config.SAFE_ADDRESS
})

// Create Safe API Kit instance
const apiKit = new SafeApiKit({
chainId: BigInt(config.CHAIN.id)
chainId: config.CHAIN_ID
})

// Create transaction
Expand Down
71 changes: 71 additions & 0 deletions playground/relay-kit/raw-paid-transaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { ethers } from 'ethers'
import { GelatoRelayPack } from '@safe-global/relay-kit'
import Safe, { EthersAdapter } from '@safe-global/protocol-kit'
import { MetaTransactionData } from '@safe-global/safe-core-sdk-types'

// Check the status of a transaction after it is relayed:
// https://relay.gelato.digital/tasks/status/<TASK_ID>

// Check the status of a transaction after it is executed:
// https://goerli.etherscan.io/tx/<TRANSACTION_HASH>
const config = {
SAFE_SIGNER_PRIVATE_KEY: process.env.DEV_MNEM as string, // '<SAFE_SIGNER_PRIVATE_KEY>',
RPC_URL: `https://goerli.infura.io/v3/${process.env.INF_API as string}`
}

// const mockOnRampConfig = {
// ADDRESS: '<ADDRESS>',
// PRIVATE_KEY: '<PRIVATE_KEY>'
// }

// const txConfig = {
// TO: '<TO>',
// DATA: '<DATA>',
// VALUE: '<VALUE>',
// // Options:
// GAS_LIMIT: BigNumber.from('<GAS_LIMIT>'),
// GAS_TOKEN: ethers.constants.AddressZero
// }

async function main() {
console.log('Create meta-transaction via Gelato Relay paid with balance in the Safe')

// SDK Initialization
const provider = new ethers.JsonRpcProvider(config.RPC_URL)
const signer = new ethers.Wallet(config.SAFE_SIGNER_PRIVATE_KEY, provider)

const transactions: MetaTransactionData[] = [
{
to: '0x883d9e75479c5064636984f592e9d2a110a27106',
data: '0x',
value: '10000000000000000'
}
]

const ethAdapter = new EthersAdapter({
ethers,
signerOrProvider: signer
})

const protocolKit: Safe = await Safe.create({
ethAdapter,
safeAddress: '0x883d9e75479c5064636984f592e9d2a110a27106'
})

const relayKit = new GelatoRelayPack({ protocolKit })

const safeTransaction = await relayKit.createRelayedTransaction({ transactions })

console.log(safeTransaction)

const signedSafeTransaction = await protocolKit.signTransaction(safeTransaction)

const response = await relayKit.executeRelayTransaction(signedSafeTransaction)

console.log(
`Relay Transaction Task ID: https://relay.gelato.digital/tasks/status/${response.taskId}`
)
return response.taskId
}

main()
76 changes: 76 additions & 0 deletions playground/relay-kit/raw-sponsored-transaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { ethers } from 'ethers'
import { GelatoRelayPack } from '@safe-global/relay-kit'
import Safe, { EthersAdapter } from '@safe-global/protocol-kit'
import { MetaTransactionData, MetaTransactionOptions } from '@safe-global/safe-core-sdk-types'

// Check the status of a transaction after it is relayed:
// https://relay.gelato.digital/tasks/status/<TASK_ID>

// Check the status of a transaction after it is executed:
// https://goerli.etherscan.io/tx/<TRANSACTION_HASH>
const config = {
SAFE_SIGNER_PRIVATE_KEY: process.env.DEV_MNEM as string, // '<SAFE_SIGNER_PRIVATE_KEY>',
RPC_URL: `https://goerli.infura.io/v3/${process.env.INF_API as string}`
}

// const mockOnRampConfig = {
// ADDRESS: '<ADDRESS>',
// PRIVATE_KEY: '<PRIVATE_KEY>'
// }

// const txConfig = {
// TO: '<TO>',
// DATA: '<DATA>',
// VALUE: '<VALUE>',
// // Options:
// GAS_LIMIT: BigNumber.from('<GAS_LIMIT>'),
// GAS_TOKEN: ethers.constants.AddressZero
// }

async function main() {
console.log('Execute meta-transaction via Gelato Relay paid by 1Balance')

// SDK Initialization
const provider = new ethers.JsonRpcProvider(config.RPC_URL)
const signer = new ethers.Wallet(config.SAFE_SIGNER_PRIVATE_KEY, provider)
const ethAdapter = new EthersAdapter({
ethers,
signerOrProvider: signer
})

const protocolKit = await Safe.create({
ethAdapter,
safeAddress: '0x883d9e75479c5064636984f592e9d2a110a27106'
})

const relayKit = new GelatoRelayPack({ protocolKit })

const transactions: MetaTransactionData[] = [
{
to: '0x883d9e75479c5064636984f592e9d2a110a27106',
data: '0x',
value: '10000000000000000'
}
]
const options: MetaTransactionOptions = {
isSponsored: true
}

const safeTransaction = await relayKit.createRelayedTransaction({
transactions,
options
})

console.log(safeTransaction)

const signedSafeTransaction = await protocolKit.signTransaction(safeTransaction)

const response = await relayKit.executeRelayTransaction(signedSafeTransaction, options)

console.log(
`Relay Transaction Task ID: https://relay.gelato.digital/tasks/status/${response.taskId}`
)
return response.taskId
}

main()

0 comments on commit 1c7dfb4

Please sign in to comment.