Skip to content

Commit ff8c5e2

Browse files
committed
remove hardcoded delegate contract
1 parent 1f647c4 commit ff8c5e2

File tree

5 files changed

+50
-23
lines changed

5 files changed

+50
-23
lines changed

src/Account.tsx

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,27 @@ import {
99
DelegateSignerResponse,
1010
announceDelegateSigner,
1111
delegateAddOrderlyKey,
12-
registerDelegateSigner,
12+
registerExampleDelegateSigner,
1313
isTestnet
1414
} from './helpers';
1515

1616
export const Account: FC<{
1717
brokerId: string;
1818
accountId: string;
19+
contractAddress: string;
1920
delegateSigner?: DelegateSignerResponse;
2021
setDelegateSigner: React.Dispatch<React.SetStateAction<DelegateSignerResponse | undefined>>;
2122
orderlyKey?: Uint8Array;
2223
setOrderlyKey: React.Dispatch<React.SetStateAction<Uint8Array | undefined>>;
23-
}> = ({ brokerId, accountId, delegateSigner, setDelegateSigner, orderlyKey, setOrderlyKey }) => {
24+
}> = ({
25+
brokerId,
26+
accountId,
27+
contractAddress,
28+
delegateSigner,
29+
setDelegateSigner,
30+
orderlyKey,
31+
setOrderlyKey
32+
}) => {
2433
const [txHash, setTxHash] = useState<string>('');
2534
const [publicKey, setPublicKey] = useState<string>();
2635

@@ -101,7 +110,12 @@ export const Account: FC<{
101110
onClick={async () => {
102111
const address = wallet?.accounts[0]?.address;
103112
if (!wallet || !connectedChain || !address) return;
104-
const hash = await registerDelegateSigner(wallet, brokerId, connectedChain.id, address);
113+
const hash = await registerExampleDelegateSigner(
114+
wallet,
115+
brokerId,
116+
connectedChain.id,
117+
address
118+
);
105119
setTxHash(hash);
106120
}}
107121
>
@@ -127,7 +141,13 @@ export const Account: FC<{
127141
disabled={!wallet || !connectedChain || !brokerId || !txHash}
128142
onClick={async () => {
129143
if (!wallet || !connectedChain || !brokerId || !txHash) return;
130-
const res = await announceDelegateSigner(wallet, connectedChain.id, brokerId, txHash);
144+
const res = await announceDelegateSigner(
145+
wallet,
146+
connectedChain.id,
147+
brokerId,
148+
contractAddress,
149+
txHash
150+
);
131151
setDelegateSigner(res);
132152
}}
133153
>
@@ -139,7 +159,13 @@ export const Account: FC<{
139159
disabled={!wallet || !connectedChain || !brokerId}
140160
onClick={async () => {
141161
if (!wallet || !connectedChain || !brokerId) return;
142-
const key = await delegateAddOrderlyKey(wallet, connectedChain.id, brokerId, accountId);
162+
const key = await delegateAddOrderlyKey(
163+
wallet,
164+
connectedChain.id,
165+
brokerId,
166+
contractAddress,
167+
accountId
168+
);
143169
setOrderlyKey(key);
144170
}}
145171
>

src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ function App() {
260260
<Account
261261
brokerId={brokerId}
262262
accountId={accountId}
263+
contractAddress={contractAddress}
263264
delegateSigner={delegateSigner}
264265
setDelegateSigner={setDelegateSigner}
265266
orderlyKey={orderlyKey}

src/Assets.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,20 @@ export const Assets: FC<{
120120
<Table.Row>
121121
<Table.RowHeaderCell>Wallet Balance (USDC):</Table.RowHeaderCell>
122122
<Table.Cell>
123-
{balance ? formatter.format(Number(formatUnits(balance, 6))) : '-'}
123+
{balance != null ? formatter.format(Number(formatUnits(balance, 6))) : '-'}
124124
</Table.Cell>
125125
</Table.Row>
126126
<Table.Row>
127127
<Table.RowHeaderCell>Contract Balance (USDC):</Table.RowHeaderCell>
128128
<Table.Cell>
129-
{contractBalance ? formatter.format(Number(formatUnits(contractBalance, 6))) : '-'}
129+
{contractBalance != null
130+
? formatter.format(Number(formatUnits(contractBalance, 6)))
131+
: '-'}
130132
</Table.Cell>
131133
</Table.Row>
132134
<Table.Row>
133135
<Table.RowHeaderCell>Account Balance (USDC):</Table.RowHeaderCell>
134-
<Table.Cell>{vaultBalance ? String(vaultBalance) : '-'}</Table.Cell>
136+
<Table.Cell>{vaultBalance != null ? String(vaultBalance) : '-'}</Table.Cell>
135137
</Table.Row>
136138
</Table.Body>
137139
</Table.Root>
@@ -185,6 +187,7 @@ export const Assets: FC<{
185187
wallet,
186188
connectedChain.id,
187189
brokerId,
190+
contractAddress,
188191
amountBN.toString(),
189192
contractAddress,
190193
accountId
@@ -213,6 +216,7 @@ export const Assets: FC<{
213216
wallet,
214217
connectedChain.id,
215218
brokerId,
219+
contractAddress,
216220
accountId,
217221
orderlyKey,
218222
amountBN.toString(),

src/SafeInstructions.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,6 @@ export const SafeInstructions: FC<{ brokerId: string; chainId: string }> = ({
174174
style={{ maxWidth: '100%' }}
175175
/>
176176
</Flex>
177-
178-
<Flex direction="column">
179-
<Strong>Execute transaction</Strong>
180-
<img
181-
src="./confirm-tx.webp"
182-
alt="Confirm Gnosis Safe batch transaction"
183-
style={{ maxWidth: '100%' }}
184-
/>
185-
</Flex>
186177
</Flex>
187178
</Tabs.Content>
188179
</Container>

src/helpers/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export type DelegateSignerResponse = {
7979
valid_signer: string;
8080
};
8181

82-
export async function registerDelegateSigner(
82+
export async function registerExampleDelegateSigner(
8383
wallet: WalletState,
8484
brokerId: string,
8585
chainId: string,
@@ -99,14 +99,15 @@ export async function announceDelegateSigner(
9999
wallet: WalletState,
100100
chainId: string,
101101
brokerId: string,
102+
delegateContract: string,
102103
txHash: ethers.BytesLike
103104
): Promise<DelegateSignerResponse> {
104105
const nonceRes = await fetch(`${getBaseUrl(chainId)}/v1/registration_nonce`);
105106
const nonceJson = await nonceRes.json();
106107
const registrationNonce = nonceJson.data.registration_nonce as string;
107108

108109
const delegateSignerMessage = {
109-
delegateContract: exampleDelegateContract,
110+
delegateContract,
110111
brokerId,
111112
chainId: Number(chainId),
112113
timestamp: Date.now(),
@@ -144,13 +145,14 @@ export async function delegateAddOrderlyKey(
144145
wallet: WalletState,
145146
chainId: string,
146147
brokerId: string,
148+
delegateContract: string,
147149
accountId: string
148150
): Promise<Uint8Array> {
149151
const privateKey = utils.randomPrivateKey();
150152
const orderlyKey = `ed25519:${encodeBase58(await getPublicKeyAsync(privateKey))}`;
151153
const timestamp = Date.now();
152154
const addKeyMessage = {
153-
delegateContract: exampleDelegateContract,
155+
delegateContract,
154156
brokerId,
155157
chainId: Number(chainId),
156158
orderlyKey,
@@ -193,6 +195,7 @@ export async function delegateDeposit(
193195
wallet: WalletState,
194196
chainId: string,
195197
brokerId: string,
198+
delegateContract: string,
196199
amount: string,
197200
contractAddress: string,
198201
accountId: string
@@ -209,13 +212,14 @@ export async function delegateDeposit(
209212
} satisfies VaultTypes.VaultDepositFEStruct;
210213
const depositFee = await contract.getDepositFee(contractAddress, depositInput);
211214

212-
await contract.depositTo(exampleDelegateContract, depositInput, { value: depositFee });
215+
await contract.depositTo(delegateContract, depositInput, { value: depositFee });
213216
}
214217

215218
export async function delegateWithdraw(
216219
wallet: WalletState,
217220
chainId: string,
218221
brokerId: string,
222+
delegateContract: string,
219223
accountId: string,
220224
orderlyKey: Uint8Array,
221225
amount: string,
@@ -230,7 +234,7 @@ export async function delegateWithdraw(
230234
const withdrawNonce = nonceJson.data.withdraw_nonce as string;
231235

232236
const delegateWithdrawMessage = {
233-
delegateContract: exampleDelegateContract,
237+
delegateContract,
234238
brokerId,
235239
chainId: Number(chainId),
236240
receiver,
@@ -272,6 +276,7 @@ export async function delegateSettlePnL(
272276
wallet: WalletState,
273277
chainId: string,
274278
brokerId: string,
279+
delegateContract: string,
275280
accountId: string,
276281
orderlyKey: Uint8Array
277282
): Promise<void> {
@@ -284,7 +289,7 @@ export async function delegateSettlePnL(
284289
const settleNonce = nonceJson.data.settle_nonce as string;
285290

286291
const delegateSettlePnLMessage = {
287-
delegateContract: exampleDelegateContract,
292+
delegateContract,
288293
brokerId,
289294
chainId: Number(chainId),
290295
timestamp: Date.now(),

0 commit comments

Comments
 (0)