gondi 0.60.0 → 0.61.0
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.mjs +61 -61
- package/dist/index.mjs.map +4 -4
- package/dist/src/clients/api/auth.d.ts +11 -4
- package/dist/src/clients/contracts/AllV6.d.ts +43 -0
- package/dist/src/clients/contracts/AllV8.d.ts +51 -4
- package/dist/src/clients/contracts/MslV6.d.ts +40 -21
- package/dist/src/clients/contracts/index.d.ts +2 -0
- package/dist/src/gondi.d.ts +2 -42
- package/dist/src/utils/auction.d.ts +82 -0
- package/dist/src/utils/blockchain.d.ts +17 -0
- package/dist/tests/utils/liquidatorRevert.d.ts +8 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -7,11 +7,17 @@ export declare const signIn: ({ wallet, issuedAt }: {
|
|
|
7
7
|
issuedAt?: string;
|
|
8
8
|
}) => Promise<any>;
|
|
9
9
|
/**
|
|
10
|
-
* The wallet's API session: signs in on the first request and reuses the token
|
|
10
|
+
* The wallet's API session: signs in on the first request and reuses the token until it is about
|
|
11
|
+
* to expire, then signs in again.
|
|
11
12
|
*
|
|
12
|
-
* Requests that start before
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* Requests that start before a sign-in finishes wait for that same sign-in rather than starting
|
|
14
|
+
* their own: every sign-in asks the API for a fresh nonce, which replaces the previous one, so
|
|
15
|
+
* concurrent sign-ins reject all but the last with `SIWE_ERROR`.
|
|
16
|
+
*
|
|
17
|
+
* The token's own `exp` decides when it is renewed. The API answers an expired token as if no
|
|
18
|
+
* token was sent, with an `UNAUTHORIZED` GraphQL error rather than an HTTP 401, and raises that
|
|
19
|
+
* same error for calls the wallet is not allowed to make, so re-signing on it would prompt the
|
|
20
|
+
* wallet on every forbidden call.
|
|
15
21
|
*/
|
|
16
22
|
export declare class SessionToken {
|
|
17
23
|
token?: string;
|
|
@@ -33,5 +39,6 @@ export declare class SessionToken {
|
|
|
33
39
|
context?: import("@apollo/client").DefaultContext;
|
|
34
40
|
extensions?: Record<string, any>;
|
|
35
41
|
}>;
|
|
42
|
+
private hasLiveToken;
|
|
36
43
|
private signIn;
|
|
37
44
|
}
|
|
@@ -2,6 +2,7 @@ import { Address, PublicClient } from 'viem';
|
|
|
2
2
|
import { Auction, LoanV6 } from '../../blockchain';
|
|
3
3
|
import { Wallet } from '../../clients/contracts';
|
|
4
4
|
import { auctionWithBuyoutLoanLiquidatorAbi as auctionWithBuyoutLoanLiquidatorABIV6 } from '../../generated/blockchain/v6';
|
|
5
|
+
import { AuctionIdentity } from '../../utils/auction';
|
|
5
6
|
import { BaseContract } from './BaseContract';
|
|
6
7
|
export declare class AllV6 extends BaseContract<typeof auctionWithBuyoutLoanLiquidatorABIV6> {
|
|
7
8
|
constructor({ walletClient, address, publicClient, }: {
|
|
@@ -9,11 +10,49 @@ export declare class AllV6 extends BaseContract<typeof auctionWithBuyoutLoanLiqu
|
|
|
9
10
|
address: Address;
|
|
10
11
|
publicClient?: PublicClient;
|
|
11
12
|
});
|
|
13
|
+
/** Reads the auction's current struct from the chain, with the NFT it auctions (`readAuction`). */
|
|
14
|
+
getAuction({ auction }: {
|
|
15
|
+
auction: AuctionIdentity;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
auction: {
|
|
18
|
+
loanAddress: `0x${string}`;
|
|
19
|
+
loanId: bigint;
|
|
20
|
+
highestBid: bigint;
|
|
21
|
+
triggerFee: bigint;
|
|
22
|
+
minBid: bigint;
|
|
23
|
+
highestBidder: `0x${string}`;
|
|
24
|
+
duration: bigint;
|
|
25
|
+
asset: `0x${string}`;
|
|
26
|
+
startTime: bigint;
|
|
27
|
+
originator: `0x${string}`;
|
|
28
|
+
lastBidTime: bigint;
|
|
29
|
+
} | {
|
|
30
|
+
loanAddress: `0x${string}`;
|
|
31
|
+
loanId: bigint;
|
|
32
|
+
highestBid: bigint;
|
|
33
|
+
triggerFee: bigint;
|
|
34
|
+
minBid: bigint;
|
|
35
|
+
highestBidder: `0x${string}`;
|
|
36
|
+
duration: bigint;
|
|
37
|
+
asset: `0x${string}`;
|
|
38
|
+
startTime: bigint;
|
|
39
|
+
originator: `0x${string}`;
|
|
40
|
+
lastBidTime: bigint;
|
|
41
|
+
loanHash: `0x${string}`;
|
|
42
|
+
buyoutWindow: bigint;
|
|
43
|
+
};
|
|
44
|
+
collectionContractAddress: `0x${string}`;
|
|
45
|
+
tokenId: bigint;
|
|
46
|
+
}>;
|
|
12
47
|
/** Whether this liquidator records an auction on the collateral; settling clears the record. */
|
|
13
48
|
hasAuction({ collectionContractAddress, tokenId, }: {
|
|
14
49
|
collectionContractAddress: Address;
|
|
15
50
|
tokenId: bigint;
|
|
16
51
|
}): Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Bids on the auction, rebuilding it from the chain when a bid placed since the caller read it
|
|
54
|
+
* makes the liquidator reject the caller's struct.
|
|
55
|
+
*/
|
|
17
56
|
placeBid({ collectionContractAddress, tokenId, bid, auction, }: {
|
|
18
57
|
collectionContractAddress: Address;
|
|
19
58
|
tokenId: bigint;
|
|
@@ -48,6 +87,10 @@ export declare class AllV6 extends BaseContract<typeof auctionWithBuyoutLoanLiqu
|
|
|
48
87
|
loanId: bigint;
|
|
49
88
|
}>;
|
|
50
89
|
}>;
|
|
90
|
+
/**
|
|
91
|
+
* Seconds left before bids open, while the loan's main lender may still buy the other lenders
|
|
92
|
+
* out. Before v3.2 that window is the liquidator's current setting, for every auction.
|
|
93
|
+
*/
|
|
51
94
|
getRemainingLockupSeconds({ auction }: {
|
|
52
95
|
auction: Pick<Auction, 'startTime'>;
|
|
53
96
|
}): Promise<number>;
|
|
@@ -1,23 +1,61 @@
|
|
|
1
1
|
import { Address, PublicClient } from 'viem';
|
|
2
|
-
import { Auction, LoanV8 } from '../../blockchain';
|
|
2
|
+
import { Auction, AuctionV8, LoanV8 } from '../../blockchain';
|
|
3
3
|
import { Wallet } from '../../clients/contracts';
|
|
4
4
|
import { auctionWithBuyoutLoanLiquidatorAbi as auctionWithBuyoutLoanLiquidatorABIV8 } from '../../generated/blockchain/v8';
|
|
5
|
+
import { AuctionIdentity } from '../../utils/auction';
|
|
5
6
|
import { BaseContract } from './BaseContract';
|
|
7
|
+
/** Buyout windows by `liquidator:loanAddress:loanId:startTime`, lowercased. */
|
|
8
|
+
export type BuyoutWindows = Map<string, Promise<bigint>>;
|
|
6
9
|
/**
|
|
7
10
|
* The AuctionLoanLiquidator of contract version 3.2. Its `Auction` struct carries `loanHash` and
|
|
8
11
|
* `buyoutWindow` on top of the version 3 struct, and an outbid bidder whose refund transfer failed
|
|
9
12
|
* claims it with `claimRefund`.
|
|
10
13
|
*/
|
|
11
14
|
export declare class AllV8 extends BaseContract<typeof auctionWithBuyoutLoanLiquidatorABIV8> {
|
|
12
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The `buyoutWindow` each auction recorded when it started, read once per auction. `Contracts`
|
|
17
|
+
* passes the one it keeps for the whole `Gondi`, since it builds a new liquidator on every call.
|
|
18
|
+
*/
|
|
19
|
+
private buyoutWindows;
|
|
20
|
+
constructor({ walletClient, address, publicClient, buyoutWindows, }: {
|
|
13
21
|
walletClient: Wallet;
|
|
14
22
|
address: Address;
|
|
15
23
|
publicClient?: PublicClient;
|
|
24
|
+
buyoutWindows?: BuyoutWindows;
|
|
16
25
|
});
|
|
17
26
|
hasAuction({ collectionContractAddress, tokenId, }: {
|
|
18
27
|
collectionContractAddress: Address;
|
|
19
28
|
tokenId: bigint;
|
|
20
29
|
}): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* Reads the auction's current struct from the chain, with the NFT it auctions (see
|
|
32
|
+
* `readAuction`), including the `loanHash` and `buyoutWindow` only its start event carries.
|
|
33
|
+
*/
|
|
34
|
+
getAuction({ auction }: {
|
|
35
|
+
auction: AuctionIdentity;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
auction: {
|
|
38
|
+
loanAddress: `0x${string}`;
|
|
39
|
+
loanId: bigint;
|
|
40
|
+
highestBid: bigint;
|
|
41
|
+
triggerFee: bigint;
|
|
42
|
+
minBid: bigint;
|
|
43
|
+
highestBidder: `0x${string}`;
|
|
44
|
+
duration: bigint;
|
|
45
|
+
asset: `0x${string}`;
|
|
46
|
+
startTime: bigint;
|
|
47
|
+
originator: `0x${string}`;
|
|
48
|
+
lastBidTime: bigint;
|
|
49
|
+
loanHash: `0x${string}`;
|
|
50
|
+
buyoutWindow: bigint;
|
|
51
|
+
};
|
|
52
|
+
collectionContractAddress: `0x${string}`;
|
|
53
|
+
tokenId: bigint;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Bids on the auction, rebuilding it from the chain when the caller's struct lacks the v3.2
|
|
57
|
+
* fields or a bid placed since the caller read it makes the liquidator reject it.
|
|
58
|
+
*/
|
|
21
59
|
placeBid({ collectionContractAddress, tokenId, bid, auction, }: {
|
|
22
60
|
collectionContractAddress: Address;
|
|
23
61
|
tokenId: bigint;
|
|
@@ -52,9 +90,16 @@ export declare class AllV8 extends BaseContract<typeof auctionWithBuyoutLoanLiqu
|
|
|
52
90
|
loanId: bigint;
|
|
53
91
|
}>;
|
|
54
92
|
}>;
|
|
55
|
-
|
|
56
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Seconds left before bids open, while the loan's main lender may still buy the other lenders
|
|
95
|
+
* out. v3.2 snapshots that window into each auction when it starts, and it is 0 when the main
|
|
96
|
+
* lender is a pool, so the liquidator's current setting does not apply. The window comes from
|
|
97
|
+
* the caller's struct when it has one, and from the chain once per auction otherwise.
|
|
98
|
+
*/
|
|
99
|
+
getRemainingLockupSeconds({ auction, }: {
|
|
100
|
+
auction: AuctionIdentity & Partial<Pick<AuctionV8, 'buyoutWindow'>>;
|
|
57
101
|
}): Promise<number>;
|
|
102
|
+
private readBuyoutWindow;
|
|
58
103
|
settleAuctionWithBuyout({ auction, loan }: {
|
|
59
104
|
auction: Auction;
|
|
60
105
|
loan: LoanV8;
|
|
@@ -154,5 +199,7 @@ export declare class AllV8 extends BaseContract<typeof auctionWithBuyoutLoanLiqu
|
|
|
154
199
|
amount: bigint;
|
|
155
200
|
}>;
|
|
156
201
|
}>;
|
|
202
|
+
/** The caller's auction with its NFT, or undefined when the struct is not a v3.2 one. */
|
|
203
|
+
private heldAuction;
|
|
157
204
|
private mapAuctionToAuctionArgs;
|
|
158
205
|
}
|
|
@@ -10092,32 +10092,21 @@ export declare class MslV6 extends BaseContract<typeof multiSourceLoanAbiV6 | ty
|
|
|
10092
10092
|
_rights: `0x${string}`;
|
|
10093
10093
|
}>;
|
|
10094
10094
|
}>;
|
|
10095
|
+
/**
|
|
10096
|
+
* Liquidates a defaulted loan. A loan with a single tranche whose lender is not a pool is
|
|
10097
|
+
* foreclosed: the lender takes the NFT, and the result's `liquidation` is `'foreclosed'`.
|
|
10098
|
+
* Any other loan is sent to the liquidator, which starts an auction: the result's
|
|
10099
|
+
* `liquidation` is `'auction'`, and it carries the auctioned NFT and the auction struct from
|
|
10100
|
+
* the liquidator's `LoanLiquidationStarted` event.
|
|
10101
|
+
*/
|
|
10095
10102
|
liquidateLoan({ loan, loanId }: {
|
|
10096
10103
|
loan: LoanV6;
|
|
10097
10104
|
loanId: bigint;
|
|
10098
10105
|
}): Promise<{
|
|
10099
10106
|
txHash: `0x${string}`;
|
|
10100
10107
|
waitTxInBlock: () => Promise<{
|
|
10101
|
-
|
|
10102
|
-
blobGasUsed?: bigint | undefined;
|
|
10103
|
-
blockHash: Hash;
|
|
10104
|
-
blockNumber: bigint;
|
|
10105
|
-
blockTimestamp?: bigint | undefined;
|
|
10106
|
-
contractAddress: Address | null | undefined;
|
|
10107
|
-
cumulativeGasUsed: bigint;
|
|
10108
|
-
effectiveGasPrice: bigint;
|
|
10109
|
-
from: Address;
|
|
10110
|
-
gasUsed: bigint;
|
|
10111
|
-
logs: import("viem").Log<bigint, number, false>[];
|
|
10112
|
-
logsBloom: Hex;
|
|
10113
|
-
root?: Hash | undefined;
|
|
10114
|
-
status: "success" | "reverted";
|
|
10115
|
-
to: Address | null;
|
|
10116
|
-
transactionHash: Hash;
|
|
10117
|
-
transactionIndex: number;
|
|
10118
|
-
type: import("viem").TransactionType;
|
|
10108
|
+
liquidation: "foreclosed";
|
|
10119
10109
|
loanId: bigint;
|
|
10120
|
-
} | {
|
|
10121
10110
|
blobGasPrice?: bigint | undefined;
|
|
10122
10111
|
blobGasUsed?: bigint | undefined;
|
|
10123
10112
|
blockHash: Hash;
|
|
@@ -10136,8 +10125,39 @@ export declare class MslV6 extends BaseContract<typeof multiSourceLoanAbiV6 | ty
|
|
|
10136
10125
|
transactionHash: Hash;
|
|
10137
10126
|
transactionIndex: number;
|
|
10138
10127
|
type: import("viem").TransactionType;
|
|
10139
|
-
loanId: bigint;
|
|
10140
10128
|
} | {
|
|
10129
|
+
collectionContractAddress: `0x${string}`;
|
|
10130
|
+
tokenId: bigint;
|
|
10131
|
+
auction: {
|
|
10132
|
+
loanAddress: `0x${string}`;
|
|
10133
|
+
loanId: bigint;
|
|
10134
|
+
highestBid: bigint;
|
|
10135
|
+
triggerFee: bigint;
|
|
10136
|
+
minBid: bigint;
|
|
10137
|
+
highestBidder: `0x${string}`;
|
|
10138
|
+
duration: bigint;
|
|
10139
|
+
asset: `0x${string}`;
|
|
10140
|
+
startTime: bigint;
|
|
10141
|
+
originator: `0x${string}`;
|
|
10142
|
+
lastBidTime: bigint;
|
|
10143
|
+
} | {
|
|
10144
|
+
loanAddress: `0x${string}`;
|
|
10145
|
+
loanId: bigint;
|
|
10146
|
+
highestBid: bigint;
|
|
10147
|
+
triggerFee: bigint;
|
|
10148
|
+
minBid: bigint;
|
|
10149
|
+
highestBidder: `0x${string}`;
|
|
10150
|
+
duration: bigint;
|
|
10151
|
+
asset: `0x${string}`;
|
|
10152
|
+
startTime: bigint;
|
|
10153
|
+
originator: `0x${string}`;
|
|
10154
|
+
lastBidTime: bigint;
|
|
10155
|
+
loanHash: `0x${string}`;
|
|
10156
|
+
buyoutWindow: bigint;
|
|
10157
|
+
};
|
|
10158
|
+
liquidation: "auction";
|
|
10159
|
+
loanId: bigint;
|
|
10160
|
+
liquidator: `0x${string}`;
|
|
10141
10161
|
blobGasPrice?: bigint | undefined;
|
|
10142
10162
|
blobGasUsed?: bigint | undefined;
|
|
10143
10163
|
blockHash: Hash;
|
|
@@ -10156,7 +10176,6 @@ export declare class MslV6 extends BaseContract<typeof multiSourceLoanAbiV6 | ty
|
|
|
10156
10176
|
transactionHash: Hash;
|
|
10157
10177
|
transactionIndex: number;
|
|
10158
10178
|
type: import("viem").TransactionType;
|
|
10159
|
-
loanId: bigint;
|
|
10160
10179
|
}>;
|
|
10161
10180
|
}>;
|
|
10162
10181
|
decodeRepaymentCalldata(calldata: Hex): {
|
|
@@ -32,6 +32,8 @@ type MslArgs = {
|
|
|
32
32
|
export declare class Contracts {
|
|
33
33
|
publicClient: GondiPublicClient;
|
|
34
34
|
walletClient: Wallet;
|
|
35
|
+
/** Shared by every version 3.2 liquidator `All` builds, so a buyout window is read once. */
|
|
36
|
+
private buyoutWindows;
|
|
35
37
|
constructor(publicClient: GondiPublicClient, walletClient: Wallet);
|
|
36
38
|
_Msls: {
|
|
37
39
|
'1': (args: MslArgs) => MslV4;
|
package/dist/src/gondi.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OperationVariables } from '@apollo/client/core/index.js';
|
|
2
2
|
import { Maybe } from 'graphql/jsutils/Maybe';
|
|
3
3
|
import { Account, Address, Hash, Hex, TransactionReceipt } from 'viem';
|
|
4
|
-
import { Auction } from './blockchain';
|
|
4
|
+
import { Auction, AuctionV8 } from './blockchain';
|
|
5
5
|
import { Api, OrderInput, Props as ApiProps } from './clients/api';
|
|
6
6
|
import { Contracts, GondiPublicClient, Wallet } from './clients/contracts';
|
|
7
7
|
import { CrossCurrencyRenegotiationInput, CrossCurrencyRenegotiationQuote } from './clients/contracts/CrossCurrencyRenegotiation';
|
|
@@ -3912,46 +3912,6 @@ export declare class Gondi {
|
|
|
3912
3912
|
transactionIndex: number;
|
|
3913
3913
|
type: import("viem").TransactionType;
|
|
3914
3914
|
loanId: bigint;
|
|
3915
|
-
} | {
|
|
3916
|
-
blobGasPrice?: bigint | undefined;
|
|
3917
|
-
blobGasUsed?: bigint | undefined;
|
|
3918
|
-
blockHash: Hash;
|
|
3919
|
-
blockNumber: bigint;
|
|
3920
|
-
blockTimestamp?: bigint | undefined;
|
|
3921
|
-
contractAddress: Address | null | undefined;
|
|
3922
|
-
cumulativeGasUsed: bigint;
|
|
3923
|
-
effectiveGasPrice: bigint;
|
|
3924
|
-
from: Address;
|
|
3925
|
-
gasUsed: bigint;
|
|
3926
|
-
logs: import("viem").Log<bigint, number, false>[];
|
|
3927
|
-
logsBloom: Hex;
|
|
3928
|
-
root?: Hash | undefined;
|
|
3929
|
-
status: "success" | "reverted";
|
|
3930
|
-
to: Address | null;
|
|
3931
|
-
transactionHash: Hash;
|
|
3932
|
-
transactionIndex: number;
|
|
3933
|
-
type: import("viem").TransactionType;
|
|
3934
|
-
loanId: bigint;
|
|
3935
|
-
} | {
|
|
3936
|
-
blobGasPrice?: bigint | undefined;
|
|
3937
|
-
blobGasUsed?: bigint | undefined;
|
|
3938
|
-
blockHash: Hash;
|
|
3939
|
-
blockNumber: bigint;
|
|
3940
|
-
blockTimestamp?: bigint | undefined;
|
|
3941
|
-
contractAddress: Address | null | undefined;
|
|
3942
|
-
cumulativeGasUsed: bigint;
|
|
3943
|
-
effectiveGasPrice: bigint;
|
|
3944
|
-
from: Address;
|
|
3945
|
-
gasUsed: bigint;
|
|
3946
|
-
logs: import("viem").Log<bigint, number, false>[];
|
|
3947
|
-
logsBloom: Hex;
|
|
3948
|
-
root?: Hash | undefined;
|
|
3949
|
-
status: "success" | "reverted";
|
|
3950
|
-
to: Address | null;
|
|
3951
|
-
transactionHash: Hash;
|
|
3952
|
-
transactionIndex: number;
|
|
3953
|
-
type: import("viem").TransactionType;
|
|
3954
|
-
loanId: bigint;
|
|
3955
3915
|
}>;
|
|
3956
3916
|
}>;
|
|
3957
3917
|
placeBid({ collectionContractAddress, tokenId, bid, auction, }: {
|
|
@@ -4142,7 +4102,7 @@ export declare class Gondi {
|
|
|
4142
4102
|
}>;
|
|
4143
4103
|
}>;
|
|
4144
4104
|
getAuctionRemainingLockupSeconds({ auction, }: {
|
|
4145
|
-
auction: Pick<Auction, 'startTime' | 'loanAddress'
|
|
4105
|
+
auction: Pick<Auction, 'startTime' | 'loanAddress' | 'loanId'> & Partial<Pick<AuctionV8, 'buyoutWindow'>>;
|
|
4146
4106
|
}): Promise<number>;
|
|
4147
4107
|
/**
|
|
4148
4108
|
* The bid refund in `token` that the auction liquidator of the loan contract at `loanAddress`
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Address, PublicClient } from 'viem';
|
|
2
|
+
import { Auction } from '../blockchain';
|
|
3
|
+
import { auctionWithBuyoutLoanLiquidatorAbi as auctionWithBuyoutLoanLiquidatorAbiV6 } from '../generated/blockchain/v6';
|
|
4
|
+
import { auctionWithBuyoutLoanLiquidatorAbi as auctionWithBuyoutLoanLiquidatorAbiV8 } from '../generated/blockchain/v8';
|
|
5
|
+
/** The fields that name an auction: they are set when it starts and no bid changes them. */
|
|
6
|
+
export type AuctionIdentity = Pick<Auction, 'loanAddress' | 'loanId' | 'startTime'>;
|
|
7
|
+
type AuctionReader = Pick<PublicClient, 'chain' | 'getBlock' | 'getChainId' | 'getContractEvents'>;
|
|
8
|
+
/**
|
|
9
|
+
* Reads an auction's current struct from its liquidator, with the NFT it auctions.
|
|
10
|
+
*
|
|
11
|
+
* The liquidator stores only the hash of the struct and expects every call to pass the struct
|
|
12
|
+
* back, so a struct held by the caller goes stale with the next bid anyone places. This rebuilds
|
|
13
|
+
* it from the auction's `LoanLiquidationStarted` event, which carries the whole struct as it
|
|
14
|
+
* started, and its latest `BidPlaced` event, which sets `highestBid`, `highestBidder` and,
|
|
15
|
+
* through its block's timestamp, `lastBidTime`; no other call changes a live auction. On v3.2
|
|
16
|
+
* the struct also carries `loanHash` and `buyoutWindow`, which only the event has.
|
|
17
|
+
*
|
|
18
|
+
* IMPLEMENTATION NOTE: neither event has an indexed argument, so viem's `getContractEvents`
|
|
19
|
+
* (https://viem.sh/docs/contract/getContractEvents) reads every event the liquidator emitted
|
|
20
|
+
* from the auction's start block onwards, and the auction's own are picked by loan contract and
|
|
21
|
+
* loan id; events before `startTime` are skipped, so starting the scan early is harmless. Some RPC
|
|
22
|
+
* providers cap the block range of `eth_getLogs`
|
|
23
|
+
* (https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getlogs), so an auction that
|
|
24
|
+
* started long ago needs a provider without that cap: callers use this only when the struct they
|
|
25
|
+
* hold is missing or stale (`writeWithCurrentAuction`).
|
|
26
|
+
*/
|
|
27
|
+
export declare const readAuction: ({ client, address, abi, auction, }: {
|
|
28
|
+
client: AuctionReader;
|
|
29
|
+
address: Address;
|
|
30
|
+
abi: typeof auctionWithBuyoutLoanLiquidatorAbiV6 | typeof auctionWithBuyoutLoanLiquidatorAbiV8;
|
|
31
|
+
auction: AuctionIdentity;
|
|
32
|
+
}) => Promise<{
|
|
33
|
+
auction: {
|
|
34
|
+
loanAddress: `0x${string}`;
|
|
35
|
+
loanId: bigint;
|
|
36
|
+
highestBid: bigint;
|
|
37
|
+
triggerFee: bigint;
|
|
38
|
+
minBid: bigint;
|
|
39
|
+
highestBidder: `0x${string}`;
|
|
40
|
+
duration: bigint;
|
|
41
|
+
asset: `0x${string}`;
|
|
42
|
+
startTime: bigint;
|
|
43
|
+
originator: `0x${string}`;
|
|
44
|
+
lastBidTime: bigint;
|
|
45
|
+
} | {
|
|
46
|
+
loanAddress: `0x${string}`;
|
|
47
|
+
loanId: bigint;
|
|
48
|
+
highestBid: bigint;
|
|
49
|
+
triggerFee: bigint;
|
|
50
|
+
minBid: bigint;
|
|
51
|
+
highestBidder: `0x${string}`;
|
|
52
|
+
duration: bigint;
|
|
53
|
+
asset: `0x${string}`;
|
|
54
|
+
startTime: bigint;
|
|
55
|
+
originator: `0x${string}`;
|
|
56
|
+
lastBidTime: bigint;
|
|
57
|
+
loanHash: `0x${string}`;
|
|
58
|
+
buyoutWindow: bigint;
|
|
59
|
+
};
|
|
60
|
+
collectionContractAddress: `0x${string}`;
|
|
61
|
+
tokenId: bigint;
|
|
62
|
+
}>;
|
|
63
|
+
/**
|
|
64
|
+
* Whether `error` is the liquidator's revert for an auction struct that no longer hashes to the
|
|
65
|
+
* one it stores, the revert a struct read before someone else's bid gets.
|
|
66
|
+
*
|
|
67
|
+
* IMPLEMENTATION NOTE: viem wraps a simulation's revert in a `ContractFunctionRevertedError`
|
|
68
|
+
* whose `data.errorName` is the custom error decoded with the contract's ABI, and `walk` finds it
|
|
69
|
+
* in the error's cause chain (https://viem.sh/docs/contract/simulateContract#handling-custom-errors).
|
|
70
|
+
*/
|
|
71
|
+
export declare const isInvalidHashAuctionError: (error: unknown) => boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Sends `write` with the auction the caller holds, and again with the one on chain
|
|
74
|
+
* (`readCurrent`) when the liquidator rejects it as stale, or straight away when the caller holds
|
|
75
|
+
* none (`held` is undefined). A fresh struct, the usual case, costs no read.
|
|
76
|
+
*/
|
|
77
|
+
export declare const writeWithCurrentAuction: <TAuction, TResult>({ held, readCurrent, write, }: {
|
|
78
|
+
held: TAuction | undefined;
|
|
79
|
+
readCurrent: () => Promise<TAuction>;
|
|
80
|
+
write: (auction: TAuction) => Promise<TResult>;
|
|
81
|
+
}) => Promise<TResult>;
|
|
82
|
+
export {};
|
|
@@ -41,4 +41,21 @@ interface ReceiptWaitOptions {
|
|
|
41
41
|
* `WaitForTransactionReceiptTimeoutError` with the transaction hash.
|
|
42
42
|
*/
|
|
43
43
|
export declare const withRetriedReceiptWait: <TClient extends ReceiptWaiter>(client: TClient, options?: ReceiptWaitOptions) => TClient;
|
|
44
|
+
type BlockReader = Pick<PublicClient, 'chain' | 'getBlock' | 'getChainId'>;
|
|
45
|
+
/**
|
|
46
|
+
* Returns a block number at or before the block a call that recorded `block.timestamp` as
|
|
47
|
+
* `timestamp` (seconds) was mined in, in one read of the latest block.
|
|
48
|
+
*
|
|
49
|
+
* No more blocks than the elapsed time over the chain's shortest block time can have been mined
|
|
50
|
+
* since `timestamp`, so stepping back that many blocks from the latest one never lands after it.
|
|
51
|
+
* The block is not exact: on a chain whose blocks are slower than that floor it lands earlier,
|
|
52
|
+
* which only widens the range a caller scans from it.
|
|
53
|
+
*
|
|
54
|
+
* IMPLEMENTATION NOTE: viem's `getBlock` reads the latest block when called without a block
|
|
55
|
+
* number, and its `timestamp` is the block's Unix time in seconds as a `bigint`
|
|
56
|
+
* (https://viem.sh/docs/actions/public/getBlock#returns). `client.chain` is unset on a client
|
|
57
|
+
* built without one, so the chain id then comes from `getChainId`
|
|
58
|
+
* (https://viem.sh/docs/actions/public/getChainId).
|
|
59
|
+
*/
|
|
60
|
+
export declare const getBlockNumberAtOrBefore: (client: BlockReader, timestamp: bigint) => Promise<bigint>;
|
|
44
61
|
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ContractFunctionExecutionError } from 'viem';
|
|
2
|
+
type LiquidatorErrorName = 'InvalidHashAuctionError' | 'AuctionOverError';
|
|
3
|
+
/**
|
|
4
|
+
* The error viem's `simulateContract` throws when a liquidator call reverts with `errorName`: a
|
|
5
|
+
* `ContractFunctionRevertedError` with the decoded error, wrapped in the execution error.
|
|
6
|
+
*/
|
|
7
|
+
export declare const liquidatorRevert: (errorName: LiquidatorErrorName) => ContractFunctionExecutionError;
|
|
8
|
+
export {};
|