@ercworldio/blockchain-shared 1.0.3-dev.3-PROJ-1296.35 → 1.0.3-dev.3-PROJ-1296.36
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.
|
@@ -2,7 +2,7 @@ import { escrow } from "./typechain-types/contracts";
|
|
|
2
2
|
import { Signer, Provider, ethers } from "ethers";
|
|
3
3
|
import { ErrorObject, EscrowErrorMessage } from "./EscrowErrors";
|
|
4
4
|
import Errors from "../errors/TransactionsErrors";
|
|
5
|
-
import { BatchSweepErc20Payload, BatchWithdrawPayload, FundWalletsPayload, OpType, TransactionStatus } from "./types/escrow";
|
|
5
|
+
import { BatchSweepErc20Payload, BatchWithdrawPayload, ExecuteWithdrawalPayload, FundWalletsPayload, OpType, TransactionStatus } from "./types/escrow";
|
|
6
6
|
/**
|
|
7
7
|
* Class to interact with the escrow contract
|
|
8
8
|
* @author @0xgio - Georgio Diab
|
|
@@ -68,6 +68,67 @@ declare class EscrowInteraction extends Errors {
|
|
|
68
68
|
fee?: undefined;
|
|
69
69
|
}>;
|
|
70
70
|
get_used_request_ids(ids: number[]): Promise<number[]>;
|
|
71
|
+
batch_withdraw(payloads: BatchWithdrawPayload[], token_price: number): Promise<{
|
|
72
|
+
status: TransactionStatus;
|
|
73
|
+
transactionHash: null;
|
|
74
|
+
receipt: null;
|
|
75
|
+
data: {
|
|
76
|
+
success: number[];
|
|
77
|
+
failed: number[];
|
|
78
|
+
dropped: number[];
|
|
79
|
+
cancel: number[];
|
|
80
|
+
};
|
|
81
|
+
fee?: undefined;
|
|
82
|
+
feePerTx?: undefined;
|
|
83
|
+
feePerTxDecimals?: undefined;
|
|
84
|
+
feePerTxUsd?: undefined;
|
|
85
|
+
feePerTxUsdDecimals?: undefined;
|
|
86
|
+
executed_at?: undefined;
|
|
87
|
+
error?: undefined;
|
|
88
|
+
} | {
|
|
89
|
+
status: TransactionStatus;
|
|
90
|
+
transactionHash: string;
|
|
91
|
+
fee: bigint;
|
|
92
|
+
feePerTx: bigint;
|
|
93
|
+
feePerTxDecimals: number;
|
|
94
|
+
feePerTxUsd: bigint;
|
|
95
|
+
feePerTxUsdDecimals: number;
|
|
96
|
+
receipt: ethers.ContractTransactionReceipt;
|
|
97
|
+
executed_at: Date;
|
|
98
|
+
data: {
|
|
99
|
+
success: number[];
|
|
100
|
+
failed: number[];
|
|
101
|
+
dropped: number[];
|
|
102
|
+
cancel: number[];
|
|
103
|
+
};
|
|
104
|
+
error?: undefined;
|
|
105
|
+
} | {
|
|
106
|
+
status: TransactionStatus;
|
|
107
|
+
transactionHash: null;
|
|
108
|
+
receipt: null;
|
|
109
|
+
executed_at: Date;
|
|
110
|
+
error: {
|
|
111
|
+
name: "ContractBusy" | "ContractPaused" | "InvalidSignature" | "SignatureAlreadyUsed" | "ZeroValue" | "ZeroAddress" | "RequestAlreadyFulfilled" | "EtherDirectTransferNotAllowed" | "DepositOnlyERC20" | "TokenNotAllowed" | "InsufficientBalance" | "InsufficientReserves" | "TransferError" | "NotAdmin" | "NotAuthorized" | "ExceedsLimit" | "ExceedsMax" | "UnknownError" | "InvalidNonce" | "TimelockConfigGroupNotSet" | "ConfigGroupNotSet" | "TimelockConfigNotSet" | "CommitmentNotFound" | "AlreadyCreatedTransaction" | "AccountAlreadyHasSignerRole" | "InvalidOperation" | "InvalidConfig" | "InvalidSignatures" | "AdminMultisigConfigNotSet" | "MultisigConfigNotSet" | "RequireTreasuryReceiverRole" | "InvalidMultiSig" | "RequireMultiSig" | "TimelockNotExpired" | "InsufficientExecutiveSigs" | "InsufficientManagerSigs";
|
|
112
|
+
message: string;
|
|
113
|
+
data?: any;
|
|
114
|
+
};
|
|
115
|
+
data: {
|
|
116
|
+
success: number[];
|
|
117
|
+
failed: number[];
|
|
118
|
+
dropped: number[];
|
|
119
|
+
cancel: number[];
|
|
120
|
+
};
|
|
121
|
+
fee?: undefined;
|
|
122
|
+
feePerTx?: undefined;
|
|
123
|
+
feePerTxDecimals?: undefined;
|
|
124
|
+
feePerTxUsd?: undefined;
|
|
125
|
+
feePerTxUsdDecimals?: undefined;
|
|
126
|
+
}>;
|
|
127
|
+
execute_withdrawal(payload: ExecuteWithdrawalPayload): Promise<{
|
|
128
|
+
status: TransactionStatus;
|
|
129
|
+
transactionHash: string;
|
|
130
|
+
fee: bigint;
|
|
131
|
+
}>;
|
|
71
132
|
admin_batch_withdraw(payloads: BatchWithdrawPayload[], token_price: number): Promise<{
|
|
72
133
|
status: TransactionStatus;
|
|
73
134
|
transactionHash: null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Escrow.d.ts","sourceRoot":"","sources":["../../src/contracts/Escrow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAqC,MAAM,EAA2B,MAAM,QAAQ,CAAC;AAG9G,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAqB,MAAM,gBAAgB,CAAC;AACpF,OAAO,MAAM,MAAM,8BAA8B,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAiB,kBAAkB,EAAiB,MAAM,EAAa,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Escrow.d.ts","sourceRoot":"","sources":["../../src/contracts/Escrow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAqC,MAAM,EAA2B,MAAM,QAAQ,CAAC;AAG9G,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAqB,MAAM,gBAAgB,CAAC;AACpF,OAAO,MAAM,MAAM,8BAA8B,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAiB,wBAAwB,EAAE,kBAAkB,EAAiB,MAAM,EAAa,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGhM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AM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE;;;;;;;;;;;;;;;;;YAyCpC,aAAa;YAiCb,aAAa;IA0C3B,iBAAiB,CAAC,KAAK,EAAE,WAAW;CAkBvC;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -162,6 +162,97 @@ class EscrowInteraction extends TransactionsErrors_1.default {
|
|
|
162
162
|
}
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
|
+
/// Withdrawal requests with no timelock (no scheduling needed)
|
|
166
|
+
batch_withdraw(payloads, token_price) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
let success = [];
|
|
169
|
+
let failed = [];
|
|
170
|
+
let dropped = [];
|
|
171
|
+
let cancel = [];
|
|
172
|
+
const executed_at = new Date();
|
|
173
|
+
try {
|
|
174
|
+
if (!this.signer)
|
|
175
|
+
throw new Error("Signer not set");
|
|
176
|
+
if (!payloads.length)
|
|
177
|
+
return {
|
|
178
|
+
status: escrow_1.TransactionStatus.FAILED,
|
|
179
|
+
transactionHash: null,
|
|
180
|
+
receipt: null,
|
|
181
|
+
data: {
|
|
182
|
+
success,
|
|
183
|
+
failed,
|
|
184
|
+
dropped,
|
|
185
|
+
cancel
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
let tx = yield this.escrowContract.batchWithdrawWithTimelock(payloads);
|
|
189
|
+
let receipt = yield tx.wait(this.CONFIRMATIONS);
|
|
190
|
+
if (!receipt)
|
|
191
|
+
throw new Error(this.UnexpectedError("Failed to retrieve transaction receipt"));
|
|
192
|
+
success = payloads.map(p => p.requestId);
|
|
193
|
+
const fee_per_transaction = receipt.fee / BigInt(payloads.length);
|
|
194
|
+
const fee_per_tx_decimals = parseFloat((0, ethers_1.formatEther)(fee_per_transaction));
|
|
195
|
+
const fee_per_tx_usd_decimals = fee_per_tx_decimals * token_price;
|
|
196
|
+
const fee_per_tx_usd = (0, ethers_1.parseUnits)(fee_per_tx_decimals.toFixed(5), 6);
|
|
197
|
+
return {
|
|
198
|
+
status: escrow_1.TransactionStatus.SUCCESS,
|
|
199
|
+
transactionHash: tx.hash,
|
|
200
|
+
fee: receipt.fee,
|
|
201
|
+
feePerTx: fee_per_transaction,
|
|
202
|
+
feePerTxDecimals: fee_per_tx_decimals,
|
|
203
|
+
feePerTxUsd: fee_per_tx_usd,
|
|
204
|
+
feePerTxUsdDecimals: fee_per_tx_usd_decimals,
|
|
205
|
+
receipt,
|
|
206
|
+
executed_at,
|
|
207
|
+
data: {
|
|
208
|
+
success,
|
|
209
|
+
failed,
|
|
210
|
+
dropped,
|
|
211
|
+
cancel
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
const errorResult = this.decodeRevertError(e);
|
|
217
|
+
return {
|
|
218
|
+
status: escrow_1.TransactionStatus.FAILED,
|
|
219
|
+
transactionHash: null,
|
|
220
|
+
receipt: null,
|
|
221
|
+
executed_at,
|
|
222
|
+
error: Object.assign({}, errorResult),
|
|
223
|
+
data: {
|
|
224
|
+
success,
|
|
225
|
+
failed,
|
|
226
|
+
dropped,
|
|
227
|
+
cancel
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
// Execute a withdrawal that has a timelock (scheduling needed)
|
|
234
|
+
execute_withdrawal(payload) {
|
|
235
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
236
|
+
const executed_at = new Date();
|
|
237
|
+
try {
|
|
238
|
+
if (!this.signer)
|
|
239
|
+
throw new Error("Signer not set");
|
|
240
|
+
const tx = yield this.escrowContract.executeWithdrawal(payload.amount, payload.requestId, payload.tokenAddress, payload.receiverAddress, payload.executeAt);
|
|
241
|
+
const receipt = yield tx.wait(this.CONFIRMATIONS);
|
|
242
|
+
if (!receipt)
|
|
243
|
+
throw new Error(this.UnexpectedError("Failed to retrieve transaction receipt"));
|
|
244
|
+
return {
|
|
245
|
+
status: escrow_1.TransactionStatus.SUCCESS,
|
|
246
|
+
transactionHash: tx.hash,
|
|
247
|
+
fee: receipt.fee,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
catch (e) {
|
|
251
|
+
const errorResult = this.decodeRevertError(e);
|
|
252
|
+
throw errorResult;
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
165
256
|
admin_batch_withdraw(payloads, token_price) {
|
|
166
257
|
return __awaiter(this, void 0, void 0, function* () {
|
|
167
258
|
let success = [];
|
|
@@ -42,5 +42,13 @@ export interface BatchWithdrawPayload {
|
|
|
42
42
|
requestId: number;
|
|
43
43
|
tokenAddress: string;
|
|
44
44
|
receiverAddress: string;
|
|
45
|
+
signatures: Signature[];
|
|
46
|
+
}
|
|
47
|
+
export interface ExecuteWithdrawalPayload {
|
|
48
|
+
amount: bigint;
|
|
49
|
+
requestId: number;
|
|
50
|
+
tokenAddress: string;
|
|
51
|
+
receiverAddress: string;
|
|
52
|
+
executeAt: number;
|
|
45
53
|
}
|
|
46
54
|
//# sourceMappingURL=escrow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"escrow.d.ts","sourceRoot":"","sources":["../../../src/contracts/types/escrow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,oBAAY,SAAS;IACjB,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,KAAK,KAAK;CACb;AAED,MAAM,WAAW,kBAAkB;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,sBAAsB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,oBAAY,iBAAiB;IACzB,OAAO,YAAY;IACnB,MAAM,WAAW;CACpB;AAED,MAAM,WAAW,SAAS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