Skip to content

Commit

Permalink
Merge pull request #463 from skalenetwork/move-paymaster-to-skale-con…
Browse files Browse the repository at this point in the history
…tracts

Move paymaster to skale contracts
  • Loading branch information
dmytrotkk authored Feb 21, 2025
2 parents 2b82a3d + 378c901 commit f48bc8a
Show file tree
Hide file tree
Showing 39 changed files with 355 additions and 328 deletions.
16 changes: 13 additions & 3 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@mui/icons-material": "^5.15.14",
"@mui/material": "^5.15.14",
"@skalenetwork/metaport": "file:packages/metaport",
"@skalenetwork/skale-contracts-ethers-v6": "1.0.1",
"@skalenetwork/skale-contracts-ethers-v6": "1.0.2-develop.54",
"@transak/transak-sdk": "^3.1.1",
"@types/react-copy-to-clipboard": "^5.0.4",
"@vercel/analytics": "^1.0.2",
Expand Down Expand Up @@ -624,9 +624,9 @@

"@skalenetwork/metaport": ["@skalenetwork/metaport@file:packages/metaport", { "dependencies": { "@/core": "file:../core", "@emotion/react": "^11.11.1", "@emotion/styled": "^11.11.0", "@mui/icons-material": "^5.15.6", "@mui/lab": "^5.0.0-alpha.162", "@mui/material": "^5.15.6", "@rainbow-me/rainbowkit": "^2.2.1", "@skalenetwork/ima-js": "2.0.2-develop.0", "@tanstack/react-query": "^5.54.1", "@web3icons/core": "^3.15.0", "@web3icons/react": "^3.15.0", "coingecko-api-v3": "^0.0.29", "react-jazzicon": "^1.0.4", "viem": "2.21.54", "wagmi": "^2.13.3", "zustand": "^4.5.0" }, "devDependencies": { "@storybook/addon-essentials": "^7.6.10", "@storybook/addon-interactions": "^7.6.10", "@storybook/addon-links": "^7.6.10", "@storybook/addon-styling": "1.3.7", "@storybook/blocks": "^7.6.10", "@storybook/react": "^7.6.10", "@storybook/react-vite": "^7.6.10", "@storybook/testing-library": "0.2.0", "@testing-library/react": "14.0.0", "@types/node": "20.4.9", "@types/react": "18.2.20", "@types/react-dom": "18.2.7", "@typescript-eslint/eslint-plugin": "5.60.0", "@vitejs/plugin-react": "4.0.4", "@vitest/coverage-v8": "0.34.1", "ajv": "^8.17.1", "autoprefixer": "10.4.14", "eslint": "8.46.0", "eslint-config-prettier": "9.0.0", "eslint-config-standard-with-typescript": "37.0.0", "eslint-plugin-import": "2.28.0", "eslint-plugin-n": "16.0.1", "eslint-plugin-promise": "6.1.1", "eslint-plugin-react": "7.33.1", "eslint-plugin-storybook": "0.6.13", "jsdom": "22.1.0", "json": "11.0.0", "lint-staged": "13.2.3", "postcss": "8.4.27", "prettier": "3.0.1", "prop-types": "15.8.1", "react": "^18.2.0", "react-dom": "^18.2.0", "sass": "^1.65.1", "storybook": "^7.6.10", "typescript": "5.1.6", "vite": "4.4.9", "vite-plugin-dts": "3.5.1", "vite-plugin-sass-dts": "^1.3.9", "vitest": "0.34.1" }, "peerDependencies": { "react": "18.2.0", "react-dom": "18.2.0" } }],

"@skalenetwork/skale-contracts": ["@skalenetwork/[email protected].1", "", { "dependencies": { "@renovatebot/pep440": "^3.0.20", "axios": "^1.4.0", "semver": "^7.6.0" } }, "sha512-Wqi6zKPdfcsQGQVoSv0S0ojQMKFKx2abrsX3IT7r11beLuOJ/C7wcSIikJhpeS0p4SQdU30EM+iZOKPAOgVvWQ=="],
"@skalenetwork/skale-contracts": ["@skalenetwork/[email protected].2-develop.54", "", { "dependencies": { "@renovatebot/pep440": "^3.0.20", "axios": "^1.4.0", "semver": "^7.6.0" } }, "sha512-33uMQ0NH4acA3CKx9LUcV7jSPb5xcVeGVFmjW6BijMwYo7CBvFkNR7cOBYywiwLvyr7hJ2W9uo6wYBtccr2zeA=="],

"@skalenetwork/skale-contracts-ethers-v6": ["@skalenetwork/[email protected].1", "", { "dependencies": { "@skalenetwork/skale-contracts": "1.0.1", "ethers": "^6.7.1" } }, "sha512-dWAWY6xBb8E5HVukZXftFi2uxsPbzRMt1WfK/nUpmO5c/4uiDjeX13xxeafYCFE8JX+n9qy4iatSoHFvvv8h4w=="],
"@skalenetwork/skale-contracts-ethers-v6": ["@skalenetwork/[email protected].2-develop.54", "", { "dependencies": { "@skalenetwork/skale-contracts": "1.0.2-develop.54", "ethers": "^6.13.5" } }, "sha512-obLEQ6X+oBQYwWKfb5ZtiuH83B3v9TnEzZHsPqac1RHNJu9289yUHkgdGZTT7ISo6iyx6eauu7CQlYnWmfPSAA=="],

"@socket.io/component-emitter": ["@socket.io/[email protected]", "", {}, "sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA=="],

Expand Down Expand Up @@ -3244,6 +3244,8 @@

"@skalenetwork/metaport/vite": ["[email protected]", "", { "dependencies": { "esbuild": "^0.18.10", "postcss": "^8.4.27", "rollup": "^3.27.1" }, "optionalDependencies": { "fsevents": "~2.3.2" }, "peerDependencies": { "@types/node": ">= 14", "less": "*", "lightningcss": "^1.21.0", "sass": "*", "stylus": "*", "sugarss": "*", "terser": "^5.4.0" }, "optionalPeers": ["@types/node", "less", "lightningcss", "sass", "stylus", "sugarss", "terser"], "bin": { "vite": "bin/vite.js" } }, "sha512-2mbUn2LlUmNASWwSCNSJ/EG2HuSRTnVNaydp6vMCm5VIqJsjMfbIWtbH2kDuwUVW5mMUKKZvGPX/rqeqVvv1XA=="],

"@skalenetwork/skale-contracts-ethers-v6/ethers": ["[email protected]", "", { "dependencies": { "@adraffy/ens-normalize": "1.10.1", "@noble/curves": "1.2.0", "@noble/hashes": "1.3.2", "@types/node": "22.7.5", "aes-js": "4.0.0-beta.5", "tslib": "2.7.0", "ws": "8.17.1" } }, "sha512-+knKNieu5EKRThQJWwqaJ10a6HE9sSehGeqWN65//wE7j47ZpFhKAnHB/JJFibwwg61I/koxaPsXbXpD/skNOQ=="],

"@spruceid/siwe-parser/@noble/hashes": ["@noble/[email protected]", "", {}, "sha512-pq5D8h10hHBjyqX+cfBm0i8JUXJ0UhczFc4r74zbuT9XgewFo2E3J1cOaGtdZynILNmQ685YWGzGE1Zv6io50w=="],

"@storybook/addon-styling/prettier": ["[email protected]", "", { "bin": { "prettier": "bin-prettier.js" } }, "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q=="],
Expand Down Expand Up @@ -3726,6 +3728,12 @@

"@skalenetwork/metaport/vite/postcss": ["[email protected]", "", { "dependencies": { "nanoid": "^3.3.8", "picocolors": "^1.1.1", "source-map-js": "^1.2.1" } }, "sha512-6oz2beyjc5VMn/KV1pPw8fliQkhBXrVn1Z3TVyqZxU8kZpzEKhBdmCFqI6ZbmGtamQvQGuU1sgPTk8ZrXDD7jQ=="],

"@skalenetwork/skale-contracts-ethers-v6/ethers/@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~6.19.2" } }, "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ=="],

"@skalenetwork/skale-contracts-ethers-v6/ethers/tslib": ["[email protected]", "", {}, "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA=="],

"@skalenetwork/skale-contracts-ethers-v6/ethers/ws": ["[email protected]", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ=="],

"@storybook/api/@storybook/manager-api/@storybook/channels": ["@storybook/[email protected]", "", { "dependencies": { "@storybook/client-logger": "7.6.17", "@storybook/core-events": "7.6.17", "@storybook/global": "^5.0.0", "qs": "^6.10.0", "telejson": "^7.2.0", "tiny-invariant": "^1.3.1" } }, "sha512-GFG40pzaSxk1hUr/J/TMqW5AFDDPUSu+HkeE/oqSWJbOodBOLJzHN6CReJS6y1DjYSZLNFt1jftPWZZInG/XUA=="],

"@storybook/api/@storybook/manager-api/@storybook/core-events": ["@storybook/[email protected]", "", { "dependencies": { "ts-dedent": "^2.0.0" } }, "sha512-AriWMCm/k1cxlv10f+jZ1wavThTRpLaN3kY019kHWbYT9XgaSuLU67G7GPr3cGnJ6HuA6uhbzu8qtqVCd6OfXA=="],
Expand Down Expand Up @@ -4008,6 +4016,8 @@

"@skalenetwork/metaport/eslint-config-standard-with-typescript/@typescript-eslint/parser/@typescript-eslint/typescript-estree": ["@typescript-eslint/[email protected]", "", { "dependencies": { "@typescript-eslint/types": "5.62.0", "@typescript-eslint/visitor-keys": "5.62.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", "semver": "^7.3.7", "tsutils": "^3.21.0" } }, "sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA=="],

"@skalenetwork/skale-contracts-ethers-v6/ethers/@types/node/undici-types": ["[email protected]", "", {}, "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw=="],

"@storybook/cli/execa/onetime/mimic-fn": ["[email protected]", "", {}, "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg=="],

"detect-package-manager/execa/onetime/mimic-fn": ["[email protected]", "", {}, "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg=="],
Expand Down
2 changes: 1 addition & 1 deletion config/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const METAPORT_CONFIG: types.mp.Config = {
symbol: 'ETH'
},
skl: {
decimals: '18',
decimals: 18,
name: 'SKALE',
symbol: 'SKL'
}
Expand Down
16 changes: 8 additions & 8 deletions config/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ export const METAPORT_CONFIG: types.mp.Config = {
symbol: 'ETH'
},
skl: {
decimals: '18',
decimals: 18,
name: 'SKALE',
symbol: 'SKL'
},
usdc: {
decimals: '6',
decimals: 6,
symbol: 'USDC',
name: 'USD Coin'
},
usdt: {
decimals: '6',
decimals: 6,
symbol: 'USDT',
name: 'Tether USD'
},
wbtc: {
decimals: '8',
decimals: 8,
symbol: 'WBTC',
name: 'WBTC'
},
Expand All @@ -67,7 +67,7 @@ export const METAPORT_CONFIG: types.mp.Config = {
iconUrl: 'https://s2.coinmarketcap.com/static/img/coins/64x64/10347.png'
},
razor: {
decimals: '18',
decimals: 18,
name: 'RAZOR Network',
symbol: 'RAZOR',
iconUrl: 'https://assets.coingecko.com/coins/images/13797/small/icon.png'
Expand All @@ -93,7 +93,7 @@ export const METAPORT_CONFIG: types.mp.Config = {
},
hmkr: {
name: 'Hitmakr',
decimals: '9',
decimals: 9,
symbol: 'HMKR',
iconUrl: 'https://assets.coingecko.com/coins/images/36660/standard/HITMAKR_logo.png'
},
Expand Down Expand Up @@ -121,7 +121,7 @@ export const METAPORT_CONFIG: types.mp.Config = {
name: 'Wrapped Car Token 1',
symbol: 'wCT1',
iconUrl: 'https://s2.coinmarketcap.com/static/img/coins/64x64/12648.png',
decimals: '2'
decimals: 2
},
flag: {
name: 'FLAG',
Expand All @@ -136,7 +136,7 @@ export const METAPORT_CONFIG: types.mp.Config = {
skivvy: {
name: 'Skivvy',
symbol: 'SKIVVY',
decimals: '8',
decimals: 8,
iconUrl: 'https://s2.coinmarketcap.com/static/img/coins/64x64/3441.png'
}
},
Expand Down
10 changes: 5 additions & 5 deletions config/testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ export const METAPORT_CONFIG: types.mp.Config = {
symbol: 'ETH'
},
skl: {
decimals: '18',
decimals: 18,
name: 'SKALE',
symbol: 'SKL'
},
usdc: {
decimals: '6',
decimals: 6,
symbol: 'USDC',
name: 'USD Coin'
},
usdt: {
decimals: '6',
decimals: 6,
symbol: 'USDT',
name: 'Tether USD'
},
wbtc: {
decimals: '8',
decimals: 8,
symbol: 'WBTC',
name: 'WBTC'
},
Expand All @@ -59,7 +59,7 @@ export const METAPORT_CONFIG: types.mp.Config = {
ubxs: {
name: 'UBXS Token',
symbol: 'UBXS',
decimals: '6',
decimals: 6,
iconUrl: 'https://s2.coinmarketcap.com/static/img/coins/64x64/17242.png'
},
trc: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"react-social-icons": "^6.17.0",
"react-transition-group": "^4.4.5",
"siwe": "^2.3.2",
"@skalenetwork/skale-contracts-ethers-v6": "1.0.1"
"@skalenetwork/skale-contracts-ethers-v6": "1.0.2-develop.54"
},
"devDependencies": {
"@types/react": "^18.2.15",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

const MS_MULTIPLIER = 1000

export const DEFAULT_ERC20_DECIMALS = '18'
export const DEFAULT_ERC20_DECIMALS = 18
export const USDC_DECIMALS = '6'

export const DEFAULT_MP_Z_INDEX = 99000
Expand Down
24 changes: 24 additions & 0 deletions packages/core/src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,30 @@ export const CONTRACTS: ContractsConfig = {
}
}

export const PAYMASTER_CONTRACTS = {
mainnet: {
chain: 'elated-tan-skat',
address: '0x0d66cA00CbAD4219734D7FDF921dD7Caadc1F78D'
},
staging: {
chain: 'staging-legal-crazy-castor',
address: '0x9E444978d11E7e753017ce3329B01663D5D78240'
},
legacy: {
chain: 'adorable-quaint-bellatrix',
address: '0xb76A448071Ed77d22cAa1669567B5D28f5448d99'
},
regression: {
chain: '',
address: '0x'
},
testnet: {
chain: '',
address: '0x'

}
}

export function getAliasOrAddress(
skaleNetwork: types.SkaleNetwork,
projectName: IPortalProject
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@ export function roundUp(num: number, decimals: number = constants.ROUNDING_DECIM
const factor = Math.pow(10, decimals)
return Math.round(num * factor) / factor
}

export function divideBigInts(a: bigint, b: bigint): number {
return Number((a * 10000n) / b) / 10000
}
1 change: 1 addition & 0 deletions packages/core/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export {
} from './ChainsMetadata'
export * as st from './staking'
export * as mp from './metaport'
export * as pm from './paymaster'

export type AddressType = `0x${string}`
export type Size = 'xs' | 'sm' | 'md' | 'lg'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/metaport/TokenMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface TokenMetadata {
symbol: string
name?: string
iconUrl?: string
decimals?: string
decimals?: number
}

export interface TokenMetadataMap {
Expand Down
35 changes: 35 additions & 0 deletions packages/core/src/types/paymaster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license
* SKALE portal
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* @file paymaster.ts
* @copyright SKALE Labs 2025-Present
*/

export interface PaymasterInfo {
maxReplenishmentPeriod: bigint
oneSklPrice: bigint
schainPricePerMonth: bigint
skaleToken: string
schain: {
name: string
paidUntil: bigint
}
effectiveTimestamp?: bigint
}

export type DueDateStatus = 'primary' | 'warning' | 'error' | 'success'
30 changes: 23 additions & 7 deletions packages/core/src/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,40 @@
*/

import { formatUnits, parseUnits, BigNumberish } from 'ethers'
import { DEFAULT_ERC20_DECIMALS } from './constants'
import { DEFAULT_ERC20_DECIMALS, DEFAULT_FRACTION_DIGITS } from './constants'


export function toWei(value: string, decimals: string): bigint {
return parseUnits(value, parseInt(decimals as string))
export function toWei(value: string, decimals: number): bigint {
return parseUnits(value, decimals)
}

export function fromWei(value: BigNumberish, decimals: string): string {
return formatUnits(value, parseInt(decimals as string))
export function fromWei(value: BigNumberish, decimals: number): string {
return formatUnits(value, decimals)
}

export function formatBalance(balance: bigint, decimals?: string): string {
export function formatBalance(balance: bigint, decimals?: number): string {
const tokenDecimals = decimals ?? DEFAULT_ERC20_DECIMALS
return formatUnits(balance, parseInt(tokenDecimals))
return formatUnits(balance, tokenDecimals)
}

export function truncateDecimals(input: string, numDecimals: number): string {
const delimiter = input.includes(',') ? ',' : '.'
const [integerPart, decimalPart = ''] = input.split(delimiter)
return `${integerPart}${delimiter}${decimalPart.slice(0, numDecimals)}`
}

export function displayBalance(
value: bigint,
tokenSymbol?: string,
customDecimals?: number
): string {
const res = Number(
truncateDecimals(
fromWei(value, customDecimals ?? DEFAULT_ERC20_DECIMALS),
DEFAULT_FRACTION_DIGITS
)
).toLocaleString(undefined, {
maximumFractionDigits: DEFAULT_FRACTION_DIGITS
})
return res + (tokenSymbol ? ` ${tokenSymbol}` : '')
}
Loading

0 comments on commit f48bc8a

Please sign in to comment.