@wireio/stake 1.2.69 → 1.4.69

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wireio/stake",
3
- "version": "1.2.69",
3
+ "version": "1.4.69",
4
4
  "description": "LIQ Staking Module for Wire Network",
5
5
  "homepage": "https://gitea.gitgo.app/Wire/sdk-stake",
6
6
  "license": "FSL-1.1-Apache-2.0",
@@ -1,7 +1,7 @@
1
1
  import { BigNumber, ethers } from 'ethers';
2
2
 
3
3
  import { EthereumContractService } from '../contract';
4
- import { sendOPPFinalize } from '../utils';
4
+ import { resolveContractWriteOverrides, sendOPPFinalize } from '../utils';
5
5
  import HoodiLiqEthBridgeArtifact from '../../../assets/ethereum/hoodi/outpost/LiqEthBridge.sol/LiqEthBridge.json';
6
6
 
7
7
  export type EthereumInstaswapSubmitParams = {
@@ -112,11 +112,18 @@ export class EthereumInstaswapClient {
112
112
  minOut,
113
113
  );
114
114
 
115
+ const txOverrides = await resolveContractWriteOverrides(
116
+ depositorWrite,
117
+ 'instaswapCrossChain',
118
+ [amountIn, destinationChain, destinationAddress, minOut],
119
+ );
120
+
115
121
  const swapTx = await depositorWrite['instaswapCrossChain'](
116
122
  amountIn,
117
123
  destinationChain,
118
124
  destinationAddress,
119
125
  minOut,
126
+ txOverrides,
120
127
  );
121
128
  await hooks?.onSubmitted?.(swapTx.hash);
122
129
 
@@ -1,6 +1,6 @@
1
1
  import { BigNumber, ethers } from "ethers";
2
2
  import { EthereumContractService } from "../contract";
3
- import { formatContractErrors, sendOPPFinalize } from "../utils";
3
+ import { formatContractErrors, resolveContractWriteOverrides, sendOPPFinalize } from "../utils";
4
4
 
5
5
  export class PretokenClient {
6
6
  private readonly contractService: EthereumContractService;
@@ -72,7 +72,12 @@ export class PretokenClient {
72
72
  // attempt the real purchase call
73
73
  let tx, receipt;
74
74
  try {
75
- tx = await this.contract.Depositor.purchasePretokensWithLiqETH(amountLiq, buyer);
75
+ const txOverrides = await resolveContractWriteOverrides(
76
+ this.contract.Depositor,
77
+ 'purchasePretokensWithLiqETH',
78
+ [amountLiq, buyer],
79
+ );
80
+ tx = await this.contract.Depositor.purchasePretokensWithLiqETH(amountLiq, buyer, txOverrides);
76
81
  receipt = await tx.wait(1);
77
82
  } catch (err: any) {
78
83
  let errorObj = formatContractErrors(err);
@@ -162,4 +167,4 @@ export class PretokenClient {
162
167
 
163
168
 
164
169
 
165
- }
170
+ }
@@ -8,7 +8,7 @@ import {
8
8
  UnstakeAndWithdrawResult,
9
9
  } from "../types";
10
10
  import { EthereumContractService } from "../contract";
11
- import { formatContractErrors } from "../utils";
11
+ import { formatContractErrors, resolveContractWriteOverrides } from "../utils";
12
12
 
13
13
  export class StakeClient {
14
14
 
@@ -63,7 +63,12 @@ export class StakeClient {
63
63
  }
64
64
 
65
65
  // send the tx to stake liqeth
66
- const tx = await this.contract.Depositor.stakeLiqETH(amountWei);
66
+ const txOverrides = await resolveContractWriteOverrides(
67
+ this.contract.Depositor,
68
+ 'stakeLiqETH',
69
+ [amountWei],
70
+ );
71
+ const tx = await this.contract.Depositor.stakeLiqETH(amountWei, txOverrides);
67
72
 
68
73
  // Wait for 1 confirmation
69
74
  const receipt = await tx.wait(1);
@@ -136,7 +141,12 @@ export class StakeClient {
136
141
  }
137
142
 
138
143
  // send the tx to stake liqeth
139
- const tx = await this.contract.Depositor.stakeLiqETHToWire(amountWei, wireAccount);
144
+ const txOverrides = await resolveContractWriteOverrides(
145
+ this.contract.Depositor,
146
+ 'stakeLiqETHToWire',
147
+ [amountWei, wireAccount],
148
+ );
149
+ const tx = await this.contract.Depositor.stakeLiqETHToWire(amountWei, wireAccount, txOverrides);
140
150
 
141
151
  // Wait for 1 confirmation
142
152
  const receipt = await tx.wait(1);
@@ -209,7 +219,13 @@ export class StakeClient {
209
219
  throw new Error(errorObj.name ?? errorObj.raw);
210
220
  }
211
221
 
212
- const tx = await this.contract.Depositor.depositAndStake({ value: amountWei });
222
+ const txOverrides = await resolveContractWriteOverrides(
223
+ this.contract.Depositor,
224
+ 'depositAndStake',
225
+ [],
226
+ { value: amountWei },
227
+ );
228
+ const tx = await this.contract.Depositor.depositAndStake(txOverrides);
213
229
  const receipt = await tx.wait(1);
214
230
  let staked: StakedEvent | undefined;
215
231
  const ev = receipt.events?.find((e: any) => e.event === 'Staked');
@@ -275,7 +291,13 @@ export class StakeClient {
275
291
  throw new Error(errorObj.name ?? errorObj.raw);
276
292
  }
277
293
 
278
- const tx = await this.contract.Depositor.depositAndPurchase({ value: amountWei });
294
+ const txOverrides = await resolveContractWriteOverrides(
295
+ this.contract.Depositor,
296
+ 'depositAndPurchase',
297
+ [],
298
+ { value: amountWei },
299
+ );
300
+ const tx = await this.contract.Depositor.depositAndPurchase(txOverrides);
279
301
  const receipt = await tx.wait(1);
280
302
  return { txHash: tx.hash, receipt };
281
303
  }
@@ -293,7 +315,12 @@ export class StakeClient {
293
315
  throw new Error(errorObj.name ?? errorObj.raw);
294
316
  }
295
317
 
296
- const tx = await this.contract.Depositor.unstakeAndRequestWithdraw(tokenId);
318
+ const txOverrides = await resolveContractWriteOverrides(
319
+ this.contract.Depositor,
320
+ 'unstakeAndRequestWithdraw',
321
+ [tokenId],
322
+ );
323
+ const tx = await this.contract.Depositor.unstakeAndRequestWithdraw(tokenId, txOverrides);
297
324
  const receipt = await tx.wait(1);
298
325
  return { txHash: tx.hash, receipt };
299
326
  }
@@ -16,6 +16,9 @@ export interface CustomContractError {
16
16
  raw: string;
17
17
  }
18
18
 
19
+ const DEFAULT_WRITE_GAS_PADDING_BPS = 2_000;
20
+ const DEFAULT_WRITE_GAS_FALLBACK_LIMIT = ethers.BigNumber.from(8_000_000);
21
+
19
22
 
20
23
 
21
24
  export function formatContractErrors(err: any): CustomContractError {
@@ -110,6 +113,55 @@ export async function sendOPPFinalize(opp: ethers.Contract, gasLimit?: ethers.Bi
110
113
  }
111
114
  }
112
115
 
116
+ export async function resolveContractWriteOverrides(
117
+ contract: ethers.Contract,
118
+ method: string,
119
+ args: any[] = [],
120
+ overrides: Record<string, unknown> = {},
121
+ options?: {
122
+ fallbackGasLimit?: ethers.BigNumberish;
123
+ paddingBps?: number;
124
+ },
125
+ ): Promise<Record<string, unknown>> {
126
+ if (overrides['gasLimit'] != null) {
127
+ return overrides;
128
+ }
129
+
130
+ const paddingBps = options?.paddingBps ?? DEFAULT_WRITE_GAS_PADDING_BPS;
131
+ const fallbackGasLimit = ethers.BigNumber.from(
132
+ options?.fallbackGasLimit ?? DEFAULT_WRITE_GAS_FALLBACK_LIMIT,
133
+ );
134
+
135
+ try {
136
+ const estimateGas = contract.estimateGas?.[method];
137
+ if (typeof estimateGas !== 'function') {
138
+ return {
139
+ ...overrides,
140
+ gasLimit: fallbackGasLimit,
141
+ };
142
+ }
143
+
144
+ const estimated = await estimateGas(...args, overrides);
145
+ const gasLimit = ethers.BigNumber.from(estimated)
146
+ .mul(10_000 + paddingBps)
147
+ .div(10_000);
148
+
149
+ return {
150
+ ...overrides,
151
+ gasLimit,
152
+ };
153
+ } catch (error) {
154
+ console.warn(
155
+ `[EthereumGas] estimateGas.${method} failed, using fallback gasLimit ${fallbackGasLimit.toString()}`,
156
+ error,
157
+ );
158
+ return {
159
+ ...overrides,
160
+ gasLimit: fallbackGasLimit,
161
+ };
162
+ }
163
+ }
164
+
113
165
 
114
166
  const BPS_DENOM = BigInt(10_000);
115
167
 
@@ -337,4 +389,4 @@ export async function buildEthereumTrancheSnapshot(options: {
337
389
  nativePriceTimestamp,
338
390
  ladder,
339
391
  };
340
- }
392
+ }
@@ -9,7 +9,7 @@ import {
9
9
  } from '@solana/web3.js';
10
10
  import { getAssociatedTokenAddressSync, TOKEN_2022_PROGRAM_ID } from '@solana/spl-token';
11
11
 
12
- import { buildOutpostAccounts } from '../utils';
12
+ import { buildOutpostAccounts, OutpostAccounts } from '../utils';
13
13
  import { LiqsolCoreClientIdl, SolanaProgramService } from '../program';
14
14
  import { ConvertClient } from './convert.client';
15
15
 
@@ -38,6 +38,46 @@ export type SolanaInstaswapConnectedBalances = {
38
38
  liqsolDecimals: number;
39
39
  };
40
40
 
41
+ export function buildSolanaInstaswapCrossChainAccounts(params: {
42
+ user: PublicKey;
43
+ accounts: OutpostAccounts;
44
+ liqsolCoreProgram: PublicKey;
45
+ transferHookProgram: PublicKey;
46
+ pendingAttestations: PublicKey;
47
+ }) {
48
+ const {
49
+ user,
50
+ accounts,
51
+ liqsolCoreProgram,
52
+ transferHookProgram,
53
+ pendingAttestations,
54
+ } = params;
55
+
56
+ return {
57
+ user,
58
+ globalState: accounts.globalState,
59
+ liqsolMint: accounts.liqsolMint,
60
+ distributionState: accounts.distributionState,
61
+ userAta: accounts.userAta,
62
+ senderUserRecord: accounts.userUserRecord,
63
+ bridgeAuthority: accounts.bridgeAuthority,
64
+ bridgeVaultAta: accounts.bridgeVaultAta,
65
+ bridgeUserRecord: accounts.bridgeUserRecord,
66
+ bridgeState: accounts.bridgeState,
67
+ extraAccountMetaList: accounts.extraAccountMetaList,
68
+ liqsolCoreProgram,
69
+ transferHookProgram,
70
+ bucketAuthority: accounts.bucketAuthority,
71
+ bucketTokenAccount: accounts.bucketTokenAccount,
72
+ bucketUserRecord: accounts.bucketUserRecord,
73
+ tokenProgram: TOKEN_2022_PROGRAM_ID,
74
+ systemProgram: SystemProgram.programId,
75
+ globalConfig: accounts.globalConfig,
76
+ oppEpochState: accounts.oppEpochState,
77
+ pendingAttestations,
78
+ };
79
+ }
80
+
41
81
  export class SolanaInstaswapClient {
42
82
  private readonly program: Program<LiqsolCoreClientIdl>;
43
83
  private readonly convertClient: ConvertClient;
@@ -81,29 +121,15 @@ export class SolanaInstaswapClient {
81
121
  destinationAddress,
82
122
  minOut,
83
123
  )
84
- .accounts({
85
- user,
86
- globalState: accounts.globalState,
87
- liqsolMint: accounts.liqsolMint,
88
- distributionState: accounts.distributionState,
89
- userAta: accounts.userAta,
90
- senderUserRecord: accounts.userUserRecord,
91
- poolAuthority: accounts.poolAuthority,
92
- liqsolPoolAta: accounts.liqsolPoolAta,
93
- poolUserRecord: accounts.liqsolPoolUserRecord,
94
- bridgeState: accounts.bridgeState,
95
- extraAccountMetaList: accounts.extraAccountMetaList,
96
- liqsolCoreProgram: this.program.programId,
97
- transferHookProgram: this.pgs.PROGRAM_IDS.TRANSFER_HOOK,
98
- bucketAuthority: accounts.bucketAuthority,
99
- bucketTokenAccount: accounts.bucketTokenAccount,
100
- bucketUserRecord: accounts.bucketUserRecord,
101
- tokenProgram: TOKEN_2022_PROGRAM_ID,
102
- systemProgram: SystemProgram.programId,
103
- globalConfig: accounts.globalConfig,
104
- oppEpochState: accounts.oppEpochState,
105
- pendingAttestations,
106
- })
124
+ .accounts(
125
+ buildSolanaInstaswapCrossChainAccounts({
126
+ user,
127
+ accounts,
128
+ liqsolCoreProgram: this.program.programId,
129
+ transferHookProgram: this.pgs.PROGRAM_IDS.TRANSFER_HOOK,
130
+ pendingAttestations,
131
+ }),
132
+ )
107
133
  .preInstructions([
108
134
  ComputeBudgetProgram.setComputeUnitLimit({ units: 900_000 }),
109
135
  ])
@@ -126,29 +152,15 @@ export class SolanaInstaswapClient {
126
152
  destinationAddress,
127
153
  minOut,
128
154
  )
129
- .accounts({
130
- user,
131
- globalState: accounts.globalState,
132
- liqsolMint: accounts.liqsolMint,
133
- distributionState: accounts.distributionState,
134
- userAta: accounts.userAta,
135
- senderUserRecord: accounts.userUserRecord,
136
- poolAuthority: accounts.poolAuthority,
137
- liqsolPoolAta: accounts.liqsolPoolAta,
138
- poolUserRecord: accounts.liqsolPoolUserRecord,
139
- bridgeState: accounts.bridgeState,
140
- extraAccountMetaList: accounts.extraAccountMetaList,
141
- liqsolCoreProgram: this.program.programId,
142
- transferHookProgram: this.pgs.PROGRAM_IDS.TRANSFER_HOOK,
143
- bucketAuthority: accounts.bucketAuthority,
144
- bucketTokenAccount: accounts.bucketTokenAccount,
145
- bucketUserRecord: accounts.bucketUserRecord,
146
- tokenProgram: TOKEN_2022_PROGRAM_ID,
147
- systemProgram: SystemProgram.programId,
148
- globalConfig: accounts.globalConfig,
149
- oppEpochState: accounts.oppEpochState,
150
- pendingAttestations,
151
- })
155
+ .accounts(
156
+ buildSolanaInstaswapCrossChainAccounts({
157
+ user,
158
+ accounts,
159
+ liqsolCoreProgram: this.program.programId,
160
+ transferHookProgram: this.pgs.PROGRAM_IDS.TRANSFER_HOOK,
161
+ pendingAttestations,
162
+ }),
163
+ )
152
164
  .preInstructions([
153
165
  ComputeBudgetProgram.setComputeUnitLimit({ units: 900_000 }),
154
166
  ])
@@ -28,6 +28,41 @@ import {
28
28
  import { INDEX_SCALE } from '../constants';
29
29
  import { LiqsolCoreClientIdl, SolanaProgramService } from '../program';
30
30
 
31
+ export function buildSolanaSyndicateAccounts(params: {
32
+ user: PublicKey;
33
+ accounts: OutpostAccounts;
34
+ liqsolCoreProgram: PublicKey;
35
+ transferHookProgram: PublicKey;
36
+ }) {
37
+ const { user, accounts, liqsolCoreProgram, transferHookProgram } = params;
38
+
39
+ return {
40
+ user,
41
+ liqsolMint: accounts.liqsolMint,
42
+ distributionState: accounts.distributionState,
43
+ globalState: accounts.globalState,
44
+ userAta: accounts.userAta,
45
+ senderUserRecord: accounts.userUserRecord,
46
+ bridgeAuthority: accounts.bridgeAuthority,
47
+ bridgeVaultAta: accounts.bridgeVaultAta,
48
+ bridgeUserRecord: accounts.bridgeUserRecord,
49
+ bridgeState: accounts.bridgeState,
50
+ outpostAccount: accounts.outpostAccount,
51
+ extraAccountMetaList: accounts.extraAccountMetaList,
52
+ liqsolCoreProgram,
53
+ transferHookProgram,
54
+ bucketAuthority: accounts.bucketAuthority,
55
+ bucketTokenAccount: accounts.bucketTokenAccount,
56
+ bucketUserRecord: accounts.bucketUserRecord,
57
+ tokenProgram: TOKEN_2022_PROGRAM_ID,
58
+ associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
59
+ systemProgram: SystemProgram.programId,
60
+ globalConfig: accounts.globalConfig,
61
+ oppEpochState: accounts.oppEpochState,
62
+ pendingAttestations: accounts.pendingAttestations,
63
+ };
64
+ }
65
+
31
66
  /**
32
67
  * OutpostClient
33
68
  *
@@ -181,30 +216,14 @@ export class OutpostClient {
181
216
 
182
217
  return program.methods
183
218
  .syndicateLiqsolToWire(wireAccount.trim(), new BN(amountLamports.toString()))
184
- .accounts({
185
- user,
186
- liqsolMint: a.liqsolMint,
187
- distributionState: a.distributionState,
188
- globalState: a.globalState,
189
- userAta: a.userAta,
190
- senderUserRecord: a.userUserRecord,
191
- poolAuthority: a.poolAuthority,
192
- liqsolPoolAta: a.liqsolPoolAta,
193
- poolUserRecord: a.liqsolPoolUserRecord,
194
- bridgeState: a.bridgeState,
195
- extraAccountMetaList: a.extraAccountMetaList,
196
- liqsolCoreProgram: this.pgs.PROGRAM_IDS.LIQSOL_CORE,
197
- transferHookProgram: this.pgs.PROGRAM_IDS.TRANSFER_HOOK,
198
- bucketAuthority: a.bucketAuthority,
199
- bucketTokenAccount: a.bucketTokenAccount,
200
- bucketUserRecord: a.bucketUserRecord,
201
- tokenProgram: TOKEN_2022_PROGRAM_ID,
202
- associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
203
- systemProgram: SystemProgram.programId,
204
- globalConfig: a.globalConfig,
205
- oppEpochState: a.oppEpochState,
206
- pendingAttestations: a.pendingAttestations,
207
- })
219
+ .accounts(
220
+ buildSolanaSyndicateAccounts({
221
+ user,
222
+ accounts: a,
223
+ liqsolCoreProgram: this.pgs.PROGRAM_IDS.LIQSOL_CORE,
224
+ transferHookProgram: this.pgs.PROGRAM_IDS.TRANSFER_HOOK,
225
+ }),
226
+ )
208
227
  .instruction();
209
228
  }
210
229