@lombard.finance/sdk 2.0.8 → 2.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +185 -179
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/sdk/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +79 -37
- package/src/web3Sdk/index.ts +1 -1
- package/src/web3Sdk/signStakeAndBake/config.ts +3 -6
- package/src/web3Sdk/signStakeAndBake/contracts.ts +13 -0
- package/src/web3Sdk/signStakeAndBake/getTypedData.ts +6 -10
- package/src/web3Sdk/signStakeAndBake/signStakeAndBake.stories.tsx +77 -23
- package/src/web3Sdk/signStakeAndBake/signStakeAndBake.ts +16 -12
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { IEnvParam } from '../../common/types/internalTypes';
|
|
2
1
|
import { TChainId } from '../../common/types/types';
|
|
3
2
|
import { getPermitNonce } from '../getPermitNonce';
|
|
4
|
-
import { getLbtcAddressConfig } from '../lbtcAddressConfig';
|
|
5
3
|
|
|
6
|
-
export interface IStakeAndBakeTypedData
|
|
4
|
+
export interface IStakeAndBakeTypedData {
|
|
7
5
|
chainId: TChainId;
|
|
8
|
-
|
|
6
|
+
expiry: number;
|
|
9
7
|
owner: string;
|
|
10
8
|
spender: string;
|
|
11
9
|
value: string;
|
|
12
10
|
rpcUrl?: string;
|
|
11
|
+
verifyingContract: string;
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
/**
|
|
@@ -20,16 +19,13 @@ export interface IStakeAndBakeTypedData extends IEnvParam {
|
|
|
20
19
|
*/
|
|
21
20
|
export async function getStakeAndBakeTypedData({
|
|
22
21
|
chainId,
|
|
23
|
-
|
|
22
|
+
expiry,
|
|
24
23
|
owner,
|
|
25
24
|
spender,
|
|
26
25
|
value,
|
|
27
|
-
env,
|
|
28
26
|
rpcUrl,
|
|
27
|
+
verifyingContract,
|
|
29
28
|
}: IStakeAndBakeTypedData) {
|
|
30
|
-
const lbtcAddresses = getLbtcAddressConfig(env);
|
|
31
|
-
const verifyingContract = lbtcAddresses[chainId];
|
|
32
|
-
|
|
33
29
|
const nonce = await getPermitNonce({
|
|
34
30
|
owner,
|
|
35
31
|
chainId,
|
|
@@ -76,7 +72,7 @@ export async function getStakeAndBakeTypedData({
|
|
|
76
72
|
spender,
|
|
77
73
|
value,
|
|
78
74
|
nonce,
|
|
79
|
-
deadline:
|
|
75
|
+
deadline: expiry.toString(),
|
|
80
76
|
},
|
|
81
77
|
};
|
|
82
78
|
}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
FormControl,
|
|
3
|
+
InputLabel,
|
|
4
|
+
MenuItem,
|
|
5
|
+
Select,
|
|
6
|
+
TextField,
|
|
7
|
+
} from '@mui/material';
|
|
8
|
+
import type { Meta } from '@storybook/react';
|
|
9
|
+
import { useEffect, useState } from 'react';
|
|
10
|
+
import { OChainId } from '../../common/types/types';
|
|
5
11
|
import { Button } from '../../stories/components/Button';
|
|
6
12
|
import { CodeBlock } from '../../stories/components/CodeBlock';
|
|
7
13
|
import { useConnect } from '../../stories/hooks/useConnect';
|
|
8
14
|
import useQuery from '../../stories/hooks/useQuery';
|
|
9
15
|
import { fromCamelCase } from '../../stories/utils/fromCamelCase';
|
|
10
|
-
import {
|
|
16
|
+
import { VAULT_CONTRACTS } from './contracts';
|
|
17
|
+
import { signStakeAndBake } from './signStakeAndBake';
|
|
11
18
|
|
|
12
19
|
const { name } = signStakeAndBake;
|
|
13
20
|
const nameWithWhitespaces = fromCamelCase(name);
|
|
@@ -22,6 +29,8 @@ const EXPIRY_OPTIONS = {
|
|
|
22
29
|
|
|
23
30
|
type ExpiryOption = keyof typeof EXPIRY_OPTIONS;
|
|
24
31
|
|
|
32
|
+
const AVAILABLE_CHAINS = Object.keys(VAULT_CONTRACTS).map(Number);
|
|
33
|
+
|
|
25
34
|
const meta = {
|
|
26
35
|
title: 'Web3SDK/signStakeAndBake',
|
|
27
36
|
component: StoryView,
|
|
@@ -30,19 +39,16 @@ const meta = {
|
|
|
30
39
|
|
|
31
40
|
export default meta;
|
|
32
41
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export const WithParams: Story = {
|
|
36
|
-
args: {
|
|
37
|
-
env: OEnv.stage,
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
type SignStakeAndBakeProps = Pick<ISignStakeAndBakeParams, 'env'>;
|
|
42
|
-
|
|
43
|
-
export function StoryView(props: SignStakeAndBakeProps) {
|
|
42
|
+
export function StoryView() {
|
|
44
43
|
const [selectedExpiry, setSelectedExpiry] =
|
|
45
44
|
useState<ExpiryOption>('10 seconds');
|
|
45
|
+
const [selectedChain, setSelectedChain] = useState(OChainId.holesky);
|
|
46
|
+
const [spender, setSpender] = useState(
|
|
47
|
+
VAULT_CONTRACTS[OChainId.holesky].SPENDER,
|
|
48
|
+
);
|
|
49
|
+
const [verifyingContract, setVerifyingContract] = useState(
|
|
50
|
+
VAULT_CONTRACTS[OChainId.holesky].VERIFYING_CONTRACT,
|
|
51
|
+
);
|
|
46
52
|
|
|
47
53
|
const {
|
|
48
54
|
data: connectData,
|
|
@@ -51,28 +57,34 @@ export function StoryView(props: SignStakeAndBakeProps) {
|
|
|
51
57
|
connect,
|
|
52
58
|
} = useConnect();
|
|
53
59
|
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
const contracts = VAULT_CONTRACTS[selectedChain];
|
|
62
|
+
setSpender(contracts.SPENDER);
|
|
63
|
+
setVerifyingContract(contracts.VERIFYING_CONTRACT);
|
|
64
|
+
}, [selectedChain]);
|
|
65
|
+
|
|
54
66
|
const request = async () => {
|
|
55
67
|
if (!connectData || !connectData.provider) {
|
|
56
68
|
return;
|
|
57
69
|
}
|
|
58
70
|
|
|
59
|
-
const
|
|
60
|
-
const expiryDate =
|
|
71
|
+
const expiry =
|
|
61
72
|
Math.floor(Date.now() / 1000) + EXPIRY_OPTIONS[selectedExpiry];
|
|
62
73
|
|
|
63
74
|
return signStakeAndBake({
|
|
64
75
|
provider: connectData.provider,
|
|
65
76
|
address: connectData.account,
|
|
66
|
-
chainId,
|
|
67
|
-
env: props.env,
|
|
77
|
+
chainId: selectedChain,
|
|
68
78
|
value: '1999',
|
|
69
|
-
|
|
79
|
+
expiry,
|
|
80
|
+
spender,
|
|
81
|
+
verifyingContract,
|
|
70
82
|
});
|
|
71
83
|
};
|
|
72
84
|
|
|
73
85
|
const { data, error, isLoading, refetch } = useQuery(
|
|
74
86
|
request,
|
|
75
|
-
[selectedExpiry],
|
|
87
|
+
[selectedExpiry, selectedChain, spender, verifyingContract],
|
|
76
88
|
false,
|
|
77
89
|
);
|
|
78
90
|
|
|
@@ -100,6 +112,48 @@ export function StoryView(props: SignStakeAndBakeProps) {
|
|
|
100
112
|
<CodeBlock text={connectError || formattedConnectData} />
|
|
101
113
|
</div>
|
|
102
114
|
|
|
115
|
+
<div className="mb-4">
|
|
116
|
+
<FormControl fullWidth>
|
|
117
|
+
<InputLabel id="chain-select-label">Chain</InputLabel>
|
|
118
|
+
<Select
|
|
119
|
+
labelId="chain-select-label"
|
|
120
|
+
value={selectedChain}
|
|
121
|
+
label="Chain"
|
|
122
|
+
onChange={e =>
|
|
123
|
+
setSelectedChain(Number(e.target.value) as typeof selectedChain)
|
|
124
|
+
}
|
|
125
|
+
>
|
|
126
|
+
{AVAILABLE_CHAINS.map(chainId => (
|
|
127
|
+
<MenuItem key={chainId} value={chainId}>
|
|
128
|
+
{chainId}
|
|
129
|
+
</MenuItem>
|
|
130
|
+
))}
|
|
131
|
+
</Select>
|
|
132
|
+
</FormControl>
|
|
133
|
+
</div>
|
|
134
|
+
|
|
135
|
+
<div className="mb-4">
|
|
136
|
+
<FormControl fullWidth>
|
|
137
|
+
<TextField
|
|
138
|
+
label="Spender Address"
|
|
139
|
+
value={spender}
|
|
140
|
+
onChange={e => setSpender(e.target.value)}
|
|
141
|
+
helperText="The address that will be authorized to spend tokens"
|
|
142
|
+
/>
|
|
143
|
+
</FormControl>
|
|
144
|
+
</div>
|
|
145
|
+
|
|
146
|
+
<div className="mb-4">
|
|
147
|
+
<FormControl fullWidth>
|
|
148
|
+
<TextField
|
|
149
|
+
label="Verifying Contract"
|
|
150
|
+
value={verifyingContract}
|
|
151
|
+
onChange={e => setVerifyingContract(e.target.value)}
|
|
152
|
+
helperText="The contract that will verify the signature"
|
|
153
|
+
/>
|
|
154
|
+
</FormControl>
|
|
155
|
+
</div>
|
|
156
|
+
|
|
103
157
|
<div className="mb-4">
|
|
104
158
|
<FormControl fullWidth>
|
|
105
159
|
<InputLabel id="expiry-select-label">Expiry Time</InputLabel>
|
|
@@ -121,7 +175,7 @@ export function StoryView(props: SignStakeAndBakeProps) {
|
|
|
121
175
|
<Button
|
|
122
176
|
onClick={refetch}
|
|
123
177
|
disabled={
|
|
124
|
-
isLoading || !connectData || connectData.chainId !==
|
|
178
|
+
isLoading || !connectData || connectData.chainId !== selectedChain
|
|
125
179
|
}
|
|
126
180
|
isLoading={isLoading}
|
|
127
181
|
>
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { IEnvParam } from '../../common/types/internalTypes';
|
|
2
1
|
import { TChainId } from '../../common/types/types';
|
|
3
2
|
import { Provider } from '../../provider';
|
|
4
3
|
import { IProviderBasedParams } from '../types';
|
|
5
|
-
import { getStakeAndBakeSpenderAddress } from './config';
|
|
6
4
|
import { getStakeAndBakeTypedData } from './getTypedData';
|
|
7
5
|
|
|
8
6
|
const NO_SIGNATURE_ERROR =
|
|
9
7
|
'Failed to obtain a valid signature. The response is undefined or invalid.';
|
|
10
8
|
|
|
11
9
|
export interface ISignStakeAndBakeParams
|
|
12
|
-
extends Pick<IProviderBasedParams, 'provider'
|
|
13
|
-
IEnvParam {
|
|
10
|
+
extends Pick<IProviderBasedParams, 'provider'> {
|
|
14
11
|
/**
|
|
15
12
|
* The address to sign with (owner)
|
|
16
13
|
*/
|
|
@@ -24,13 +21,21 @@ export interface ISignStakeAndBakeParams
|
|
|
24
21
|
*/
|
|
25
22
|
value: string;
|
|
26
23
|
/**
|
|
27
|
-
* Expiry date
|
|
24
|
+
* Expiry date as a unix timestamp
|
|
28
25
|
*/
|
|
29
|
-
|
|
26
|
+
expiry: number;
|
|
30
27
|
/**
|
|
31
28
|
* Optional RPC URL for the network
|
|
32
29
|
*/
|
|
33
30
|
rpcUrl?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The spender address that will be authorized to spend tokens
|
|
33
|
+
*/
|
|
34
|
+
spender: string;
|
|
35
|
+
/**
|
|
36
|
+
* The contract address that will verify the signature
|
|
37
|
+
*/
|
|
38
|
+
verifyingContract: string;
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
export interface ISignStakeAndBakeResult {
|
|
@@ -55,9 +60,10 @@ export async function signStakeAndBake({
|
|
|
55
60
|
provider,
|
|
56
61
|
chainId,
|
|
57
62
|
value,
|
|
58
|
-
|
|
59
|
-
expiryDate,
|
|
63
|
+
expiry,
|
|
60
64
|
rpcUrl,
|
|
65
|
+
spender,
|
|
66
|
+
verifyingContract,
|
|
61
67
|
}: ISignStakeAndBakeParams): Promise<ISignStakeAndBakeResult> {
|
|
62
68
|
const providerInstance = new Provider({
|
|
63
69
|
provider,
|
|
@@ -65,16 +71,14 @@ export async function signStakeAndBake({
|
|
|
65
71
|
chainId,
|
|
66
72
|
});
|
|
67
73
|
|
|
68
|
-
const spender = getStakeAndBakeSpenderAddress(chainId);
|
|
69
|
-
|
|
70
74
|
const typedDataObject = await getStakeAndBakeTypedData({
|
|
71
75
|
chainId,
|
|
72
|
-
|
|
76
|
+
expiry,
|
|
73
77
|
owner: address,
|
|
74
78
|
spender,
|
|
75
79
|
value,
|
|
76
|
-
env,
|
|
77
80
|
rpcUrl,
|
|
81
|
+
verifyingContract,
|
|
78
82
|
});
|
|
79
83
|
|
|
80
84
|
const typedData = JSON.stringify(typedDataObject);
|