-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
4,021 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ETHEREUM_PRIVATE_KEY=bd75a7b8a79f94102f4fcb9cc282660ec644798620980cd830a82454262bceca | ||
ALCHEMY_MUMBAI_URL=https://polygon-mumbai.g.alchemy.com/v2/gab24G6d4XSf3EA2dMLTEsEZqfQ4gJPB | ||
ALCHEMY_GOERLI_URL=https://eth-goerli.g.alchemy.com/v2/jQRXBq2vttfq5xNT1SCgli1Q9Kl_B4Bi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ yarn-error.log* | |
|
||
# local env files | ||
.env*.local | ||
.env | ||
|
||
# vercel | ||
.vercel | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** @type import('hardhat/config').HardhatUserConfig */ | ||
module.exports = { | ||
solidity: "0.8.18", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import type {NextApiRequest, NextApiResponse} from 'next'; | ||
|
||
import {ethers} from 'ethers' | ||
import Safe, {AddOwnerTxParams, EthersAdapter} from '@safe-global/protocol-kit' | ||
import {SafeFactory} from '@safe-global/protocol-kit' | ||
import {SafeAccountConfig} from '@safe-global/protocol-kit' | ||
import {update} from 'immutable'; | ||
|
||
//process.env.ALCHEMY_MUMBAI_URL | ||
|
||
let acc0 = process.env.ETHEREUM_PRIVATE_KEY as string; | ||
// goerli deploys | ||
let gameGuard = '0x2D00A3F404AEaea97E929766d595A90D8bE0554d'; | ||
let moduleAddress = '0xc074Dca6083ccD17872394c8A58Cb79Ac660Ac3d'; | ||
|
||
const provider = new ethers.providers.JsonRpcProvider(process.env.ALCHEMY_GOERLI_URL) | ||
const dev = new ethers.Wallet(acc0, provider) | ||
|
||
async function updateOwners(safeInstance: any, newOwner: string) { | ||
let params: AddOwnerTxParams = { | ||
ownerAddress: newOwner | ||
} | ||
|
||
let ret = []; | ||
|
||
let safeTX = await safeInstance.createAddOwnerTx(params) | ||
let txResponse = await safeInstance.executeTransaction(safeTX) | ||
await txResponse.transactionResponse?.wait() | ||
|
||
console.log('Adding new owner: ', txResponse); | ||
|
||
params = { | ||
ownerAddress: await dev.getAddress() | ||
} | ||
|
||
safeTX = await safeInstance.createRemoveOwnerTx(params); | ||
txResponse = await safeInstance.executeTransaction(safeTX); | ||
await txResponse.transactionResponse?.wait(); | ||
|
||
console.log('Removing dev: ', txResponse); | ||
} | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
try { | ||
const {ethAddress} = req.body; // body only contains ETH address | ||
|
||
// if (!ethers.utils.isAddress(ethAddress)) return; | ||
|
||
// get signers | ||
const owner1Signer = new ethers.Wallet(acc0, provider); | ||
const ethAdapterOwner1 = new EthersAdapter({ | ||
ethers, | ||
signerOrProvider: owner1Signer | ||
}); | ||
|
||
// create safe config | ||
const safeFactory = await SafeFactory.create({ethAdapter: ethAdapterOwner1}); | ||
const safeAccountConfig: SafeAccountConfig = { | ||
owners: [ | ||
await owner1Signer.getAddress() // set original owner to be server | ||
], | ||
threshold: 1 | ||
}; | ||
|
||
// create safe for user | ||
const safeInstance = await safeFactory.deploySafe({safeAccountConfig}); | ||
const safeAddress = safeInstance.getAddress(); | ||
|
||
// enable superfluid module | ||
let safeTX = await safeInstance.createEnableModuleTx(moduleAddress) | ||
let txResponse = await safeInstance.executeTransaction(safeTX) | ||
await txResponse.transactionResponse?.wait() | ||
|
||
await updateOwners(safeInstance, ethAddress); | ||
|
||
// enable guard - final step | ||
// safeTX = await safeInstance.createEnableGuardTx(gameGuard) | ||
// txResponse = await safeInstance.executeTransaction(safeTX) | ||
// await txResponse.transactionResponse?.wait() | ||
|
||
const modules = await safeInstance.getModules(); | ||
const guardAddress = await safeInstance.getGuard(); | ||
|
||
console.log(safeAddress, modules, guardAddress); | ||
res.send({success: true}); | ||
} catch (error) { | ||
console.error(error) | ||
// @ts-ignore | ||
res.status(500).send({success: false, error: error.message}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {NextApiRequest, NextApiResponse} from 'next'; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
try { | ||
// implement any game action | ||
res.send({success: true}); | ||
} catch (error) { | ||
console.error(error) | ||
// @ts-ignore | ||
res.status(500).send({success: false, error: error.message}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {NextApiRequest, NextApiResponse} from 'next'; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
try { | ||
// start superfluid subscription | ||
res.send({success: true}); | ||
} catch (error) { | ||
console.error(error) | ||
// @ts-ignore | ||
res.status(500).send({success: false, error: error.message}) | ||
} | ||
} |
Oops, something went wrong.