Skip to content

Commit

Permalink
misc. plugin support
Browse files Browse the repository at this point in the history
  • Loading branch information
jimobrien committed Aug 3, 2023
1 parent d02e182 commit 9e5e624
Show file tree
Hide file tree
Showing 14 changed files with 3,657 additions and 3,592 deletions.
11 changes: 10 additions & 1 deletion packages/connext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"name": "@rabbitholegg/questdk-plugin-connext",
"version": "1.0.0-alpha.0",
"type": "module",
"exports": {
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js"
},
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"packageManager": "[email protected]",
Expand All @@ -23,15 +27,20 @@
"test:ci": "CI=true vitest --coverage",
"test:typecheck": "SKIP_GLOBAL_SETUP=true vitest typecheck",
"test:ui": "vitest dev --ui",
"typecheck": "tsc --noEmit"
"typecheck": "tsc --noEmit",
"update-contract-addresses": "ts-node -P ./scripts/tsconfig.json ./scripts/update-contract-addresses.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"types": "./dist/types/index.d.ts",
"typings": "./dist/types/index.d.ts",
"devDependencies": {
"@types/node": "^20.4.5",
"@vitest/coverage-v8": "^0.33.0",
"rimraf": "^5.0.1",
"rome": "^12.1.3",
"ts-node": "^10.9.1",
"tsconfig": "workspace:*",
"typescript": "^5.1.6",
"vitest": "^0.33.0"
Expand Down
12 changes: 12 additions & 0 deletions packages/connext/scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"module": "CommonJS",
"target": "es2017",
"lib": ["es2017", "dom"],
"strict": true,
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true
},
"include": ["./**/*.ts"]
}
42 changes: 42 additions & 0 deletions packages/connext/scripts/update-contract-addresses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import connextContracts from '@connext/smart-contracts/deployments.json'
import fs from 'fs'
import path from 'path'
import { type Abi } from 'viem'

type ConnextContractsJson = {
[chainId: string]: {
chainId: string
name: string
contracts: {
[name: string]: {
address: string
abi: Abi
}
}
}[]
}

const _getContract = (chainId: number, name: string) => {
const contracts = connextContracts as ConnextContractsJson
return contracts[chainId][0].contracts[name]
}

async function main() {
const _CONNEXT_CONTRACT_NAME = 'Connext'
const _networks = Object.keys(connextContracts)
const contractAddresses: Record<string, string> = {}

for (const network of _networks) {
const contract = _getContract(Number(network), _CONNEXT_CONTRACT_NAME)
if (contract) {
contractAddresses[network] = contract.address
}
}

fs.writeFileSync(
path.join(__dirname, '../src/contract-addresses.ts'),
JSON.stringify(contractAddresses, null, 2),
)
}

main()
34 changes: 7 additions & 27 deletions packages/connext/src/Connext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chainData from './chain-data.json'
import connextContracts from '@connext/smart-contracts/deployments.json'
import { type BridgeAction, compressJson } from '@rabbitholegg/questdk'
import { type Abi, toHex } from 'viem'
import { chainData } from './chain-data.js'
import { ConnextContract } from './contract-addresses.js'
import { type BridgeActionParams, compressJson } from '@rabbitholegg/questdk'
import { toHex } from 'viem'

const getChainData = async (chainId: number) => {
return chainData.find((chain) => chain.chainId === chainId)
Expand Down Expand Up @@ -42,27 +42,7 @@ export const XCALL_ABI_FRAGMENTS = [
},
]

type ConnextContractsJson = {
[chainId: string]: {
chainId: string
name: string
contracts: {
[name: string]: {
address: string
abi: Abi
}
}
}[]
}

const getContract = (chainId: number, name: string) => {
const contracts = connextContracts as ConnextContractsJson
return contracts[chainId][0].contracts[name]
}

export const bridge = async (
bridge: BridgeAction & { destinationChainId: number },
) => {
export const bridge = async (bridge: BridgeActionParams) => {
const {
sourceChainId,
destinationChainId,
Expand All @@ -80,12 +60,12 @@ export const bridge = async (
)
}

const contract = getContract(sourceChainId, 'Connext')
const defaultContractAddress = ConnextContract[sourceChainId]

// https://docs.connext.network/developers/reference/contracts/calls#xcall
return compressJson({
chainId: toHex(sourceChainId),
to: contractAddress || contract.address,
to: contractAddress || defaultContractAddress,
input: {
$abi: XCALL_ABI_FRAGMENTS,
_destination: Number(chain.domainId),
Expand Down
Loading

0 comments on commit 9e5e624

Please sign in to comment.