@gearbox-protocol/sdk 14.2.0 → 14.2.1
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/cjs/dev/claimDSToken.js +208 -0
- package/dist/cjs/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +19 -2
- package/dist/cjs/sdk/market/kyc/securitize/types.js +20 -0
- package/dist/esm/dev/claimDSToken.js +187 -0
- package/dist/esm/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +21 -2
- package/dist/esm/sdk/market/kyc/securitize/types.js +12 -0
- package/dist/types/dev/claimDSToken.d.ts +34 -0
- package/dist/types/sdk/market/kyc/securitize/SecuritizeKYCFactory.d.ts +1 -1
- package/dist/types/sdk/market/kyc/securitize/types.d.ts +37 -22
- package/package.json +1 -1
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var claimDSToken_exports = {};
|
|
20
|
+
__export(claimDSToken_exports, {
|
|
21
|
+
claimDSToken: () => claimDSToken,
|
|
22
|
+
claimDSTokens: () => claimDSTokens,
|
|
23
|
+
registerInvestor: () => registerInvestor
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(claimDSToken_exports);
|
|
26
|
+
var import_viem = require("viem");
|
|
27
|
+
var import_accounts = require("viem/accounts");
|
|
28
|
+
var import_iDSRegistryService = require("../abi/kyc/iDSRegistryService.js");
|
|
29
|
+
var import_iDSToken = require("../abi/kyc/iDSToken.js");
|
|
30
|
+
var import_sdk = require("../sdk/index.js");
|
|
31
|
+
async function writeAndWait(anvil, params) {
|
|
32
|
+
const hash = await anvil.writeContract(params);
|
|
33
|
+
await anvil.mine({ blocks: 1 });
|
|
34
|
+
await anvil.waitForTransactionReceipt({
|
|
35
|
+
hash,
|
|
36
|
+
pollingInterval: 100
|
|
37
|
+
});
|
|
38
|
+
return hash;
|
|
39
|
+
}
|
|
40
|
+
async function registerInvestor(props) {
|
|
41
|
+
const { claimer, anvil, token, adminPrivateKey, logger } = props;
|
|
42
|
+
const account = (0, import_accounts.privateKeyToAccount)(adminPrivateKey);
|
|
43
|
+
const registryServiceId = await anvil.readContract({
|
|
44
|
+
address: token,
|
|
45
|
+
abi: import_iDSToken.iDSTokenAbi,
|
|
46
|
+
functionName: "REGISTRY_SERVICE"
|
|
47
|
+
});
|
|
48
|
+
const registryService = await anvil.readContract({
|
|
49
|
+
address: token,
|
|
50
|
+
abi: import_iDSToken.iDSTokenAbi,
|
|
51
|
+
functionName: "getDSService",
|
|
52
|
+
args: [registryServiceId]
|
|
53
|
+
});
|
|
54
|
+
logger?.debug(`Registry service: ${registryService} (${registryServiceId})`);
|
|
55
|
+
const [isRegistered, ACCREDITED, APPROVED] = await anvil.multicall({
|
|
56
|
+
contracts: [
|
|
57
|
+
{
|
|
58
|
+
address: registryService,
|
|
59
|
+
abi: import_iDSRegistryService.iDSRegistryServiceAbi,
|
|
60
|
+
functionName: "isWallet",
|
|
61
|
+
args: [claimer]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
address: registryService,
|
|
65
|
+
abi: import_iDSRegistryService.iDSRegistryServiceAbi,
|
|
66
|
+
functionName: "ACCREDITED",
|
|
67
|
+
args: []
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
address: registryService,
|
|
71
|
+
abi: import_iDSRegistryService.iDSRegistryServiceAbi,
|
|
72
|
+
functionName: "APPROVED",
|
|
73
|
+
args: []
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
allowFailure: false
|
|
77
|
+
});
|
|
78
|
+
if (!isRegistered) {
|
|
79
|
+
logger?.debug(
|
|
80
|
+
`Claimer ${claimer} is not a registered wallet, registering...`
|
|
81
|
+
);
|
|
82
|
+
const investorId = `investor-${claimer.toLowerCase()}`;
|
|
83
|
+
const investorExists = await anvil.readContract({
|
|
84
|
+
address: registryService,
|
|
85
|
+
abi: import_iDSRegistryService.iDSRegistryServiceAbi,
|
|
86
|
+
functionName: "isInvestor",
|
|
87
|
+
args: [investorId]
|
|
88
|
+
});
|
|
89
|
+
if (!investorExists) {
|
|
90
|
+
await writeAndWait(anvil, {
|
|
91
|
+
account,
|
|
92
|
+
chain: anvil.chain,
|
|
93
|
+
address: registryService,
|
|
94
|
+
abi: import_iDSRegistryService.iDSRegistryServiceAbi,
|
|
95
|
+
functionName: "registerInvestor",
|
|
96
|
+
args: [investorId, investorId]
|
|
97
|
+
});
|
|
98
|
+
logger?.debug(`Registered investor "${investorId}"`);
|
|
99
|
+
}
|
|
100
|
+
await writeAndWait(anvil, {
|
|
101
|
+
account,
|
|
102
|
+
chain: anvil.chain,
|
|
103
|
+
address: registryService,
|
|
104
|
+
abi: import_iDSRegistryService.iDSRegistryServiceAbi,
|
|
105
|
+
functionName: "addWallet",
|
|
106
|
+
args: [claimer, investorId]
|
|
107
|
+
});
|
|
108
|
+
logger?.debug(`Added wallet ${claimer} for investor "${investorId}"`);
|
|
109
|
+
try {
|
|
110
|
+
await writeAndWait(anvil, {
|
|
111
|
+
account,
|
|
112
|
+
chain: anvil.chain,
|
|
113
|
+
address: registryService,
|
|
114
|
+
abi: import_iDSRegistryService.iDSRegistryServiceAbi,
|
|
115
|
+
functionName: "setCountry",
|
|
116
|
+
args: [investorId, "US"]
|
|
117
|
+
});
|
|
118
|
+
logger?.debug(`Set country for investor "${investorId}" to "US"`);
|
|
119
|
+
await writeAndWait(anvil, {
|
|
120
|
+
account,
|
|
121
|
+
chain: anvil.chain,
|
|
122
|
+
address: registryService,
|
|
123
|
+
abi: import_iDSRegistryService.iDSRegistryServiceAbi,
|
|
124
|
+
functionName: "setAttribute",
|
|
125
|
+
args: [
|
|
126
|
+
investorId,
|
|
127
|
+
ACCREDITED,
|
|
128
|
+
BigInt(APPROVED),
|
|
129
|
+
import_sdk.MAX_UINT256,
|
|
130
|
+
"fake proof"
|
|
131
|
+
]
|
|
132
|
+
});
|
|
133
|
+
logger?.debug(`Set attributes for investor "${investorId}"`);
|
|
134
|
+
} catch (e) {
|
|
135
|
+
logger?.error(e);
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
logger?.debug(`Claimer ${claimer} is already a registered wallet`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async function claimDSToken(props) {
|
|
142
|
+
const {
|
|
143
|
+
anvil,
|
|
144
|
+
claimer,
|
|
145
|
+
adminPrivateKey,
|
|
146
|
+
token,
|
|
147
|
+
marketConfigurators,
|
|
148
|
+
kycFactories,
|
|
149
|
+
usdAmount: usdAmountProp = "100000"
|
|
150
|
+
} = props;
|
|
151
|
+
const account = (0, import_accounts.privateKeyToAccount)(adminPrivateKey);
|
|
152
|
+
const symbol = await anvil.readContract({
|
|
153
|
+
address: token,
|
|
154
|
+
abi: import_viem.erc20Abi,
|
|
155
|
+
functionName: "symbol",
|
|
156
|
+
args: []
|
|
157
|
+
});
|
|
158
|
+
const logger = props.logger?.child?.({ symbol });
|
|
159
|
+
const usdAmount = BigInt(usdAmountProp) * 10n ** 8n;
|
|
160
|
+
const sdk = new import_sdk.OnchainSDK(anvil.chain.network, {
|
|
161
|
+
client: anvil,
|
|
162
|
+
timeout: 12e4
|
|
163
|
+
});
|
|
164
|
+
await sdk.attach({ marketConfigurators, kycFactories });
|
|
165
|
+
let amount = 0n;
|
|
166
|
+
for (const market of sdk.marketRegister.markets) {
|
|
167
|
+
try {
|
|
168
|
+
amount = market.priceOracle.convertFromUSD(token, usdAmount);
|
|
169
|
+
} catch {
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (amount === 0n) {
|
|
173
|
+
throw new Error(`No market found for token ${token}`);
|
|
174
|
+
}
|
|
175
|
+
logger?.debug(`${usdAmountProp} USD === ${amount} ${symbol}`);
|
|
176
|
+
await registerInvestor({ ...props, logger });
|
|
177
|
+
logger?.debug(`Issuing ${amount} tokens to ${claimer}...`);
|
|
178
|
+
const mintHash = await writeAndWait(anvil, {
|
|
179
|
+
account,
|
|
180
|
+
chain: anvil.chain,
|
|
181
|
+
address: token,
|
|
182
|
+
abi: import_iDSToken.iDSTokenAbi,
|
|
183
|
+
functionName: "issueTokens",
|
|
184
|
+
args: [claimer, amount]
|
|
185
|
+
});
|
|
186
|
+
logger?.debug(`Done! tx: ${mintHash}`);
|
|
187
|
+
const balance = await anvil.readContract({
|
|
188
|
+
address: token,
|
|
189
|
+
abi: import_viem.erc20Abi,
|
|
190
|
+
functionName: "balanceOf",
|
|
191
|
+
args: [claimer]
|
|
192
|
+
});
|
|
193
|
+
logger?.debug(
|
|
194
|
+
`Balance of ${claimer}: ${sdk.tokensMeta.formatBN(token, balance)}`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
async function claimDSTokens(props) {
|
|
198
|
+
const { tokens, ...rest } = props;
|
|
199
|
+
for (const token of tokens) {
|
|
200
|
+
await claimDSToken({ ...rest, token });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
204
|
+
0 && (module.exports = {
|
|
205
|
+
claimDSToken,
|
|
206
|
+
claimDSTokens,
|
|
207
|
+
registerInvestor
|
|
208
|
+
});
|
|
@@ -26,6 +26,7 @@ var import_iSecuritizeKYCFactory = require("../../../../abi/kyc/iSecuritizeKYCFa
|
|
|
26
26
|
var import_base = require("../../../base/index.js");
|
|
27
27
|
var import_utils = require("../../../utils/index.js");
|
|
28
28
|
var import_constants = require("./constants.js");
|
|
29
|
+
var import_types = require("./types.js");
|
|
29
30
|
const abi = import_iSecuritizeKYCFactory.iSecuritizeKYCFactoryAbi;
|
|
30
31
|
class SecuritizeKYCFactory extends import_base.BaseContract {
|
|
31
32
|
#sdk;
|
|
@@ -93,7 +94,23 @@ class SecuritizeKYCFactory extends import_base.BaseContract {
|
|
|
93
94
|
type: import_constants.KYC_FACTORY_SECURITIZE,
|
|
94
95
|
factory: this.address,
|
|
95
96
|
cachedSignatures: [...cachedSignatures],
|
|
96
|
-
registerVaultMessages:
|
|
97
|
+
registerVaultMessages: registerVaultMessages.map((m) => ({
|
|
98
|
+
types: import_types.SECURITIZE_REGISTER_VAULT_TYPES,
|
|
99
|
+
primaryType: "RegisterVault",
|
|
100
|
+
domain: {
|
|
101
|
+
name: m.domain.name,
|
|
102
|
+
version: m.domain.version,
|
|
103
|
+
chainId: m.domain.chainId,
|
|
104
|
+
verifyingContract: m.domain.verifyingContract
|
|
105
|
+
},
|
|
106
|
+
message: {
|
|
107
|
+
investor: m.investor,
|
|
108
|
+
operator: m.operator,
|
|
109
|
+
token: m.token,
|
|
110
|
+
nonce: m.nonce,
|
|
111
|
+
deadline: m.deadline
|
|
112
|
+
}
|
|
113
|
+
})),
|
|
97
114
|
registeredTokens: [...registeredTokens],
|
|
98
115
|
creditAccounts: creditAccounts.map((ca) => {
|
|
99
116
|
const [registeredTokens2] = (0, import_viem.decodeAbiParameters)(
|
|
@@ -163,7 +180,7 @@ class SecuritizeKYCFactory extends import_base.BaseContract {
|
|
|
163
180
|
const unsignedTokens = tokensToRegister.difference(signedTokens);
|
|
164
181
|
const securitizeTokensToRegister = tokensToRegister.difference(registredTokens);
|
|
165
182
|
const requiredSignatures = investorData.registerVaultMessages.filter(
|
|
166
|
-
(m) => unsignedTokens.has(m.token)
|
|
183
|
+
(m) => unsignedTokens.has(m.message.token)
|
|
167
184
|
);
|
|
168
185
|
return {
|
|
169
186
|
type: import_constants.KYC_FACTORY_SECURITIZE,
|
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -13,4 +17,20 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
13
17
|
};
|
|
14
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
19
|
var types_exports = {};
|
|
20
|
+
__export(types_exports, {
|
|
21
|
+
SECURITIZE_REGISTER_VAULT_TYPES: () => SECURITIZE_REGISTER_VAULT_TYPES
|
|
22
|
+
});
|
|
16
23
|
module.exports = __toCommonJS(types_exports);
|
|
24
|
+
const SECURITIZE_REGISTER_VAULT_TYPES = {
|
|
25
|
+
RegisterVault: [
|
|
26
|
+
{ name: "investor", type: "address" },
|
|
27
|
+
{ name: "operator", type: "address" },
|
|
28
|
+
{ name: "token", type: "address" },
|
|
29
|
+
{ name: "nonce", type: "uint256" },
|
|
30
|
+
{ name: "deadline", type: "uint256" }
|
|
31
|
+
]
|
|
32
|
+
};
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
SECURITIZE_REGISTER_VAULT_TYPES
|
|
36
|
+
});
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import {
|
|
2
|
+
erc20Abi
|
|
3
|
+
} from "viem";
|
|
4
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
5
|
+
import { iDSRegistryServiceAbi } from "../abi/kyc/iDSRegistryService.js";
|
|
6
|
+
import { iDSTokenAbi } from "../abi/kyc/iDSToken.js";
|
|
7
|
+
import {
|
|
8
|
+
MAX_UINT256,
|
|
9
|
+
OnchainSDK
|
|
10
|
+
} from "../sdk/index.js";
|
|
11
|
+
async function writeAndWait(anvil, params) {
|
|
12
|
+
const hash = await anvil.writeContract(params);
|
|
13
|
+
await anvil.mine({ blocks: 1 });
|
|
14
|
+
await anvil.waitForTransactionReceipt({
|
|
15
|
+
hash,
|
|
16
|
+
pollingInterval: 100
|
|
17
|
+
});
|
|
18
|
+
return hash;
|
|
19
|
+
}
|
|
20
|
+
async function registerInvestor(props) {
|
|
21
|
+
const { claimer, anvil, token, adminPrivateKey, logger } = props;
|
|
22
|
+
const account = privateKeyToAccount(adminPrivateKey);
|
|
23
|
+
const registryServiceId = await anvil.readContract({
|
|
24
|
+
address: token,
|
|
25
|
+
abi: iDSTokenAbi,
|
|
26
|
+
functionName: "REGISTRY_SERVICE"
|
|
27
|
+
});
|
|
28
|
+
const registryService = await anvil.readContract({
|
|
29
|
+
address: token,
|
|
30
|
+
abi: iDSTokenAbi,
|
|
31
|
+
functionName: "getDSService",
|
|
32
|
+
args: [registryServiceId]
|
|
33
|
+
});
|
|
34
|
+
logger?.debug(`Registry service: ${registryService} (${registryServiceId})`);
|
|
35
|
+
const [isRegistered, ACCREDITED, APPROVED] = await anvil.multicall({
|
|
36
|
+
contracts: [
|
|
37
|
+
{
|
|
38
|
+
address: registryService,
|
|
39
|
+
abi: iDSRegistryServiceAbi,
|
|
40
|
+
functionName: "isWallet",
|
|
41
|
+
args: [claimer]
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
address: registryService,
|
|
45
|
+
abi: iDSRegistryServiceAbi,
|
|
46
|
+
functionName: "ACCREDITED",
|
|
47
|
+
args: []
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
address: registryService,
|
|
51
|
+
abi: iDSRegistryServiceAbi,
|
|
52
|
+
functionName: "APPROVED",
|
|
53
|
+
args: []
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
allowFailure: false
|
|
57
|
+
});
|
|
58
|
+
if (!isRegistered) {
|
|
59
|
+
logger?.debug(
|
|
60
|
+
`Claimer ${claimer} is not a registered wallet, registering...`
|
|
61
|
+
);
|
|
62
|
+
const investorId = `investor-${claimer.toLowerCase()}`;
|
|
63
|
+
const investorExists = await anvil.readContract({
|
|
64
|
+
address: registryService,
|
|
65
|
+
abi: iDSRegistryServiceAbi,
|
|
66
|
+
functionName: "isInvestor",
|
|
67
|
+
args: [investorId]
|
|
68
|
+
});
|
|
69
|
+
if (!investorExists) {
|
|
70
|
+
await writeAndWait(anvil, {
|
|
71
|
+
account,
|
|
72
|
+
chain: anvil.chain,
|
|
73
|
+
address: registryService,
|
|
74
|
+
abi: iDSRegistryServiceAbi,
|
|
75
|
+
functionName: "registerInvestor",
|
|
76
|
+
args: [investorId, investorId]
|
|
77
|
+
});
|
|
78
|
+
logger?.debug(`Registered investor "${investorId}"`);
|
|
79
|
+
}
|
|
80
|
+
await writeAndWait(anvil, {
|
|
81
|
+
account,
|
|
82
|
+
chain: anvil.chain,
|
|
83
|
+
address: registryService,
|
|
84
|
+
abi: iDSRegistryServiceAbi,
|
|
85
|
+
functionName: "addWallet",
|
|
86
|
+
args: [claimer, investorId]
|
|
87
|
+
});
|
|
88
|
+
logger?.debug(`Added wallet ${claimer} for investor "${investorId}"`);
|
|
89
|
+
try {
|
|
90
|
+
await writeAndWait(anvil, {
|
|
91
|
+
account,
|
|
92
|
+
chain: anvil.chain,
|
|
93
|
+
address: registryService,
|
|
94
|
+
abi: iDSRegistryServiceAbi,
|
|
95
|
+
functionName: "setCountry",
|
|
96
|
+
args: [investorId, "US"]
|
|
97
|
+
});
|
|
98
|
+
logger?.debug(`Set country for investor "${investorId}" to "US"`);
|
|
99
|
+
await writeAndWait(anvil, {
|
|
100
|
+
account,
|
|
101
|
+
chain: anvil.chain,
|
|
102
|
+
address: registryService,
|
|
103
|
+
abi: iDSRegistryServiceAbi,
|
|
104
|
+
functionName: "setAttribute",
|
|
105
|
+
args: [
|
|
106
|
+
investorId,
|
|
107
|
+
ACCREDITED,
|
|
108
|
+
BigInt(APPROVED),
|
|
109
|
+
MAX_UINT256,
|
|
110
|
+
"fake proof"
|
|
111
|
+
]
|
|
112
|
+
});
|
|
113
|
+
logger?.debug(`Set attributes for investor "${investorId}"`);
|
|
114
|
+
} catch (e) {
|
|
115
|
+
logger?.error(e);
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
logger?.debug(`Claimer ${claimer} is already a registered wallet`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async function claimDSToken(props) {
|
|
122
|
+
const {
|
|
123
|
+
anvil,
|
|
124
|
+
claimer,
|
|
125
|
+
adminPrivateKey,
|
|
126
|
+
token,
|
|
127
|
+
marketConfigurators,
|
|
128
|
+
kycFactories,
|
|
129
|
+
usdAmount: usdAmountProp = "100000"
|
|
130
|
+
} = props;
|
|
131
|
+
const account = privateKeyToAccount(adminPrivateKey);
|
|
132
|
+
const symbol = await anvil.readContract({
|
|
133
|
+
address: token,
|
|
134
|
+
abi: erc20Abi,
|
|
135
|
+
functionName: "symbol",
|
|
136
|
+
args: []
|
|
137
|
+
});
|
|
138
|
+
const logger = props.logger?.child?.({ symbol });
|
|
139
|
+
const usdAmount = BigInt(usdAmountProp) * 10n ** 8n;
|
|
140
|
+
const sdk = new OnchainSDK(anvil.chain.network, {
|
|
141
|
+
client: anvil,
|
|
142
|
+
timeout: 12e4
|
|
143
|
+
});
|
|
144
|
+
await sdk.attach({ marketConfigurators, kycFactories });
|
|
145
|
+
let amount = 0n;
|
|
146
|
+
for (const market of sdk.marketRegister.markets) {
|
|
147
|
+
try {
|
|
148
|
+
amount = market.priceOracle.convertFromUSD(token, usdAmount);
|
|
149
|
+
} catch {
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (amount === 0n) {
|
|
153
|
+
throw new Error(`No market found for token ${token}`);
|
|
154
|
+
}
|
|
155
|
+
logger?.debug(`${usdAmountProp} USD === ${amount} ${symbol}`);
|
|
156
|
+
await registerInvestor({ ...props, logger });
|
|
157
|
+
logger?.debug(`Issuing ${amount} tokens to ${claimer}...`);
|
|
158
|
+
const mintHash = await writeAndWait(anvil, {
|
|
159
|
+
account,
|
|
160
|
+
chain: anvil.chain,
|
|
161
|
+
address: token,
|
|
162
|
+
abi: iDSTokenAbi,
|
|
163
|
+
functionName: "issueTokens",
|
|
164
|
+
args: [claimer, amount]
|
|
165
|
+
});
|
|
166
|
+
logger?.debug(`Done! tx: ${mintHash}`);
|
|
167
|
+
const balance = await anvil.readContract({
|
|
168
|
+
address: token,
|
|
169
|
+
abi: erc20Abi,
|
|
170
|
+
functionName: "balanceOf",
|
|
171
|
+
args: [claimer]
|
|
172
|
+
});
|
|
173
|
+
logger?.debug(
|
|
174
|
+
`Balance of ${claimer}: ${sdk.tokensMeta.formatBN(token, balance)}`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
async function claimDSTokens(props) {
|
|
178
|
+
const { tokens, ...rest } = props;
|
|
179
|
+
for (const token of tokens) {
|
|
180
|
+
await claimDSToken({ ...rest, token });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
export {
|
|
184
|
+
claimDSToken,
|
|
185
|
+
claimDSTokens,
|
|
186
|
+
registerInvestor
|
|
187
|
+
};
|
|
@@ -3,6 +3,9 @@ import { iSecuritizeKYCFactoryAbi } from "../../../../abi/kyc/iSecuritizeKYCFact
|
|
|
3
3
|
import { BaseContract } from "../../../base/index.js";
|
|
4
4
|
import { AddressMap, AddressSet } from "../../../utils/index.js";
|
|
5
5
|
import { KYC_FACTORY_SECURITIZE } from "./constants.js";
|
|
6
|
+
import {
|
|
7
|
+
SECURITIZE_REGISTER_VAULT_TYPES
|
|
8
|
+
} from "./types.js";
|
|
6
9
|
const abi = iSecuritizeKYCFactoryAbi;
|
|
7
10
|
class SecuritizeKYCFactory extends BaseContract {
|
|
8
11
|
#sdk;
|
|
@@ -70,7 +73,23 @@ class SecuritizeKYCFactory extends BaseContract {
|
|
|
70
73
|
type: KYC_FACTORY_SECURITIZE,
|
|
71
74
|
factory: this.address,
|
|
72
75
|
cachedSignatures: [...cachedSignatures],
|
|
73
|
-
registerVaultMessages:
|
|
76
|
+
registerVaultMessages: registerVaultMessages.map((m) => ({
|
|
77
|
+
types: SECURITIZE_REGISTER_VAULT_TYPES,
|
|
78
|
+
primaryType: "RegisterVault",
|
|
79
|
+
domain: {
|
|
80
|
+
name: m.domain.name,
|
|
81
|
+
version: m.domain.version,
|
|
82
|
+
chainId: m.domain.chainId,
|
|
83
|
+
verifyingContract: m.domain.verifyingContract
|
|
84
|
+
},
|
|
85
|
+
message: {
|
|
86
|
+
investor: m.investor,
|
|
87
|
+
operator: m.operator,
|
|
88
|
+
token: m.token,
|
|
89
|
+
nonce: m.nonce,
|
|
90
|
+
deadline: m.deadline
|
|
91
|
+
}
|
|
92
|
+
})),
|
|
74
93
|
registeredTokens: [...registeredTokens],
|
|
75
94
|
creditAccounts: creditAccounts.map((ca) => {
|
|
76
95
|
const [registeredTokens2] = decodeAbiParameters(
|
|
@@ -140,7 +159,7 @@ class SecuritizeKYCFactory extends BaseContract {
|
|
|
140
159
|
const unsignedTokens = tokensToRegister.difference(signedTokens);
|
|
141
160
|
const securitizeTokensToRegister = tokensToRegister.difference(registredTokens);
|
|
142
161
|
const requiredSignatures = investorData.registerVaultMessages.filter(
|
|
143
|
-
(m) => unsignedTokens.has(m.token)
|
|
162
|
+
(m) => unsignedTokens.has(m.message.token)
|
|
144
163
|
);
|
|
145
164
|
return {
|
|
146
165
|
type: KYC_FACTORY_SECURITIZE,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const SECURITIZE_REGISTER_VAULT_TYPES = {
|
|
2
|
+
RegisterVault: [
|
|
3
|
+
{ name: "investor", type: "address" },
|
|
4
|
+
{ name: "operator", type: "address" },
|
|
5
|
+
{ name: "token", type: "address" },
|
|
6
|
+
{ name: "nonce", type: "uint256" },
|
|
7
|
+
{ name: "deadline", type: "uint256" }
|
|
8
|
+
]
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
SECURITIZE_REGISTER_VAULT_TYPES
|
|
12
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Address, type Hex } from "viem";
|
|
2
|
+
import { type ILogger } from "../sdk/index.js";
|
|
3
|
+
import type { AnvilClient } from "./createAnvilClient.js";
|
|
4
|
+
interface ClaimDSTokenProps {
|
|
5
|
+
anvil: AnvilClient;
|
|
6
|
+
claimer: Address;
|
|
7
|
+
adminPrivateKey: Hex;
|
|
8
|
+
/**
|
|
9
|
+
* DSToken addresses
|
|
10
|
+
*/
|
|
11
|
+
token: Address;
|
|
12
|
+
/**
|
|
13
|
+
* USD amount without decimals
|
|
14
|
+
*/
|
|
15
|
+
usdAmount?: string;
|
|
16
|
+
marketConfigurators?: Address[];
|
|
17
|
+
kycFactories?: Address[];
|
|
18
|
+
logger?: ILogger;
|
|
19
|
+
}
|
|
20
|
+
type ClaimDSTokensProps = Omit<ClaimDSTokenProps, "token"> & {
|
|
21
|
+
tokens: Address[];
|
|
22
|
+
};
|
|
23
|
+
export declare function registerInvestor(props: ClaimDSTokenProps): Promise<void>;
|
|
24
|
+
export declare function claimDSToken(props: ClaimDSTokenProps): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Helper function to claim DSToken from the faucet.
|
|
27
|
+
* Works both for MockDStoken and real DSToken connected by securitize-deploy script
|
|
28
|
+
* @param forkStatus
|
|
29
|
+
* @param publicClient
|
|
30
|
+
* @param claimer
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
export declare function claimDSTokens(props: ClaimDSTokensProps): Promise<void>;
|
|
34
|
+
export {};
|
|
@@ -5,7 +5,7 @@ import type { OnchainSDK } from "../../../OnchainSDK.js";
|
|
|
5
5
|
import type { MultiCall, RawTx } from "../../../types/index.js";
|
|
6
6
|
import type { IKYCFactory, KYCCompressorInvestorData, KYCFactoryData } from "../types.js";
|
|
7
7
|
import { KYC_FACTORY_SECURITIZE } from "./constants.js";
|
|
8
|
-
import type
|
|
8
|
+
import { type DStokenData, type SecuritizeInvestorData, type SecuritizeKYCFactoryStateHuman, type SecuritizeOpenAccountRequirements, type SecuritizeOperationParams } from "./types.js";
|
|
9
9
|
declare const abi: readonly [{
|
|
10
10
|
readonly type: "function";
|
|
11
11
|
readonly name: "contractType";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Address, Hex } from "viem";
|
|
1
|
+
import type { Address, Hex, TypedDataDefinition } from "viem";
|
|
2
2
|
import type { BaseContractStateHuman } from "../../../types/index.js";
|
|
3
3
|
import type { KYC_FACTORY_SECURITIZE } from "./constants.js";
|
|
4
4
|
/**
|
|
@@ -33,31 +33,46 @@ export interface SecuritizeSignature {
|
|
|
33
33
|
/** Raw EIP-712 signature bytes. */
|
|
34
34
|
signature: Hex;
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* EIP-712 type schema for the `RegisterVault` message expected by Securitize's
|
|
38
|
+
* VaultRegistrar. Matches the contract's `RegisterVault` typehash field order.
|
|
39
|
+
**/
|
|
40
|
+
export declare const SECURITIZE_REGISTER_VAULT_TYPES: {
|
|
41
|
+
readonly RegisterVault: readonly [{
|
|
42
|
+
readonly name: "investor";
|
|
43
|
+
readonly type: "address";
|
|
44
|
+
}, {
|
|
45
|
+
readonly name: "operator";
|
|
46
|
+
readonly type: "address";
|
|
47
|
+
}, {
|
|
48
|
+
readonly name: "token";
|
|
49
|
+
readonly type: "address";
|
|
50
|
+
}, {
|
|
51
|
+
readonly name: "nonce";
|
|
52
|
+
readonly type: "uint256";
|
|
53
|
+
}, {
|
|
54
|
+
readonly name: "deadline";
|
|
55
|
+
readonly type: "uint256";
|
|
56
|
+
}];
|
|
57
|
+
};
|
|
36
58
|
/**
|
|
37
59
|
* EIP-712 typed-data message that must be signed by the investor to allow the
|
|
38
|
-
* KYC factory to register a credit account as a vault in Securitize's VaultRegistrar
|
|
39
|
-
*
|
|
60
|
+
* KYC factory to register a credit account as a vault in Securitize's VaultRegistrar.
|
|
61
|
+
*
|
|
62
|
+
* Shaped as a viem {@link TypedDataDefinition} so it can be spread directly into
|
|
63
|
+
* `walletClient.signTypedData({ account, ...message })`. The caller only has to
|
|
64
|
+
* supply the signing `account`.
|
|
65
|
+
*
|
|
66
|
+
* - `domain` — EIP-712 domain from the VaultRegistrar contract.
|
|
67
|
+
* - `message.investor` — investor EOA that will sign the message.
|
|
68
|
+
* - `message.operator` — operator address (the DegenNFT contract).
|
|
69
|
+
* - `message.token` — DSToken address to register for.
|
|
70
|
+
* - `message.nonce` — monotonic nonce from VaultRegistrar `(investor, operator)`.
|
|
71
|
+
* - `message.deadline` — unix timestamp after which the message is no longer valid.
|
|
40
72
|
*
|
|
73
|
+
* @see VaultRegistrar in https://github.com/Gearbox-protocol/periphery-v3
|
|
41
74
|
**/
|
|
42
|
-
export
|
|
43
|
-
/** EIP-712 domain from the VaultRegistrar contract. */
|
|
44
|
-
domain: {
|
|
45
|
-
name: string;
|
|
46
|
-
version: string;
|
|
47
|
-
chainId: bigint;
|
|
48
|
-
verifyingContract: Address;
|
|
49
|
-
};
|
|
50
|
-
/** Investor EOA that will sign the message. */
|
|
51
|
-
investor: Address;
|
|
52
|
-
/** Operator address (the DegenNFT contract). */
|
|
53
|
-
operator: Address;
|
|
54
|
-
/** DSToken address to register for. */
|
|
55
|
-
token: Address;
|
|
56
|
-
/** Monotonic nonce from VaultRegistrar (investor, operator). */
|
|
57
|
-
nonce: bigint;
|
|
58
|
-
/** Unix timestamp after which the message is no longer valid. */
|
|
59
|
-
deadline: bigint;
|
|
60
|
-
}
|
|
75
|
+
export type SecuritizeRegisterVaultMessage = TypedDataDefinition<typeof SECURITIZE_REGISTER_VAULT_TYPES, "RegisterVault">;
|
|
61
76
|
/**
|
|
62
77
|
* Per-credit-account data decoded from the KYC compressor's
|
|
63
78
|
* `getCreditAccountData` extra details for a Securitize factory.
|