@chainflip/sdk 0.1.20 → 0.2.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/{chunk-VOWQWFJD.mjs → chunk-UBMU3BTF.mjs} +21 -23
- package/dist/{enums-3131916c.d.ts → contracts-646d1727.d.ts} +10 -1
- package/dist/funding.d.mts +5 -5
- package/dist/funding.d.ts +5 -5
- package/dist/funding.js +51 -64
- package/dist/funding.mjs +36 -47
- package/dist/swap.d.mts +47 -48
- package/dist/swap.d.ts +47 -48
- package/dist/swap.js +66 -90
- package/dist/swap.mjs +54 -78
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Interface, Contract } from 'ethers';
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -144,10 +144,10 @@ var _abi = [
|
|
|
144
144
|
];
|
|
145
145
|
var _ERC20__factory = class _ERC20__factory {
|
|
146
146
|
static createInterface() {
|
|
147
|
-
return new
|
|
147
|
+
return new Interface(_abi);
|
|
148
148
|
}
|
|
149
|
-
static connect(address,
|
|
150
|
-
return new Contract(address, _abi,
|
|
149
|
+
static connect(address, runner) {
|
|
150
|
+
return new Contract(address, _abi, runner);
|
|
151
151
|
}
|
|
152
152
|
};
|
|
153
153
|
__name(_ERC20__factory, "ERC20__factory");
|
|
@@ -815,10 +815,10 @@ var _abi2 = [
|
|
|
815
815
|
];
|
|
816
816
|
var _StateChainGateway__factory = class _StateChainGateway__factory {
|
|
817
817
|
static createInterface() {
|
|
818
|
-
return new
|
|
818
|
+
return new Interface(_abi2);
|
|
819
819
|
}
|
|
820
|
-
static connect(address,
|
|
821
|
-
return new Contract(address, _abi2,
|
|
820
|
+
static connect(address, runner) {
|
|
821
|
+
return new Contract(address, _abi2, runner);
|
|
822
822
|
}
|
|
823
823
|
};
|
|
824
824
|
__name(_StateChainGateway__factory, "StateChainGateway__factory");
|
|
@@ -2039,10 +2039,10 @@ var _abi3 = [
|
|
|
2039
2039
|
];
|
|
2040
2040
|
var _Vault__factory = class _Vault__factory {
|
|
2041
2041
|
static createInterface() {
|
|
2042
|
-
return new
|
|
2042
|
+
return new Interface(_abi3);
|
|
2043
2043
|
}
|
|
2044
|
-
static connect(address,
|
|
2045
|
-
return new Contract(address, _abi3,
|
|
2044
|
+
static connect(address, runner) {
|
|
2045
|
+
return new Contract(address, _abi3, runner);
|
|
2046
2046
|
}
|
|
2047
2047
|
};
|
|
2048
2048
|
__name(_Vault__factory, "Vault__factory");
|
|
@@ -2105,6 +2105,10 @@ var isTokenSwap = /* @__PURE__ */ __name((params) => params.srcAsset !== Assets.
|
|
|
2105
2105
|
var isTokenCall = /* @__PURE__ */ __name((params) => params.srcAsset !== Assets.ETH, "isTokenCall");
|
|
2106
2106
|
|
|
2107
2107
|
// ../shared/src/contracts.ts
|
|
2108
|
+
var extractOverrides = /* @__PURE__ */ __name((transactionOverrides) => {
|
|
2109
|
+
const { wait, ...ethersOverrides } = transactionOverrides;
|
|
2110
|
+
return ethersOverrides;
|
|
2111
|
+
}, "extractOverrides");
|
|
2108
2112
|
var getTokenContractAddress = /* @__PURE__ */ __name((asset, network) => {
|
|
2109
2113
|
assert(network !== ChainflipNetworks.mainnet, "Mainnet is not yet supported");
|
|
2110
2114
|
if (asset === Assets.FLIP)
|
|
@@ -2122,20 +2126,15 @@ var checkAllowance = /* @__PURE__ */ __name(async (amount, spenderAddress, erc20
|
|
|
2122
2126
|
const allowance = await erc20.allowance(signerAddress, spenderAddress);
|
|
2123
2127
|
return {
|
|
2124
2128
|
allowance,
|
|
2125
|
-
isAllowable: allowance
|
|
2129
|
+
isAllowable: allowance >= amount,
|
|
2126
2130
|
erc20
|
|
2127
2131
|
};
|
|
2128
2132
|
}, "checkAllowance");
|
|
2129
|
-
var approve = /* @__PURE__ */ __name(async (amount, spenderAddress, erc20, allowance,
|
|
2130
|
-
|
|
2131
|
-
const allowanceBigNumber = BigNumber.from(allowance);
|
|
2132
|
-
if (allowanceBigNumber.gte(amountBigNumber))
|
|
2133
|
+
var approve = /* @__PURE__ */ __name(async (amount, spenderAddress, erc20, allowance, txOpts) => {
|
|
2134
|
+
if (allowance >= amount)
|
|
2133
2135
|
return null;
|
|
2134
|
-
const
|
|
2135
|
-
|
|
2136
|
-
nonce
|
|
2137
|
-
});
|
|
2138
|
-
return tx.wait(1);
|
|
2136
|
+
const transaction = await erc20.approve(spenderAddress, amount - allowance, extractOverrides(txOpts));
|
|
2137
|
+
return transaction.wait(txOpts.wait);
|
|
2139
2138
|
}, "approve");
|
|
2140
2139
|
var getVaultManagerContractAddress = /* @__PURE__ */ __name((network) => {
|
|
2141
2140
|
assert(network !== ChainflipNetworks.mainnet, "Mainnet is not yet supported");
|
|
@@ -2144,8 +2143,7 @@ var getVaultManagerContractAddress = /* @__PURE__ */ __name((network) => {
|
|
|
2144
2143
|
var getFlipBalance = /* @__PURE__ */ __name(async (network, signer) => {
|
|
2145
2144
|
const flipAddress = getTokenContractAddress("FLIP", network);
|
|
2146
2145
|
const flip = ERC20__factory.connect(flipAddress, signer);
|
|
2147
|
-
|
|
2148
|
-
return balance.toBigInt();
|
|
2146
|
+
return flip.balanceOf(await signer.getAddress());
|
|
2149
2147
|
}, "getFlipBalance");
|
|
2150
2148
|
|
|
2151
|
-
export { Assets, ChainflipNetworks, Chains, StateChainGateway__factory, Vault__factory, __name, __publicField, approve, assert, assetChains, assetContractIds, assetDecimals, chainAssets, chainContractIds, checkAllowance, getFlipBalance, getMinimumDepositAmount, getMinimumSwapAmount, getStateChainGatewayContractAddress, getTokenContractAddress, getVaultManagerContractAddress, isString, isTestnet, isTokenCall, isTokenSwap };
|
|
2149
|
+
export { Assets, ChainflipNetworks, Chains, StateChainGateway__factory, Vault__factory, __name, __publicField, approve, assert, assetChains, assetContractIds, assetDecimals, chainAssets, chainContractIds, checkAllowance, extractOverrides, getFlipBalance, getMinimumDepositAmount, getMinimumSwapAmount, getStateChainGatewayContractAddress, getTokenContractAddress, getVaultManagerContractAddress, isString, isTestnet, isTokenCall, isTokenSwap };
|
|
@@ -29,4 +29,13 @@ declare const chainAssets: {
|
|
|
29
29
|
};
|
|
30
30
|
declare const chainContractIds: Record<Chain, number>;
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
type TransactionOptions = {
|
|
33
|
+
gasLimit?: bigint;
|
|
34
|
+
gasPrice?: bigint;
|
|
35
|
+
maxFeePerGas?: bigint;
|
|
36
|
+
maxPriorityFeePerGas?: bigint;
|
|
37
|
+
nonce?: number;
|
|
38
|
+
wait?: number;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { Asset as A, Chain as C, TransactionOptions as T, ChainflipNetwork as a, Chains as b, chainAssets as c, Assets as d, ChainflipNetworks as e, assetChains as f, assetDecimals as g, assetContractIds as h, chainContractIds as i };
|
package/dist/funding.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Signer } from 'ethers';
|
|
2
|
-
import { a as ChainflipNetwork } from './
|
|
2
|
+
import { T as TransactionOptions, a as ChainflipNetwork } from './contracts-646d1727.js';
|
|
3
3
|
|
|
4
4
|
type SDKOptions = {
|
|
5
5
|
network?: Exclude<ChainflipNetwork, 'mainnet'>;
|
|
@@ -9,12 +9,12 @@ type TransactionHash = string;
|
|
|
9
9
|
declare class FundingSDK {
|
|
10
10
|
private readonly options;
|
|
11
11
|
constructor(options: SDKOptions);
|
|
12
|
-
fundStateChainAccount(accountId: `0x${string}`, amount:
|
|
13
|
-
executeRedemption(accountId: `0x${string}
|
|
12
|
+
fundStateChainAccount(accountId: `0x${string}`, amount: bigint, txOpts?: TransactionOptions): Promise<TransactionHash>;
|
|
13
|
+
executeRedemption(accountId: `0x${string}`, txOpts?: TransactionOptions): Promise<TransactionHash>;
|
|
14
14
|
getMinimumFunding(): Promise<bigint>;
|
|
15
|
-
getRedemptionDelay(): Promise<
|
|
15
|
+
getRedemptionDelay(): Promise<bigint>;
|
|
16
16
|
getFlipBalance(): Promise<bigint>;
|
|
17
|
-
approveStateChainGateway(amount: bigint
|
|
17
|
+
approveStateChainGateway(amount: bigint, txOpts?: TransactionOptions): Promise<TransactionHash | null>;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export { FundingSDK };
|
package/dist/funding.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Signer } from 'ethers';
|
|
2
|
-
import { a as ChainflipNetwork } from './
|
|
2
|
+
import { T as TransactionOptions, a as ChainflipNetwork } from './contracts-646d1727.js';
|
|
3
3
|
|
|
4
4
|
type SDKOptions = {
|
|
5
5
|
network?: Exclude<ChainflipNetwork, 'mainnet'>;
|
|
@@ -9,12 +9,12 @@ type TransactionHash = string;
|
|
|
9
9
|
declare class FundingSDK {
|
|
10
10
|
private readonly options;
|
|
11
11
|
constructor(options: SDKOptions);
|
|
12
|
-
fundStateChainAccount(accountId: `0x${string}`, amount:
|
|
13
|
-
executeRedemption(accountId: `0x${string}
|
|
12
|
+
fundStateChainAccount(accountId: `0x${string}`, amount: bigint, txOpts?: TransactionOptions): Promise<TransactionHash>;
|
|
13
|
+
executeRedemption(accountId: `0x${string}`, txOpts?: TransactionOptions): Promise<TransactionHash>;
|
|
14
14
|
getMinimumFunding(): Promise<bigint>;
|
|
15
|
-
getRedemptionDelay(): Promise<
|
|
15
|
+
getRedemptionDelay(): Promise<bigint>;
|
|
16
16
|
getFlipBalance(): Promise<bigint>;
|
|
17
|
-
approveStateChainGateway(amount: bigint
|
|
17
|
+
approveStateChainGateway(amount: bigint, txOpts?: TransactionOptions): Promise<TransactionHash | null>;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export { FundingSDK };
|
package/dist/funding.js
CHANGED
|
@@ -80,10 +80,10 @@ var _abi = [
|
|
|
80
80
|
];
|
|
81
81
|
var _ERC20__factory = class _ERC20__factory {
|
|
82
82
|
static createInterface() {
|
|
83
|
-
return new ethers.
|
|
83
|
+
return new ethers.Interface(_abi);
|
|
84
84
|
}
|
|
85
|
-
static connect(address,
|
|
86
|
-
return new ethers.Contract(address, _abi,
|
|
85
|
+
static connect(address, runner) {
|
|
86
|
+
return new ethers.Contract(address, _abi, runner);
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
89
|
__name(_ERC20__factory, "ERC20__factory");
|
|
@@ -751,10 +751,10 @@ var _abi2 = [
|
|
|
751
751
|
];
|
|
752
752
|
var _StateChainGateway__factory = class _StateChainGateway__factory {
|
|
753
753
|
static createInterface() {
|
|
754
|
-
return new ethers.
|
|
754
|
+
return new ethers.Interface(_abi2);
|
|
755
755
|
}
|
|
756
|
-
static connect(address,
|
|
757
|
-
return new ethers.Contract(address, _abi2,
|
|
756
|
+
static connect(address, runner) {
|
|
757
|
+
return new ethers.Contract(address, _abi2, runner);
|
|
758
758
|
}
|
|
759
759
|
};
|
|
760
760
|
__name(_StateChainGateway__factory, "StateChainGateway__factory");
|
|
@@ -877,6 +877,10 @@ function assert(condition, message) {
|
|
|
877
877
|
__name(assert, "assert");
|
|
878
878
|
|
|
879
879
|
// ../shared/src/contracts.ts
|
|
880
|
+
var extractOverrides = /* @__PURE__ */ __name((transactionOverrides) => {
|
|
881
|
+
const { wait, ...ethersOverrides } = transactionOverrides;
|
|
882
|
+
return ethersOverrides;
|
|
883
|
+
}, "extractOverrides");
|
|
880
884
|
var getTokenContractAddress = /* @__PURE__ */ __name((asset, network) => {
|
|
881
885
|
assert(network !== ChainflipNetworks.mainnet, "Mainnet is not yet supported");
|
|
882
886
|
if (asset === Assets.FLIP)
|
|
@@ -894,71 +898,62 @@ var checkAllowance = /* @__PURE__ */ __name(async (amount, spenderAddress, erc20
|
|
|
894
898
|
const allowance = await erc20.allowance(signerAddress, spenderAddress);
|
|
895
899
|
return {
|
|
896
900
|
allowance,
|
|
897
|
-
isAllowable: allowance
|
|
901
|
+
isAllowable: allowance >= amount,
|
|
898
902
|
erc20
|
|
899
903
|
};
|
|
900
904
|
}, "checkAllowance");
|
|
901
|
-
var approve = /* @__PURE__ */ __name(async (amount, spenderAddress, erc20, allowance,
|
|
902
|
-
|
|
903
|
-
const allowanceBigNumber = ethers.BigNumber.from(allowance);
|
|
904
|
-
if (allowanceBigNumber.gte(amountBigNumber))
|
|
905
|
+
var approve = /* @__PURE__ */ __name(async (amount, spenderAddress, erc20, allowance, txOpts) => {
|
|
906
|
+
if (allowance >= amount)
|
|
905
907
|
return null;
|
|
906
|
-
const
|
|
907
|
-
|
|
908
|
-
nonce
|
|
909
|
-
});
|
|
910
|
-
return tx.wait(1);
|
|
908
|
+
const transaction = await erc20.approve(spenderAddress, amount - allowance, extractOverrides(txOpts));
|
|
909
|
+
return transaction.wait(txOpts.wait);
|
|
911
910
|
}, "approve");
|
|
912
911
|
var getFlipBalance = /* @__PURE__ */ __name(async (network, signer) => {
|
|
913
912
|
const flipAddress = getTokenContractAddress("FLIP", network);
|
|
914
913
|
const flip = ERC20__factory.connect(flipAddress, signer);
|
|
915
|
-
|
|
916
|
-
return balance.toBigInt();
|
|
914
|
+
return flip.balanceOf(await signer.getAddress());
|
|
917
915
|
}, "getFlipBalance");
|
|
918
916
|
|
|
919
917
|
// ../shared/src/stateChainGateway/utils.ts
|
|
920
|
-
var getStateChainGateway = /* @__PURE__ */ __name((
|
|
921
|
-
const stateChainGatewayContractAddress =
|
|
922
|
-
return StateChainGateway__factory.connect(stateChainGatewayContractAddress,
|
|
918
|
+
var getStateChainGateway = /* @__PURE__ */ __name((networkOpts) => {
|
|
919
|
+
const stateChainGatewayContractAddress = networkOpts.network === "localnet" ? networkOpts.stateChainGatewayContractAddress : getStateChainGatewayContractAddress(networkOpts.network);
|
|
920
|
+
return StateChainGateway__factory.connect(stateChainGatewayContractAddress, networkOpts.signer);
|
|
923
921
|
}, "getStateChainGateway");
|
|
924
922
|
|
|
925
923
|
// ../shared/src/stateChainGateway/approval.ts
|
|
926
|
-
var checkStateChainGatewayAllowance = /* @__PURE__ */ __name(async (amount,
|
|
927
|
-
const flipContractAddress =
|
|
928
|
-
const stateChainGatewayContractAddress =
|
|
929
|
-
return checkAllowance(amount, stateChainGatewayContractAddress, flipContractAddress,
|
|
924
|
+
var checkStateChainGatewayAllowance = /* @__PURE__ */ __name(async (amount, networkOpts) => {
|
|
925
|
+
const flipContractAddress = networkOpts.network === "localnet" ? networkOpts.flipContractAddress : getTokenContractAddress(Assets.FLIP, networkOpts.network);
|
|
926
|
+
const stateChainGatewayContractAddress = networkOpts.network === "localnet" ? networkOpts.stateChainGatewayContractAddress : getStateChainGatewayContractAddress(networkOpts.network);
|
|
927
|
+
return checkAllowance(amount, stateChainGatewayContractAddress, flipContractAddress, networkOpts.signer);
|
|
930
928
|
}, "checkStateChainGatewayAllowance");
|
|
931
|
-
var approveStateChainGateway = /* @__PURE__ */ __name(async (amount,
|
|
932
|
-
const { allowance, erc20, isAllowable } = await checkStateChainGatewayAllowance(amount,
|
|
929
|
+
var approveStateChainGateway = /* @__PURE__ */ __name(async (amount, networkOpts, txOpts) => {
|
|
930
|
+
const { allowance, erc20, isAllowable } = await checkStateChainGatewayAllowance(amount, networkOpts);
|
|
933
931
|
if (isAllowable)
|
|
934
932
|
return null;
|
|
935
|
-
const stateChainGatewayContractAddress =
|
|
936
|
-
|
|
937
|
-
return receipt;
|
|
933
|
+
const stateChainGatewayContractAddress = networkOpts.network === "localnet" ? networkOpts.stateChainGatewayContractAddress : getStateChainGatewayContractAddress(networkOpts.network);
|
|
934
|
+
return approve(amount, stateChainGatewayContractAddress, erc20, allowance, txOpts);
|
|
938
935
|
}, "approveStateChainGateway");
|
|
939
936
|
|
|
940
937
|
// ../shared/src/stateChainGateway/index.ts
|
|
941
|
-
var fundStateChainAccount = /* @__PURE__ */ __name(async (accountId, amount,
|
|
942
|
-
const flipContractAddress =
|
|
943
|
-
const stateChainGateway = getStateChainGateway(
|
|
944
|
-
const { isAllowable } = await checkAllowance(amount, stateChainGateway.
|
|
938
|
+
var fundStateChainAccount = /* @__PURE__ */ __name(async (accountId, amount, networkOpts, txOpts) => {
|
|
939
|
+
const flipContractAddress = networkOpts.network === "localnet" ? networkOpts.flipContractAddress : getTokenContractAddress(Assets.FLIP, networkOpts.network);
|
|
940
|
+
const stateChainGateway = getStateChainGateway(networkOpts);
|
|
941
|
+
const { isAllowable } = await checkAllowance(amount, await stateChainGateway.getAddress(), flipContractAddress, networkOpts.signer);
|
|
945
942
|
assert(isAllowable, "Insufficient allowance");
|
|
946
|
-
const transaction = await stateChainGateway.fundStateChainAccount(accountId, amount,
|
|
947
|
-
|
|
948
|
-
});
|
|
949
|
-
return transaction.wait(1);
|
|
943
|
+
const transaction = await stateChainGateway.fundStateChainAccount(accountId, amount, extractOverrides(txOpts));
|
|
944
|
+
return transaction.wait(txOpts.wait);
|
|
950
945
|
}, "fundStateChainAccount");
|
|
951
|
-
var executeRedemption = /* @__PURE__ */ __name(async (accountId,
|
|
952
|
-
const stateChainGateway = getStateChainGateway(
|
|
953
|
-
const transaction = await stateChainGateway.executeRedemption(accountId,
|
|
954
|
-
return transaction.wait(
|
|
946
|
+
var executeRedemption = /* @__PURE__ */ __name(async (accountId, networkOpts, txOpts) => {
|
|
947
|
+
const stateChainGateway = getStateChainGateway(networkOpts);
|
|
948
|
+
const transaction = await stateChainGateway.executeRedemption(accountId, extractOverrides(txOpts));
|
|
949
|
+
return transaction.wait(txOpts.wait);
|
|
955
950
|
}, "executeRedemption");
|
|
956
|
-
var getMinimumFunding = /* @__PURE__ */ __name((
|
|
957
|
-
const stateChainGateway = getStateChainGateway(
|
|
951
|
+
var getMinimumFunding = /* @__PURE__ */ __name((networkOpts) => {
|
|
952
|
+
const stateChainGateway = getStateChainGateway(networkOpts);
|
|
958
953
|
return stateChainGateway.getMinimumFunding();
|
|
959
954
|
}, "getMinimumFunding");
|
|
960
|
-
var getRedemptionDelay = /* @__PURE__ */ __name((
|
|
961
|
-
const stateChainGateway = getStateChainGateway(
|
|
955
|
+
var getRedemptionDelay = /* @__PURE__ */ __name((networkOpts) => {
|
|
956
|
+
const stateChainGateway = getStateChainGateway(networkOpts);
|
|
962
957
|
return stateChainGateway.REDEMPTION_DELAY();
|
|
963
958
|
}, "getRedemptionDelay");
|
|
964
959
|
|
|
@@ -974,25 +969,20 @@ var _FundingSDK = class _FundingSDK {
|
|
|
974
969
|
/**
|
|
975
970
|
* @param accountId the hex-encoded validator account id
|
|
976
971
|
* @param amount the amount to fund in base units of FLIP
|
|
977
|
-
* @param signer a signer to use for the transaction if different from the one
|
|
978
|
-
* provided in the constructor
|
|
979
972
|
*/
|
|
980
|
-
async fundStateChainAccount(accountId, amount) {
|
|
981
|
-
const tx = await fundStateChainAccount(accountId, amount, this.options);
|
|
982
|
-
return tx.
|
|
973
|
+
async fundStateChainAccount(accountId, amount, txOpts = {}) {
|
|
974
|
+
const tx = await fundStateChainAccount(accountId, amount, this.options, txOpts);
|
|
975
|
+
return tx.hash;
|
|
983
976
|
}
|
|
984
977
|
/**
|
|
985
978
|
* @param accountId the hex-encoded validator account id
|
|
986
|
-
* @param signer a signer to use for the transaction if different from the one
|
|
987
|
-
* provided in the constructor
|
|
988
979
|
*/
|
|
989
|
-
async executeRedemption(accountId) {
|
|
990
|
-
const tx = await executeRedemption(accountId, this.options);
|
|
991
|
-
return tx.
|
|
980
|
+
async executeRedemption(accountId, txOpts = {}) {
|
|
981
|
+
const tx = await executeRedemption(accountId, this.options, txOpts);
|
|
982
|
+
return tx.hash;
|
|
992
983
|
}
|
|
993
984
|
async getMinimumFunding() {
|
|
994
|
-
|
|
995
|
-
return amount.toBigInt();
|
|
985
|
+
return getMinimumFunding(this.options);
|
|
996
986
|
}
|
|
997
987
|
async getRedemptionDelay() {
|
|
998
988
|
return getRedemptionDelay(this.options);
|
|
@@ -1004,12 +994,9 @@ var _FundingSDK = class _FundingSDK {
|
|
|
1004
994
|
* @param amount the amount of FLIP to request approval for
|
|
1005
995
|
* @returns the transaction hash or null if no approval was required
|
|
1006
996
|
*/
|
|
1007
|
-
async approveStateChainGateway(amount,
|
|
1008
|
-
const receipt = await approveStateChainGateway(amount,
|
|
1009
|
-
|
|
1010
|
-
...this.options
|
|
1011
|
-
});
|
|
1012
|
-
return receipt && receipt.transactionHash;
|
|
997
|
+
async approveStateChainGateway(amount, txOpts = {}) {
|
|
998
|
+
const receipt = await approveStateChainGateway(amount, this.options, txOpts);
|
|
999
|
+
return receipt && receipt.hash;
|
|
1013
1000
|
}
|
|
1014
1001
|
};
|
|
1015
1002
|
__name(_FundingSDK, "FundingSDK");
|
package/dist/funding.mjs
CHANGED
|
@@ -1,48 +1,45 @@
|
|
|
1
|
-
import { __name, __publicField, ChainflipNetworks, getFlipBalance, getStateChainGatewayContractAddress, approve, getTokenContractAddress, Assets, checkAllowance, assert, StateChainGateway__factory } from './chunk-
|
|
1
|
+
import { __name, __publicField, ChainflipNetworks, getFlipBalance, getStateChainGatewayContractAddress, approve, getTokenContractAddress, Assets, checkAllowance, assert, extractOverrides, StateChainGateway__factory } from './chunk-UBMU3BTF.mjs';
|
|
2
2
|
|
|
3
3
|
// ../shared/src/stateChainGateway/utils.ts
|
|
4
|
-
var getStateChainGateway = /* @__PURE__ */ __name((
|
|
5
|
-
const stateChainGatewayContractAddress =
|
|
6
|
-
return StateChainGateway__factory.connect(stateChainGatewayContractAddress,
|
|
4
|
+
var getStateChainGateway = /* @__PURE__ */ __name((networkOpts) => {
|
|
5
|
+
const stateChainGatewayContractAddress = networkOpts.network === "localnet" ? networkOpts.stateChainGatewayContractAddress : getStateChainGatewayContractAddress(networkOpts.network);
|
|
6
|
+
return StateChainGateway__factory.connect(stateChainGatewayContractAddress, networkOpts.signer);
|
|
7
7
|
}, "getStateChainGateway");
|
|
8
8
|
|
|
9
9
|
// ../shared/src/stateChainGateway/approval.ts
|
|
10
|
-
var checkStateChainGatewayAllowance = /* @__PURE__ */ __name(async (amount,
|
|
11
|
-
const flipContractAddress =
|
|
12
|
-
const stateChainGatewayContractAddress =
|
|
13
|
-
return checkAllowance(amount, stateChainGatewayContractAddress, flipContractAddress,
|
|
10
|
+
var checkStateChainGatewayAllowance = /* @__PURE__ */ __name(async (amount, networkOpts) => {
|
|
11
|
+
const flipContractAddress = networkOpts.network === "localnet" ? networkOpts.flipContractAddress : getTokenContractAddress(Assets.FLIP, networkOpts.network);
|
|
12
|
+
const stateChainGatewayContractAddress = networkOpts.network === "localnet" ? networkOpts.stateChainGatewayContractAddress : getStateChainGatewayContractAddress(networkOpts.network);
|
|
13
|
+
return checkAllowance(amount, stateChainGatewayContractAddress, flipContractAddress, networkOpts.signer);
|
|
14
14
|
}, "checkStateChainGatewayAllowance");
|
|
15
|
-
var approveStateChainGateway = /* @__PURE__ */ __name(async (amount,
|
|
16
|
-
const { allowance, erc20, isAllowable } = await checkStateChainGatewayAllowance(amount,
|
|
15
|
+
var approveStateChainGateway = /* @__PURE__ */ __name(async (amount, networkOpts, txOpts) => {
|
|
16
|
+
const { allowance, erc20, isAllowable } = await checkStateChainGatewayAllowance(amount, networkOpts);
|
|
17
17
|
if (isAllowable)
|
|
18
18
|
return null;
|
|
19
|
-
const stateChainGatewayContractAddress =
|
|
20
|
-
|
|
21
|
-
return receipt;
|
|
19
|
+
const stateChainGatewayContractAddress = networkOpts.network === "localnet" ? networkOpts.stateChainGatewayContractAddress : getStateChainGatewayContractAddress(networkOpts.network);
|
|
20
|
+
return approve(amount, stateChainGatewayContractAddress, erc20, allowance, txOpts);
|
|
22
21
|
}, "approveStateChainGateway");
|
|
23
22
|
|
|
24
23
|
// ../shared/src/stateChainGateway/index.ts
|
|
25
|
-
var fundStateChainAccount = /* @__PURE__ */ __name(async (accountId, amount,
|
|
26
|
-
const flipContractAddress =
|
|
27
|
-
const stateChainGateway = getStateChainGateway(
|
|
28
|
-
const { isAllowable } = await checkAllowance(amount, stateChainGateway.
|
|
24
|
+
var fundStateChainAccount = /* @__PURE__ */ __name(async (accountId, amount, networkOpts, txOpts) => {
|
|
25
|
+
const flipContractAddress = networkOpts.network === "localnet" ? networkOpts.flipContractAddress : getTokenContractAddress(Assets.FLIP, networkOpts.network);
|
|
26
|
+
const stateChainGateway = getStateChainGateway(networkOpts);
|
|
27
|
+
const { isAllowable } = await checkAllowance(amount, await stateChainGateway.getAddress(), flipContractAddress, networkOpts.signer);
|
|
29
28
|
assert(isAllowable, "Insufficient allowance");
|
|
30
|
-
const transaction = await stateChainGateway.fundStateChainAccount(accountId, amount,
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
return transaction.wait(1);
|
|
29
|
+
const transaction = await stateChainGateway.fundStateChainAccount(accountId, amount, extractOverrides(txOpts));
|
|
30
|
+
return transaction.wait(txOpts.wait);
|
|
34
31
|
}, "fundStateChainAccount");
|
|
35
|
-
var executeRedemption = /* @__PURE__ */ __name(async (accountId,
|
|
36
|
-
const stateChainGateway = getStateChainGateway(
|
|
37
|
-
const transaction = await stateChainGateway.executeRedemption(accountId,
|
|
38
|
-
return transaction.wait(
|
|
32
|
+
var executeRedemption = /* @__PURE__ */ __name(async (accountId, networkOpts, txOpts) => {
|
|
33
|
+
const stateChainGateway = getStateChainGateway(networkOpts);
|
|
34
|
+
const transaction = await stateChainGateway.executeRedemption(accountId, extractOverrides(txOpts));
|
|
35
|
+
return transaction.wait(txOpts.wait);
|
|
39
36
|
}, "executeRedemption");
|
|
40
|
-
var getMinimumFunding = /* @__PURE__ */ __name((
|
|
41
|
-
const stateChainGateway = getStateChainGateway(
|
|
37
|
+
var getMinimumFunding = /* @__PURE__ */ __name((networkOpts) => {
|
|
38
|
+
const stateChainGateway = getStateChainGateway(networkOpts);
|
|
42
39
|
return stateChainGateway.getMinimumFunding();
|
|
43
40
|
}, "getMinimumFunding");
|
|
44
|
-
var getRedemptionDelay = /* @__PURE__ */ __name((
|
|
45
|
-
const stateChainGateway = getStateChainGateway(
|
|
41
|
+
var getRedemptionDelay = /* @__PURE__ */ __name((networkOpts) => {
|
|
42
|
+
const stateChainGateway = getStateChainGateway(networkOpts);
|
|
46
43
|
return stateChainGateway.REDEMPTION_DELAY();
|
|
47
44
|
}, "getRedemptionDelay");
|
|
48
45
|
|
|
@@ -58,25 +55,20 @@ var _FundingSDK = class _FundingSDK {
|
|
|
58
55
|
/**
|
|
59
56
|
* @param accountId the hex-encoded validator account id
|
|
60
57
|
* @param amount the amount to fund in base units of FLIP
|
|
61
|
-
* @param signer a signer to use for the transaction if different from the one
|
|
62
|
-
* provided in the constructor
|
|
63
58
|
*/
|
|
64
|
-
async fundStateChainAccount(accountId, amount) {
|
|
65
|
-
const tx = await fundStateChainAccount(accountId, amount, this.options);
|
|
66
|
-
return tx.
|
|
59
|
+
async fundStateChainAccount(accountId, amount, txOpts = {}) {
|
|
60
|
+
const tx = await fundStateChainAccount(accountId, amount, this.options, txOpts);
|
|
61
|
+
return tx.hash;
|
|
67
62
|
}
|
|
68
63
|
/**
|
|
69
64
|
* @param accountId the hex-encoded validator account id
|
|
70
|
-
* @param signer a signer to use for the transaction if different from the one
|
|
71
|
-
* provided in the constructor
|
|
72
65
|
*/
|
|
73
|
-
async executeRedemption(accountId) {
|
|
74
|
-
const tx = await executeRedemption(accountId, this.options);
|
|
75
|
-
return tx.
|
|
66
|
+
async executeRedemption(accountId, txOpts = {}) {
|
|
67
|
+
const tx = await executeRedemption(accountId, this.options, txOpts);
|
|
68
|
+
return tx.hash;
|
|
76
69
|
}
|
|
77
70
|
async getMinimumFunding() {
|
|
78
|
-
|
|
79
|
-
return amount.toBigInt();
|
|
71
|
+
return getMinimumFunding(this.options);
|
|
80
72
|
}
|
|
81
73
|
async getRedemptionDelay() {
|
|
82
74
|
return getRedemptionDelay(this.options);
|
|
@@ -88,12 +80,9 @@ var _FundingSDK = class _FundingSDK {
|
|
|
88
80
|
* @param amount the amount of FLIP to request approval for
|
|
89
81
|
* @returns the transaction hash or null if no approval was required
|
|
90
82
|
*/
|
|
91
|
-
async approveStateChainGateway(amount,
|
|
92
|
-
const receipt = await approveStateChainGateway(amount,
|
|
93
|
-
|
|
94
|
-
...this.options
|
|
95
|
-
});
|
|
96
|
-
return receipt && receipt.transactionHash;
|
|
83
|
+
async approveStateChainGateway(amount, txOpts = {}) {
|
|
84
|
+
const receipt = await approveStateChainGateway(amount, this.options, txOpts);
|
|
85
|
+
return receipt && receipt.hash;
|
|
97
86
|
}
|
|
98
87
|
};
|
|
99
88
|
__name(_FundingSDK, "FundingSDK");
|