@wireio/stake 1.3.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/README.md +2 -0
- package/lib/stake.browser.js +117 -32
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +31 -1
- package/lib/stake.js +152 -47
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +117 -32
- package/lib/stake.m.js.map +1 -1
- package/package.json +1 -1
- package/src/networks/ethereum/clients/instaswap.client.ts +8 -1
- package/src/networks/ethereum/clients/pretoken.client.ts +8 -3
- package/src/networks/ethereum/clients/stake.client.ts +33 -6
- package/src/networks/ethereum/utils.ts +53 -1
- package/src/networks/solana/clients/outpost.client.ts +43 -24
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
+
}
|
|
@@ -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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
|