Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Polygon zkEvm Cardona support #1243

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# dependencies
node_modules
.yarn

# IDEs and editors
/.idea
Expand Down
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 @@ -17,7 +17,7 @@ const NETWORK_MAPPING: NwMappingType = {
97: 'BSC_TESTNET',
11155420: 'OPTIMISM_TESTNET',
10: 'OPTIMISM_MAINNET',
1442: 'POLYGON_ZK_EVM_TESTNET',
2442: 'POLYGON_ZK_EVM_TESTNET',
1101: 'POLYGON_ZK_EVM_MAINNET',
421614: 'ARBITRUM_TESTNET',
42161: 'ARBITRUMONE_MAINNET',
Expand All @@ -28,7 +28,7 @@ const NETWORK_MAPPING: NwMappingType = {

const injected = new InjectedConnector({
supportedChainIds: [
1, 3, 4, 11155111, 42, 137, 80002, 56, 97, 10, 11155420, 1442, 1101, 421614,
1, 3, 4, 11155111, 42, 137, 80002, 56, 97, 10, 11155420, 2442, 1101, 421614,
42161, 122, 123, 80085,
],
});
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 @@ -19,7 +19,7 @@ const Constants = {
DEFAULT_CHAIN_ID: 11155111,
DEV_CHAIN_ID: 99999,
NON_ETH_CHAINS: [
137, 80002, 56, 97, 10, 11155420, 1442, 1101, 421614, 42161, 122, 123,
137, 80002, 56, 97, 10, 11155420, 2442, 1101, 421614, 42161, 122, 123,
80085,
],
ETH_CHAINS: [1, 11155111],
Expand Down
334 changes: 327 additions & 7 deletions packages/restapi/CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/restapi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pushprotocol/restapi",
"version": "1.7.6",
"version": "0.0.1-alpha.84",
"type": "commonjs",
"publishConfig": {
"registry": "https://registry.npmjs.org/"
Expand Down
51 changes: 36 additions & 15 deletions packages/restapi/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
optimism,
optimismSepolia,
polygonZkEvm,
polygonZkEvmTestnet,
sepolia,
arbitrum,
arbitrumSepolia,
Expand All @@ -19,6 +18,28 @@ import {
} from 'viem/chains';
import { defineChain } from 'viem';

const polygonZkEvmCordona = defineChain({
id: 2442,
name: 'Polygon zkEVM Cardona Testnet',
network: 'polygon-zkevm-testnet',
nativeCurrency: {
decimals: 18,
name: 'ETH',
symbol: 'ETH',
},
rpcUrls: {
default: { http: ['https://rpc.cardona.zkevm-rpc.com/'] },
public: { http: ['https://rpc.cardona.zkevm-rpc.com/'] },
},
blockExplorers: {
default: {
name: 'Polygon zkEVM Cardona',
url: ' https://cardona-zkevm.polygonscan.com/',
},
},
testnet: true,
})

const polygonAmoy = defineChain({
id: 80002,
name: 'Polygon Amoy Testnet',
Expand Down Expand Up @@ -86,7 +107,7 @@ const BLOCKCHAIN_NETWORK = {
BSC_TESTNET: 'eip155:97',
OPTIMISM_TESTNET: 'eip155:11155420',
OPTIMISM_MAINNET: 'eip155:10',
POLYGON_ZK_EVM_TESTNET: 'eip155:1442',
POLYGON_ZK_EVM_TESTNET: 'eip155:2442',
POLYGON_ZK_EVM_MAINNET: 'eip155:1101',
ARBITRUM_TESTNET: 'eip155:421614',
ARBITRUMONE_MAINNET: 'eip155:42161',
Expand Down Expand Up @@ -133,9 +154,9 @@ export const ALIAS_CHAIN_ID: {
},
POLYGONZKEVM: {
[ENV.PROD]: 1101,
[ENV.STAGING]: 1442,
[ENV.DEV]: 1442,
[ENV.LOCAL]: 1442,
[ENV.STAGING]: 2442,
[ENV.DEV]: 2442,
[ENV.LOCAL]: 2442,
},
ARBITRUMONE: {
[ENV.PROD]: 42161,
Expand Down Expand Up @@ -177,7 +198,7 @@ export const CHAIN_NAME: { [key: number]: string } = {
11155420: 'OPTIMISM',
// plygonzkevm
1101: 'POLYGONZKEVM',
1442: 'POLYGONZKEVM',
2442: 'POLYGONZKEVM',
// arbitrun
421614: 'ARBITRUN',
42161: 'ARBITRUM',
Expand Down Expand Up @@ -284,7 +305,7 @@ const CONFIG = {
},
[BLOCKCHAIN_NETWORK.POLYGON_ZK_EVM_TESTNET]: {
API_BASE_URL: API_BASE_URL[ENV.STAGING],
EPNS_COMMUNICATOR_CONTRACT: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa',
EPNS_COMMUNICATOR_CONTRACT: '0x6e489b7af21ceb969f49a90e481274966ce9d74d',
},
[BLOCKCHAIN_NETWORK.ARBITRUM_TESTNET]: {
API_BASE_URL: API_BASE_URL[ENV.STAGING],
Expand Down Expand Up @@ -318,7 +339,7 @@ const CONFIG = {
},
[BLOCKCHAIN_NETWORK.POLYGON_ZK_EVM_TESTNET]: {
API_BASE_URL: API_BASE_URL[ENV.DEV],
EPNS_COMMUNICATOR_CONTRACT: '0x630b152e4185c63D7177c656b56b26f878C61572',
EPNS_COMMUNICATOR_CONTRACT: '0x9cb3bd7550b5c92baa056fc0f08132f49508145f',
},
[BLOCKCHAIN_NETWORK.ARBITRUM_TESTNET]: {
API_BASE_URL: API_BASE_URL[ENV.DEV],
Expand Down Expand Up @@ -352,7 +373,7 @@ const CONFIG = {
},
[BLOCKCHAIN_NETWORK.POLYGON_ZK_EVM_TESTNET]: {
API_BASE_URL: API_BASE_URL[ENV.LOCAL],
EPNS_COMMUNICATOR_CONTRACT: '0x630b152e4185c63D7177c656b56b26f878C61572',
EPNS_COMMUNICATOR_CONTRACT: '0x9cb3bd7550b5c92baa056fc0f08132f49508145f',
},
[BLOCKCHAIN_NETWORK.ARBITRUM_TESTNET]: {
API_BASE_URL: API_BASE_URL[ENV.LOCAL],
Expand Down Expand Up @@ -461,9 +482,9 @@ export const VIEM_CONFIG = {
EPNS_COMMUNICATOR_CONTRACT: '0x9Dc25996ba72A2FD7E64e7a674232a683f406F1A',
},
[BLOCKCHAIN_NETWORK.POLYGON_ZK_EVM_TESTNET]: {
NETWORK: polygonZkEvmTestnet,
NETWORK: polygonZkEvmCordona,
API_BASE_URL: API_BASE_URL[ENV.STAGING],
EPNS_COMMUNICATOR_CONTRACT: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa',
EPNS_COMMUNICATOR_CONTRACT: '0x6e489b7af21ceb969f49a90e481274966ce9d74d',
},
[BLOCKCHAIN_NETWORK.ARBITRUM_TESTNET]: {
NETWORK: arbitrumSepolia,
Expand Down Expand Up @@ -503,9 +524,9 @@ export const VIEM_CONFIG = {
EPNS_COMMUNICATOR_CONTRACT: '0x754787358fac861ef904c92d54f7adb659779317',
},
[BLOCKCHAIN_NETWORK.POLYGON_ZK_EVM_TESTNET]: {
NETWORK: polygonZkEvmTestnet,
NETWORK: polygonZkEvmCordona,
API_BASE_URL: API_BASE_URL[ENV.DEV],
EPNS_COMMUNICATOR_CONTRACT: '0x630b152e4185c63D7177c656b56b26f878C61572',
EPNS_COMMUNICATOR_CONTRACT: '0x9cb3bd7550b5c92baa056fc0f08132f49508145f',
},
[BLOCKCHAIN_NETWORK.ARBITRUM_TESTNET]: {
NETWORK: arbitrumSepolia,
Expand Down Expand Up @@ -545,9 +566,9 @@ export const VIEM_CONFIG = {
EPNS_COMMUNICATOR_CONTRACT: '0x754787358fac861ef904c92d54f7adb659779317',
},
[BLOCKCHAIN_NETWORK.POLYGON_ZK_EVM_TESTNET]: {
NETWORK: polygonZkEvmTestnet,
NETWORK: polygonZkEvmCordona,
API_BASE_URL: API_BASE_URL[ENV.DEV],
EPNS_COMMUNICATOR_CONTRACT: '0x630b152e4185c63D7177c656b56b26f878C61572',
EPNS_COMMUNICATOR_CONTRACT: '0x9cb3bd7550b5c92baa056fc0f08132f49508145f',
},
[BLOCKCHAIN_NETWORK.ARBITRUM_TESTNET]: {
NETWORK: arbitrumSepolia,
Expand Down
2 changes: 1 addition & 1 deletion packages/restapi/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const Constants = {
DEFAULT_CHAIN_ID: 11155111,
DEV_CHAIN_ID: 99999,
NON_ETH_CHAINS: [
137, 80002, 56, 97, 10, 11155420, 1442, 1101, 421614, 42161, 122, 123,
137, 80002, 56, 97, 10, 11155420, 2442, 1101, 421614, 42161, 122, 123,
80085,
],
ETH_CHAINS: [1, 11155111],
Expand Down
2 changes: 1 addition & 1 deletion packages/restapi/src/lib/payloads/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const CHAIN_ID_TO_SOURCE: ChainIdToSourceType = {
97: 'BSC_TESTNET',
10: 'OPTIMISM_MAINNET',
11155420: 'OPTIMISM_TESTNET',
1442: 'POLYGON_ZK_EVM_TESTNET',
2442: 'POLYGON_ZK_EVM_TESTNET',
1101: 'POLYGON_ZK_EVM_MAINNET',
421614: "ARBITRUM_TESTNET",
42161: "ARBITRUMONE_MAINNET",
Expand Down
2 changes: 1 addition & 1 deletion packages/restapi/src/lib/payloads/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export function getCAIPFormat(chainId: number, address: string) {
// EVM based chains
if (
[
1, 11155111, 42, 137, 80002, 56, 97, 10, 11155420, 1442, 1101, 421614,
1, 11155111, 42, 137, 80002, 56, 97, 10, 11155420, 2442, 1101, 421614,
42161, 122, 123, 80085,
].includes(chainId)
) {
Expand Down
10 changes: 5 additions & 5 deletions packages/restapi/src/lib/pushapi/PushAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import { cache } from '../helpers/cache';
import { v4 as uuidv4 } from 'uuid';

export class PushAPI {
private signer?: SignerType;
public signer?: SignerType;
private readMode: boolean;
private alpha: { feature: string[] };
public account: string;
private decryptedPgpPvtKey?: string;
private pgpPublicKey?: string;
private env: ENV;
public decryptedPgpPvtKey?: string;
public pgpPublicKey?: string;
public env: ENV;
private progressHook?: (progress: ProgressHookType) => void;
private cache: LRUCache<string, any>;

Expand Down Expand Up @@ -118,7 +118,7 @@ export class PushAPI {
}
// Overloaded initialize method signatures
static async initialize(
signer?: SignerType,
signer?: SignerType | null,
options?: PushAPIInitializeProps
): Promise<PushAPI>;
static async initialize(options?: PushAPIInitializeProps): Promise<PushAPI>;
Expand Down
5 changes: 2 additions & 3 deletions packages/restapi/src/lib/pushapi/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ export class Chat {
};
try {
const chatInfo = await PUSH_CHAT.getChatInfo(request);
const finalRecipient = chatInfo.meta.group ? chatInfo.chatId : recipient;

const finalRecipient = chatInfo.meta?.group ? chatInfo.chatId : recipient;
const response: ChatInfoResponse = {
meta: chatInfo.meta,
list: chatInfo.list,
Expand Down Expand Up @@ -727,4 +726,4 @@ export class Chat {
});
},
};
}
}
1 change: 1 addition & 0 deletions packages/restapi/tests/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ BERACHAIN_CHANNEL_PRIVATE_KEY=your_berachain_channel_private_key
ARBITRUM_CHANNEL_PRIVATE_KEY=your_arbitrum_channel_private_key
OPTIMISM_CHANNEL_PRIVATE_KEY=your_optimism_channel_private_key
POLYGON_CHANNEL_PRIVATE_KEY=your_polygon_channel_private_key
POLYGON_ZKEVM_CHANNEL_PRIVATE_KEY=your_polygon_zkevm_channel_private_key

WALLET_PRIVATE_KEY=your_wallet_private_key
WALLET_PRIVATE_KEY_2=your_wallet_private_key_2
Expand Down
85 changes: 85 additions & 0 deletions packages/restapi/tests/lib/alias/polygonZkevm.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { ethers } from 'ethers';
import { PushAPI } from '../../../src';
import { ENV } from '../../../src/lib/constants';

describe.only('POLYGON ZKEVM ALIAS functionality', () => {
let userAlice: PushAPI;
let userBob: PushAPI;
let account: string;
let account2: string;

// accessing env dynamically using process.env
type EnvStrings = keyof typeof ENV;
const envMode = process.env.ENV as EnvStrings;
const _env = ENV[envMode];

before(async () => {
const provider = new ethers.providers.JsonRpcProvider(
'https://rpc.cardona.zkevm-rpc.com/'
);
const signer = new ethers.Wallet(
`0x${process.env['POLYGON_ZKEVM_CHANNEL_PRIVATE_KEY']}`,
provider
);
account = signer.address;
userAlice = await PushAPI.initialize(signer, {
env: _env,
});

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

it.skip('Should be able to create channel', async () => {
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:2442:${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:2442:${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:2442:${account}`,
});
});

it('Should be able to remove delegatee', async () => {
await userAlice.channel.delegate.remove(account2);
});
});
5 changes: 4 additions & 1 deletion packages/uiweb/src/lib/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const TESTNET_NETWORK = {
POLYGON: 'eip155:80002',
BSC: 'eip155:97',
OPTIMISM: 'eip155:11155420',
POLYGON_ZK_EVM: 'eip155:1442',
POLYGON_ZK_EVM: 'eip155:2442',
ARBITRUM: 'eip155:421614',
FUSE: 'eip155:123',
BERACHAIN: 'eip155:80085',
Expand Down Expand Up @@ -95,6 +95,7 @@ export const allowedNetworks = {
421614, // for arbitrum testnet
123, // for fuse testnet
80085, // for berachain testnet
2442 // polygon zkevm
],
staging: [
// 42, //for kovan
Expand All @@ -105,6 +106,7 @@ export const allowedNetworks = {
421614, // for arbitrum testnet
123, // for fuse testnet
80085, // for berachain testnet
2442 // polygon zkevm
],
local: [
11155111, // for eth sepolia
Expand All @@ -114,6 +116,7 @@ export const allowedNetworks = {
421614, // for arbitrum testnet
123, // for fuse testnet
80085, // for berachain testnet
2442 // polygon zkevm
],
};

Expand Down
Loading