Skip to content

Commit

Permalink
Merge pull request #29 from subsquid/develop
Browse files Browse the repository at this point in the history
release
  • Loading branch information
belopash authored Jun 6, 2024
2 parents 860536e + 95ecc9e commit 0a337b0
Show file tree
Hide file tree
Showing 55 changed files with 1,119 additions and 582 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"preview": "vite preview --outDir build --host 127.0.0.1 --port 3005",
"upg": "yarn upgrade-interactive",
"prepare": "husky install",
"codegen": "graphql-codegen --config src/api/subsquid-network-squid/graphql.config.js"
"codegen": "graphql-codegen --config src/api/subsquid-network-squid/graphql.config.ts"
},
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx}": "eslint --cache --fix"
Expand All @@ -30,12 +30,12 @@
"@types/ms": "^0.7.34",
"axios": "^1.6.8",
"base58-universal": "^2.0.0",
"bignumber.js": "^9.1.2",
"bs58": "^5.0.0",
"buffer": "^6.0.3",
"classnames": "^2.5.1",
"country-list": "^2.3.0",
"date-fns": "^3.6.0",
"decimal.js": "^10.4.3",
"ethers": "^6.11.1",
"formik": "^2.4.5",
"graphql": "^16.8.1",
Expand All @@ -51,6 +51,7 @@
"react-syntax-highlighter": "^15.5.0",
"recharts": "^2.12.3",
"semver": "^7.6.2",
"use-debounce": "^10.0.1",
"use-element-position": "^1.0.13",
"use-local-storage-state": "^19.2.0",
"viem": "^2.10.9",
Expand Down
3 changes: 2 additions & 1 deletion src/api/contracts/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { waitForTransactionReceipt } from 'viem/actions';
import { useWriteContract, useClient } from 'wagmi';

import { REWARD_TREASURY_CONTRACT_ABI } from '@api/contracts/reaward-treasury.abi';
import { errorMessage, TxResult, WriteContractRes } from '@api/contracts/utils';
import { VESTING_CONTRACT_ABI } from '@api/contracts/vesting.abi';
import { AccountType, SourceWallet } from '@api/subsquid-network-squid';
import { useSquidNetworkHeightHooks } from '@hooks/useSquidNetworkHeightHooks.ts';
import { useAccount } from '@network/useAccount.ts';
import { useContracts } from '@network/useContracts.ts';

import { TxResult, errorMessage, WriteContractRes } from './utils';

export type ClaimRequest = {
wallet: SourceWallet;
};
Expand Down
3 changes: 2 additions & 1 deletion src/api/contracts/gateway-registration/useRegisterGateway.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react';

import { peerIdToHex } from '@lib/network';
import { logger } from '@logger';
import { encodeFunctionData } from 'viem';
import { usePublicClient, useWriteContract } from 'wagmi';
Expand All @@ -9,7 +10,7 @@ import { useSquidNetworkHeightHooks } from '@hooks/useSquidNetworkHeightHooks.ts
import { useAccount } from '@network/useAccount';
import { useContracts } from '@network/useContracts.ts';

import { errorMessage, peerIdToHex, TxResult, WriteContractRes } from '../utils';
import { TxResult, errorMessage, WriteContractRes } from '../utils';
import { VESTING_CONTRACT_ABI } from '../vesting.abi';

import { encodeGatewayMetadata, GetawayMetadata } from './GatewayMetadata';
Expand Down
13 changes: 6 additions & 7 deletions src/api/contracts/gateway-registration/useStakeGateway.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useState } from 'react';

import { logger } from '@logger';
import Decimal from 'decimal.js';
import { encodeFunctionData } from 'viem';
import { usePublicClient, useWriteContract } from 'wagmi';

Expand All @@ -11,13 +10,13 @@ import { useAccount } from '@network/useAccount';
import { useContracts } from '@network/useContracts.ts';

import { useApproveSqd } from '../sqd';
import { errorMessage, isApproveRequiredError, toSqd, TxResult, WriteContractRes } from '../utils';
import { errorMessage, TxResult, isApproveRequiredError, WriteContractRes } from '../utils';
import { VESTING_CONTRACT_ABI } from '../vesting.abi';

import { GATEWAY_REGISTRATION_CONTRACT_ABI } from './GatewayRegistration.abi';

type StakeGatewayRequest = {
amount: number;
amount: string;
durationBlocks: number;
autoExtension: boolean;
wallet: SourceWallet;
Expand All @@ -40,7 +39,7 @@ function useStakeFromWallet() {
address: contracts.GATEWAY_REGISTRATION,
abi: GATEWAY_REGISTRATION_CONTRACT_ABI,
functionName: 'stake',
args: [toSqd(amount), BigInt(durationBlocks), autoExtension],
args: [BigInt(amount), BigInt(durationBlocks), autoExtension],
}),
};
} catch (e) {
Expand All @@ -56,7 +55,7 @@ function useStakeFromWallet() {
if (isApproveRequiredError(res.error)) {
const approveRes = await approveSqd({
contractAddress: contracts.GATEWAY_REGISTRATION,
amount: new Decimal(toSqd(req.amount).toString()),
amount: req.amount,
});
if (!approveRes.success) {
return { error: approveRes.failedReason };
Expand Down Expand Up @@ -86,7 +85,7 @@ function useStakeFromVestingContract() {
const data = encodeFunctionData({
abi: GATEWAY_REGISTRATION_CONTRACT_ABI,
functionName: 'stake',
args: [toSqd(amount), BigInt(durationBlocks), autoExtension],
args: [BigInt(amount), BigInt(durationBlocks), autoExtension],
});

return {
Expand All @@ -95,7 +94,7 @@ function useStakeFromVestingContract() {
address: wallet.id as `0x${string}`,
abi: VESTING_CONTRACT_ABI,
functionName: 'execute',
args: [contracts.GATEWAY_REGISTRATION, data, toSqd(amount)],
args: [contracts.GATEWAY_REGISTRATION, data, BigInt(amount)],
}),
};
} catch (e: unknown) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react';

import { peerIdToHex } from '@lib/network';
import { logger } from '@logger';
import { encodeFunctionData } from 'viem';
import { useWriteContract, usePublicClient } from 'wagmi';
Expand All @@ -10,7 +11,7 @@ import { useSquidNetworkHeightHooks } from '@hooks/useSquidNetworkHeightHooks.ts
import { useAccount } from '@network/useAccount';
import { useContracts } from '@network/useContracts.ts';

import { errorMessage, peerIdToHex, TxResult, WriteContractRes } from '../utils';
import { TxResult, errorMessage, WriteContractRes } from '../utils';
import { VESTING_CONTRACT_ABI } from '../vesting.abi';

import { GATEWAY_REGISTRATION_CONTRACT_ABI } from './GatewayRegistration.abi';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useSquidNetworkHeightHooks } from '@hooks/useSquidNetworkHeightHooks.ts
import { useAccount } from '@network/useAccount';
import { useContracts } from '@network/useContracts.ts';

import { errorMessage, TxResult, WriteContractRes } from '../utils';
import { TxResult, errorMessage, WriteContractRes } from '../utils';
import { VESTING_CONTRACT_ABI } from '../vesting.abi';

import { GATEWAY_REGISTRATION_CONTRACT_ABI } from './GatewayRegistration.abi';
Expand Down
26 changes: 26 additions & 0 deletions src/api/contracts/soft-cap.abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export const SOFT_CAP_ABI = [
{
type: 'function',
name: 'cap',
inputs: [{ name: 'x', type: 'uint256', internalType: 'UD60x18' }],
outputs: [{ name: '', type: 'uint256', internalType: 'UD60x18' }],
stateMutability: 'pure',
},
{
type: 'function',
name: 'capedStake',
inputs: [{ name: 'workerId', type: 'uint256', internalType: 'uint256' }],
outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'capedStakeAfterDelegation',
inputs: [
{ name: 'workerId', type: 'uint256', internalType: 'uint256' },
{ name: 'delegationAmount', type: 'int256', internalType: 'int256' },
],
outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
stateMutability: 'view',
},
] as const;
7 changes: 3 additions & 4 deletions src/api/contracts/sqd.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { logger } from '@logger';
import Decimal from 'decimal.js';
import { erc20Abi } from 'viem';
import { waitForTransactionReceipt } from 'viem/actions';
import { useWriteContract, useClient } from 'wagmi';
import { WriteContractData } from 'wagmi/query';

import { useContracts } from '@network/useContracts.ts';

import { errorMessage, WriteContractRes } from './utils';
import { WriteContractRes, errorMessage } from './utils';

export function useApproveSqd() {
const client = useClient();
Expand All @@ -19,7 +18,7 @@ export function useApproveSqd() {
amount,
}: {
contractAddress: `0x${string}`;
amount: Decimal;
amount: string;
}): Promise<WriteContractRes> {
let tx: WriteContractData;
logger.debug(`approving SQD to ${contracts.WORKER_REGISTRATION}...`);
Expand All @@ -28,7 +27,7 @@ export function useApproveSqd() {
address: contracts.SQD,
abi: erc20Abi,
functionName: 'approve',
args: [contractAddress, BigInt(amount.toFixed(0))],
args: [contractAddress, BigInt(amount)],
});
} catch (e) {
const error = errorMessage(e);
Expand Down
19 changes: 19 additions & 0 deletions src/api/contracts/staking.abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,23 @@ export const STAKING_CONTRACT_ABI = [
],
stateMutability: 'view',
},
{
type: 'function',
name: 'delegated',
inputs: [
{
name: 'worker',
type: 'uint256',
internalType: 'uint256',
},
],
outputs: [
{
name: '',
type: 'uint256',
internalType: 'uint256',
},
],
stateMutability: 'view',
},
] as const;
Loading

0 comments on commit 0a337b0

Please sign in to comment.