Skip to content

Commit

Permalink
Add Berachain support to SDK (#1128)
Browse files Browse the repository at this point in the history
* feat: berachain support for push-sdk

* fix: add Berachain

* fix: added tests, fixed address

---------

Co-authored-by: Pratham Bhatnagar <[email protected]>
Co-authored-by: aman035 <[email protected]>
  • Loading branch information
3 people authored Mar 19, 2024
1 parent c01798a commit 7c569ee
Show file tree
Hide file tree
Showing 17 changed files with 2,181 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
echo "\nRunning GIT hooks..."
yarn cleanbuild
yarn nx affected --target=lint
#yarn nx affected --target=test
yarn nx affected --target=test
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ const NETWORK_MAPPING: NwMappingType = {
421613: "ARBITRUM_TESTNET",
42161: "ARBITRUMONE_MAINNET",
122: "FUSE_MAINNET",
123: "FUSE_TESTNET"
123: "FUSE_TESTNET",
80085: "BERACHAIN_TESTNET",
};

const injected = new InjectedConnector({
supportedChainIds: [1, 3, 4, 11155111, 42, 137, 80001, 56, 97, 10, 420, 1442, 1101, 421613, 42161, 122, 123],
supportedChainIds: [1, 3, 4, 11155111, 42, 137, 80001, 56, 97, 10, 420, 1442, 1101, 421613, 42161, 122, 123,80085],
})

const ConnectWrapper = styled.div`
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/sdk-frontend-react/src/app/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Constants = {
},
DEFAULT_CHAIN_ID: 11155111,
DEV_CHAIN_ID: 99999,
NON_ETH_CHAINS: [137, 80001, 56, 97, 10, 420, 1442, 1101, 421613, 42161, 122, 123],
NON_ETH_CHAINS: [137, 80001, 56, 97, 10, 420, 1442, 1101, 421613, 42161, 122, 123,80085],
ETH_CHAINS: [1, 11155111]
};

Expand Down
62 changes: 60 additions & 2 deletions packages/restapi/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,31 @@ import {
fuse,
fuseSparknet,
} from 'viem/chains';
import { defineChain } from 'viem';
const { ENV } = Constants;

const berachainTestnet = defineChain({
id: 80085,
name: 'Berachain Artio',
network: 'berachain-testnet',
nativeCurrency: {
decimals: 18,
name: 'BERA Token',
symbol: 'BERA',
},
rpcUrls: {
default: { http: ['https://artio.rpc.berachain.com'] },
public: { http: ['https://artio.rpc.berachain.com'] },
},
blockExplorers: {
default: {
name: 'Berachain',
url: 'https://artio.beratrail.io',
},
},
testnet: true,
});

// for methods not needing the entire config
export const API_BASE_URL = {
[ENV.PROD]: 'https://backend.epns.io/apis',
Expand Down Expand Up @@ -47,6 +70,7 @@ const BLOCKCHAIN_NETWORK = {
ARBITRUMONE_MAINNET: 'eip155:42161',
FUSE_TESTNET: 'eip155:123',
FUSE_MAINNET: 'eip155:122',
BERACHAIN_TESTNET: 'eip155:80085',
};

export type ALIAS_CHAIN =
Expand All @@ -55,7 +79,8 @@ export type ALIAS_CHAIN =
| 'OPTIMISM'
| 'POLYGONZKEVM'
| 'ARBITRUMONE'
| 'FUSE';
| 'FUSE'
| 'BERACHAIN';

export const ETH_CHAIN_ID = {
[ENV.PROD]: 1,
Expand Down Expand Up @@ -100,6 +125,11 @@ export const ALIAS_CHAIN_ID = {
[ENV.DEV]: 123,
[ENV.LOCAL]: 123,
},
BERACHAIN: {
[ENV.STAGING]: 80085,
[ENV.DEV]: 80085,
[ENV.LOCAL]: 80085,
},
};

export const CHAIN_ID = {
Expand Down Expand Up @@ -129,6 +159,8 @@ export const CHAIN_NAME: { [key: number]: string } = {
// fuse
122: 'FUSE',
123: 'FUSE',
// berachain
80085: 'BERACHAIN',
};
export interface ConfigType {
API_BASE_URL: string;
Expand Down Expand Up @@ -237,6 +269,10 @@ const CONFIG = {
API_BASE_URL: API_BASE_URL[ENV.STAGING],
EPNS_COMMUNICATOR_CONTRACT: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa',
},
[BLOCKCHAIN_NETWORK.BERACHAIN_TESTNET]: {
API_BASE_URL: API_BASE_URL[ENV.STAGING],
EPNS_COMMUNICATOR_CONTRACT: '0x7b9C405e261ba671f008c20D0321f62d08C140EC',
},
},
[ENV.DEV]: {
[BLOCKCHAIN_NETWORK.ETH_SEPOLIA]: {
Expand Down Expand Up @@ -267,6 +303,10 @@ const CONFIG = {
API_BASE_URL: API_BASE_URL[ENV.DEV],
EPNS_COMMUNICATOR_CONTRACT: '0x7eBb54D86CF928115965DB596a3E600404dD8039',
},
[BLOCKCHAIN_NETWORK.BERACHAIN_TESTNET]: {
API_BASE_URL: API_BASE_URL[ENV.DEV],
EPNS_COMMUNICATOR_CONTRACT: '0xA1DF3E68D085aa6918bcc2506b24e499830Db0eB',
},
},
[ENV.LOCAL]: {
[BLOCKCHAIN_NETWORK.ETH_SEPOLIA]: {
Expand Down Expand Up @@ -297,6 +337,10 @@ const CONFIG = {
API_BASE_URL: API_BASE_URL[ENV.LOCAL],
EPNS_COMMUNICATOR_CONTRACT: '0x7eBb54D86CF928115965DB596a3E600404dD8039',
},
[BLOCKCHAIN_NETWORK.BERACHAIN_TESTNET]: {
API_BASE_URL: API_BASE_URL[ENV.LOCAL],
EPNS_COMMUNICATOR_CONTRACT: '0xA1DF3E68D085aa6918bcc2506b24e499830Db0eB',
},
},
};

Expand Down Expand Up @@ -406,6 +450,11 @@ export const VIEM_CONFIG = {
API_BASE_URL: API_BASE_URL[ENV.STAGING],
EPNS_COMMUNICATOR_CONTRACT: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa',
},
[BLOCKCHAIN_NETWORK.BERACHAIN_TESTNET]: {
NETWORK: berachainTestnet,
API_BASE_URL: API_BASE_URL[ENV.STAGING],
EPNS_COMMUNICATOR_CONTRACT: '0x7b9C405e261ba671f008c20D0321f62d08C140EC',
},
},
[ENV.DEV]: {
[BLOCKCHAIN_NETWORK.ETH_SEPOLIA]: {
Expand Down Expand Up @@ -443,6 +492,11 @@ export const VIEM_CONFIG = {
API_BASE_URL: API_BASE_URL[ENV.DEV],
EPNS_COMMUNICATOR_CONTRACT: '0x7eBb54D86CF928115965DB596a3E600404dD8039',
},
[BLOCKCHAIN_NETWORK.BERACHAIN_TESTNET]: {
NETWORK: berachainTestnet,
API_BASE_URL: API_BASE_URL[ENV.DEV],
EPNS_COMMUNICATOR_CONTRACT: '0xA1DF3E68D085aa6918bcc2506b24e499830Db0eB',
},
},
[ENV.LOCAL]: {
[BLOCKCHAIN_NETWORK.ETH_SEPOLIA]: {
Expand Down Expand Up @@ -480,10 +534,14 @@ export const VIEM_CONFIG = {
API_BASE_URL: API_BASE_URL[ENV.LOCAL],
EPNS_COMMUNICATOR_CONTRACT: '0x7eBb54D86CF928115965DB596a3E600404dD8039',
},
[BLOCKCHAIN_NETWORK.BERACHAIN_TESTNET]: {
NETWORK: berachainTestnet,
API_BASE_URL: API_BASE_URL[ENV.LOCAL],
EPNS_COMMUNICATOR_CONTRACT: '0xA1DF3E68D085aa6918bcc2506b24e499830Db0eB',
},
},
};


export const ALPHA_FEATURE_CONFIG = {
STABLE: {
feature: [] as string[],
Expand Down
4 changes: 3 additions & 1 deletion packages/restapi/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ const Constants = {
},
DEFAULT_CHAIN_ID: 11155111,
DEV_CHAIN_ID: 99999,
NON_ETH_CHAINS: [137, 80001, 56, 97, 10, 420, 1442, 1101, 421613, 42161, 122, 123],
NON_ETH_CHAINS: [
137, 80001, 56, 97, 10, 420, 1442, 1101, 421613, 42161, 122, 123, 80085,
],
ETH_CHAINS: [1, 11155111],
ENC_TYPE_V1: 'x25519-xsalsa20-poly1305',
ENC_TYPE_V2: 'aes256GcmHkdfSha256',
Expand Down
4 changes: 3 additions & 1 deletion packages/restapi/src/lib/payloads/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const CHAIN_ID_TO_SOURCE: ChainIdToSourceType = {
421613: "ARBITRUM_TESTNET",
42161: "ARBITRUMONE_MAINNET",
122: "FUSE_MAINNET",
123: "FUSE_TESTNET"
123: "FUSE_TESTNET",
80085: "BERACHAIN_TESTNET"
};

export const SOURCE_TYPES = {
Expand All @@ -34,6 +35,7 @@ export const SOURCE_TYPES = {
ARBITRUMONE_MAINNET: "ARBITRUMONE_MAINNET",
FUSE_TESTNET:"FUSE_TESTNET",
FUSE_MAINNET:"FUSE_MAINNET",
BERACHAIN_TESTNET: "BERACHAIN_TESTNET",
THE_GRAPH: 'THE_GRAPH',
PUSH_VIDEO: 'PUSH_VIDEO',
SIMULATE: 'SIMULATE'
Expand Down
9 changes: 6 additions & 3 deletions packages/restapi/src/lib/payloads/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export async function getVerificationProof({
wallet,
pgpPrivateKey,
env,
rules
rules,
}: {
senderType: 0 | 1;
signer: any;
Expand All @@ -212,7 +212,7 @@ export async function getVerificationProof({
wallet?: walletType;
pgpPrivateKey?: string;
env?: ENV;
rules?:VideoNotificationRules;
rules?: VideoNotificationRules;
}) {
let message = null;
let verificationProof = null;
Expand Down Expand Up @@ -328,7 +328,10 @@ export function getSource(
export function getCAIPFormat(chainId: number, address: string) {
// EVM based chains
if (
[1, 11155111, 42, 137, 80001, 56, 97, 10, 420, 1442, 1101, 421613, 42161, 122, 123].includes(chainId)
[
1, 11155111, 42, 137, 80001, 56, 97, 10, 420, 1442, 1101, 421613, 42161,
122, 123, 80085,
].includes(chainId)
) {
return `eip155:${chainId}:${address}`;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/restapi/tests/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# ENVIRONMENT | 'STAGING' or 'PROD' or 'DEV'
ENV=env_name

## CHANNEL WITH ALIAS
BERACHAIN_CHANNEL_PRIVATE_KEY=

WALLET_PRIVATE_KEY=your_wallet_private_key
WALLET_PRIVATE_KEY_2=your_wallet_private_key_2
WALLET_RECIPIENT_PK=your_wallet_recipient_pk
Expand Down
86 changes: 86 additions & 0 deletions packages/restapi/tests/lib/alias/berachain.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import * as path from 'path';
import * as dotenv from 'dotenv';
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
import * as PUSH_CHANNELS from '../../../src/lib/channels';
import { expect } from 'chai';
import { ethers } from 'ethers';
import { PushAPI, user } from '../../../src';
import { ENV } from '../../../src/lib/constants';

describe('ALIAS functionality', () => {
let userAlice: PushAPI;
let userBob: PushAPI;
let account: string;
let account2: string;
before(async () => {
const provider = new ethers.providers.JsonRpcProvider(
'https://artio.rpc.berachain.com' // berachain artio Provider
);
const signer = new ethers.Wallet(
`0x${process.env['BERACHAIN_CHANNEL_PRIVATE_KEY']}`,
provider
);
account = signer.address;
userAlice = await PushAPI.initialize(signer, {
env: ENV.DEV,
});

const signer2 = new ethers.Wallet(ethers.Wallet.createRandom().privateKey);
account2 = signer2.address;
userBob = await PushAPI.initialize(signer2, { env: ENV.DEV });
});

it.skip('Should be able to create channel', async () => {
const channelInfo = await userAlice.channel.info();
if (channelInfo) return; // skip if already exists
const res = await userAlice.channel.create({
name: 'SDK Alias Test',
description: 'Testing using sdk',
url: 'https://push.org',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAz0lEQVR4AcXBsU0EQQyG0e+saWJ7oACiKYDMEZVs6GgSpC2BIhzRwAS0sgk9HKn3gpFOAv3v3V4/3+4U4Z1q5KTy42Ql940qvFONnFSGmCFmiN2+fj7uCBlihpgh1ngwcvKfwjuVIWaIGWKNB+GdauSk8uNkJfeNKryzYogZYoZY40m5b/wlQ8wQM8TayMlKeKcaOVkJ71QjJyuGmCFmiDUe+HFy4VyEd57hx0mV+0ZliBlihlgL71w4FyMnVXhnZeSkiu93qheuDDFDzBD7BcCyMAOfy204AAAAAElFTkSuQmCC',
alias: `eip155:80085:${account}`,
progressHook: (progress: any) => console.log(progress),
});
console.log(res);
});

it('Should be able to send notifications', async () => {
await userAlice.channel.send(['*'], {
notification: {
title: 'hi',
body: 'test-broadcast',
},
payload: {
title: 'testing broadcast notification',
body: 'testing with random body',
cta: 'https://google.com/',
embed: 'https://avatars.githubusercontent.com/u/64157541?s=200&v=4',
},
channel: `eip155:80085:${account}`,
});
});

it('Should be able to add delegatee', async () => {
await userAlice.channel.delegate.add(account2);
});

it('Should be able to send notifications from delegate', async () => {
await userBob.channel.send(['*'], {
notification: {
title: 'hi',
body: 'test-broadcast',
},
payload: {
title: 'testing broadcast notification',
body: 'testing with random body',
cta: 'https://google.com/',
embed: 'https://avatars.githubusercontent.com/u/64157541?s=200&v=4',
},
channel: `eip155:80085:${account}`,
});
});

it('Should be able to remove delegatee', async () => {
await userAlice.channel.delegate.remove(account2);
});
});
2 changes: 1 addition & 1 deletion packages/uiweb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ where
| cta | string | Call To Action Link (given during notification creation) |
| image | string | Any media link (given during notification creation) |
| url | string | Channel Link (given during channel setup) |
| chainName | string | Can be anyone of the following blockchain networks on which the notification was sent - "ETH_MAINNET", "ETH_TEST_SEPOLIA", "POLYGON_MAINNET", "POLYGON_TEST_MUMBAI", "BSC_MAINNET, "BSC_TESTNET", "OPTIMISM_MAINNET", "OPTIMISM_TESTNET", "POLYGON_ZK_EVM_TESTNET", "POLYGON_ZK_EVM_MAINNET", "ARBITRUM_TESTNET", "ARBITRUMONE_MAINNET", "FUSE_TESTNET", "FUSE_MAINNET", "THE_GRAPH" |
| chainName | string | Can be anyone of the following blockchain networks on which the notification was sent - "ETH_MAINNET", "ETH_TEST_SEPOLIA", "POLYGON_MAINNET", "POLYGON_TEST_MUMBAI", "BSC_MAINNET, "BSC_TESTNET", "OPTIMISM_MAINNET", "OPTIMISM_TESTNET", "POLYGON_ZK_EVM_TESTNET", "POLYGON_ZK_EVM_MAINNET", "ARBITRUM_TESTNET", "ARBITRUMONE_MAINNET", "FUSE_TESTNET", "FUSE_MAINNET", "BERACHIAN_TESTNET", "THE_GRAPH" |
| theme | string | 'light' or 'dark' (customization to be given by the dApp) |
| customTheme | INotificationItemTheme | custom theme object for the component |
| isSpam | boolean | whether a spam notification or not |
Expand Down
Loading

0 comments on commit 7c569ee

Please sign in to comment.