@kasufinance/kasu-sdk 2.6.0 → 2.7.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/README.md +128 -3
- package/dist/bundle.cjs.js +1119 -254
- package/dist/bundle.esm.js +1109 -255
- package/dist/domain/index.d.ts +3 -2
- package/dist/domain/index.js +2 -2
- package/dist/domain/index.js.map +1 -1
- package/dist/domain/requests.d.ts +42 -4
- package/dist/domain/requests.js +20 -4
- package/dist/domain/requests.js.map +1 -1
- package/dist/domain/wallet-errors.d.ts +63 -8
- package/dist/domain/wallet-errors.js +115 -16
- package/dist/domain/wallet-errors.js.map +1 -1
- package/dist/facade/deposits.js +2 -1
- package/dist/facade/deposits.js.map +1 -1
- package/dist/facade/flows.d.ts +95 -0
- package/dist/facade/flows.js +116 -0
- package/dist/facade/flows.js.map +1 -0
- package/dist/facade/index.d.ts +3 -0
- package/dist/facade/index.js +3 -0
- package/dist/facade/index.js.map +1 -1
- package/dist/facade/kasu.d.ts +6 -2
- package/dist/facade/kasu.js +28 -3
- package/dist/facade/kasu.js.map +1 -1
- package/dist/facade/read-only.d.ts +12 -0
- package/dist/facade/read-only.js +13 -0
- package/dist/facade/read-only.js.map +1 -0
- package/dist/flows/deposit-flow.d.ts +301 -0
- package/dist/flows/deposit-flow.js +358 -0
- package/dist/flows/deposit-flow.js.map +1 -0
- package/dist/flows/flow.d.ts +72 -0
- package/dist/flows/flow.js +110 -0
- package/dist/flows/flow.js.map +1 -0
- package/dist/flows/index.d.ts +19 -0
- package/dist/flows/index.js +17 -0
- package/dist/flows/index.js.map +1 -0
- package/dist/flows/observable.d.ts +59 -0
- package/dist/flows/observable.js +81 -0
- package/dist/flows/observable.js.map +1 -0
- package/dist/flows/withdraw-flow.d.ts +99 -0
- package/dist/flows/withdraw-flow.js +83 -0
- package/dist/flows/withdraw-flow.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/services/DataService/data-service.js +0 -1
- package/dist/services/DataService/data-service.js.map +1 -1
- package/package.json +8 -2
- package/src/domain/index.ts +7 -1
- package/src/domain/requests.ts +57 -4
- package/src/domain/wallet-errors.ts +135 -18
- package/src/facade/deposits.ts +2 -3
- package/src/facade/flows.ts +172 -0
- package/src/facade/index.ts +8 -0
- package/src/facade/kasu.ts +43 -3
- package/src/facade/read-only.ts +13 -0
- package/src/flows/deposit-flow.ts +775 -0
- package/src/flows/flow.ts +108 -0
- package/src/flows/index.ts +45 -0
- package/src/flows/observable.ts +97 -0
- package/src/flows/withdraw-flow.ts +210 -0
- package/src/index.ts +7 -0
- package/src/services/DataService/data-service.ts +0 -1
- package/dist/domain/au-minimum.test.d.ts +0 -1
- package/dist/domain/au-minimum.test.js +0 -202
- package/dist/domain/au-minimum.test.js.map +0 -1
- package/dist/domain/deposit-bounds.test.d.ts +0 -1
- package/dist/domain/deposit-bounds.test.js +0 -135
- package/dist/domain/deposit-bounds.test.js.map +0 -1
- package/dist/domain/loan-contract.test.d.ts +0 -1
- package/dist/domain/loan-contract.test.js +0 -255
- package/dist/domain/loan-contract.test.js.map +0 -1
- package/dist/domain/partners.test.d.ts +0 -1
- package/dist/domain/partners.test.js +0 -53
- package/dist/domain/partners.test.js.map +0 -1
- package/dist/domain/pools.test.d.ts +0 -1
- package/dist/domain/pools.test.js +0 -184
- package/dist/domain/pools.test.js.map +0 -1
- package/dist/domain/rates.test.d.ts +0 -1
- package/dist/domain/rates.test.js +0 -181
- package/dist/domain/rates.test.js.map +0 -1
- package/dist/domain/requests.test.d.ts +0 -1
- package/dist/domain/requests.test.js +0 -470
- package/dist/domain/requests.test.js.map +0 -1
- package/dist/domain/settlement.test.d.ts +0 -1
- package/dist/domain/settlement.test.js +0 -152
- package/dist/domain/settlement.test.js.map +0 -1
- package/dist/domain/tranche-display-name.test.d.ts +0 -1
- package/dist/domain/tranche-display-name.test.js +0 -58
- package/dist/domain/tranche-display-name.test.js.map +0 -1
- package/dist/domain/tranches.test.d.ts +0 -1
- package/dist/domain/tranches.test.js +0 -206
- package/dist/domain/tranches.test.js.map +0 -1
- package/dist/domain/wallet-errors.test.d.ts +0 -1
- package/dist/domain/wallet-errors.test.js +0 -71
- package/dist/domain/wallet-errors.test.js.map +0 -1
- package/dist/facade/config.test.d.ts +0 -1
- package/dist/facade/config.test.js +0 -216
- package/dist/facade/config.test.js.map +0 -1
- package/dist/facade/facade.test.d.ts +0 -1
- package/dist/facade/facade.test.js +0 -278
- package/dist/facade/facade.test.js.map +0 -1
- package/dist/services/Locking/calculate-apy.test.d.ts +0 -1
- package/dist/services/Locking/calculate-apy.test.js +0 -41
- package/dist/services/Locking/calculate-apy.test.js.map +0 -1
- package/dist/tests/sample.test.d.ts +0 -1
- package/dist/tests/sample.test.js +0 -59
- package/dist/tests/sample.test.js.map +0 -1
- package/src/domain/au-minimum.test.ts +0 -371
- package/src/domain/deposit-bounds.test.ts +0 -200
- package/src/domain/loan-contract.test.ts +0 -343
- package/src/domain/partners.test.ts +0 -83
- package/src/domain/pools.test.ts +0 -260
- package/src/domain/rates.test.ts +0 -254
- package/src/domain/requests.test.ts +0 -653
- package/src/domain/settlement.test.ts +0 -198
- package/src/domain/tranche-display-name.test.ts +0 -96
- package/src/domain/tranches.test.ts +0 -300
- package/src/domain/wallet-errors.test.ts +0 -100
- package/src/facade/config.test.ts +0 -265
- package/src/facade/facade.test.ts +0 -374
- package/src/services/Locking/calculate-apy.test.ts +0 -52
- package/src/tests/sample.test.ts +0 -63
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
asContractType,
|
|
5
|
-
buildContractVersionType,
|
|
6
|
-
buildFullNameRequestMessage,
|
|
7
|
-
buildLegacyContractRequestMessage,
|
|
8
|
-
buildLoanAgreementSignMessage,
|
|
9
|
-
ContractType,
|
|
10
|
-
encodeDepositData,
|
|
11
|
-
formatSignTimestampUtc,
|
|
12
|
-
parseFormattedMessage,
|
|
13
|
-
} from './loan-contract';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Ported from kasu-ui `src/features/lending/lib/encode-deposit-data.test.ts`
|
|
17
|
-
* and `sign-message.test.ts`.
|
|
18
|
-
*
|
|
19
|
-
* PINNED CROSS-REPO CONTRACT. The expected strings and byte strings here are
|
|
20
|
-
* what kasu-backend reconstructs and verifies against. A diff in this file
|
|
21
|
-
* without a matching kasu-backend diff means signatures stop verifying in
|
|
22
|
-
* production.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
describe('buildContractVersionType', () => {
|
|
26
|
-
it('packs version 1 retail as 0x0100 (256)', () => {
|
|
27
|
-
expect(buildContractVersionType(1, 'retail')).toBe(256);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('packs version 1 exempt as 0x0101 (257)', () => {
|
|
31
|
-
expect(buildContractVersionType(1, 'exempt')).toBe(257);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('packs version 0 retail as 0', () => {
|
|
35
|
-
expect(buildContractVersionType(0, 'retail')).toBe(0);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('packs version 2 exempt as 0x0201 (513)', () => {
|
|
39
|
-
expect(buildContractVersionType(2, 'exempt')).toBe(513);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const SIG_65 =
|
|
44
|
-
'0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' +
|
|
45
|
-
'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef1c';
|
|
46
|
-
const SIG_65_B =
|
|
47
|
-
'0x4a1e2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8' +
|
|
48
|
-
'4a1e2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f81b';
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* BYTE FIXTURES — produced by the viem implementation kasu-ui runs
|
|
52
|
-
* (`encodeAbiParameters(parseAbiParameters('bytes, uint256, uint256'), …)`)
|
|
53
|
-
* and pasted here verbatim. This is the whole point of the port: the ethers v5
|
|
54
|
-
* encoder in `loan-contract.ts` must emit exactly these bytes, because kasu-ui
|
|
55
|
-
* and kasu-mobile write the same `depositData` field on the same contract.
|
|
56
|
-
*
|
|
57
|
-
* Covers both contract types, a contract version >= 2, a short signature and
|
|
58
|
-
* the empty-signature/zero-timestamp floor.
|
|
59
|
-
*/
|
|
60
|
-
const VIEM_FIXTURES: {
|
|
61
|
-
name: string;
|
|
62
|
-
signature: string;
|
|
63
|
-
timestamp: number;
|
|
64
|
-
contractVersion: number;
|
|
65
|
-
contractType: ContractType;
|
|
66
|
-
expected: string;
|
|
67
|
-
}[] = [
|
|
68
|
-
{
|
|
69
|
-
name: 'v1 retail, ms timestamp',
|
|
70
|
-
signature: SIG_65,
|
|
71
|
-
timestamp: 1_700_000_000_000,
|
|
72
|
-
contractVersion: 1,
|
|
73
|
-
contractType: 'retail',
|
|
74
|
-
expected:
|
|
75
|
-
'0x00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000018bcfe5680000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000041deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef1c00000000000000000000000000000000000000000000000000000000000000',
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
name: 'v1 exempt, ms timestamp',
|
|
79
|
-
signature: SIG_65,
|
|
80
|
-
timestamp: 1_700_000_000_000,
|
|
81
|
-
contractVersion: 1,
|
|
82
|
-
contractType: 'exempt',
|
|
83
|
-
expected:
|
|
84
|
-
'0x00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000018bcfe5680000000000000000000000000000000000000000000000000000000000000001010000000000000000000000000000000000000000000000000000000000000041deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef1c00000000000000000000000000000000000000000000000000000000000000',
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
name: 'v2 retail, deck timestamp',
|
|
88
|
-
signature: SIG_65_B,
|
|
89
|
-
timestamp: 1_785_313_320_000,
|
|
90
|
-
contractVersion: 2,
|
|
91
|
-
contractType: 'retail',
|
|
92
|
-
expected:
|
|
93
|
-
'0x00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000019facf75c40000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000414a1e2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f84a1e2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f81b00000000000000000000000000000000000000000000000000000000000000',
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
name: 'v2 exempt, deck timestamp',
|
|
97
|
-
signature: SIG_65_B,
|
|
98
|
-
timestamp: 1_785_313_320_000,
|
|
99
|
-
contractVersion: 2,
|
|
100
|
-
contractType: 'exempt',
|
|
101
|
-
expected:
|
|
102
|
-
'0x00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000019facf75c40000000000000000000000000000000000000000000000000000000000000020100000000000000000000000000000000000000000000000000000000000000414a1e2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f84a1e2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f81b00000000000000000000000000000000000000000000000000000000000000',
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
name: 'short signature, v3 exempt, timestamp 1',
|
|
106
|
-
signature: '0x1234',
|
|
107
|
-
timestamp: 1,
|
|
108
|
-
contractVersion: 3,
|
|
109
|
-
contractType: 'exempt',
|
|
110
|
-
expected:
|
|
111
|
-
'0x00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000030100000000000000000000000000000000000000000000000000000000000000021234000000000000000000000000000000000000000000000000000000000000',
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
name: 'empty signature, v0 retail, timestamp 0',
|
|
115
|
-
signature: '0x',
|
|
116
|
-
timestamp: 0,
|
|
117
|
-
contractVersion: 0,
|
|
118
|
-
contractType: 'retail',
|
|
119
|
-
expected:
|
|
120
|
-
'0x0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
|
121
|
-
},
|
|
122
|
-
];
|
|
123
|
-
|
|
124
|
-
describe('encodeDepositData — byte-identical to the viem implementation', () => {
|
|
125
|
-
for (const fixture of VIEM_FIXTURES) {
|
|
126
|
-
it(`matches the viem fixture: ${fixture.name}`, () => {
|
|
127
|
-
expect(
|
|
128
|
-
encodeDepositData({
|
|
129
|
-
signature: fixture.signature,
|
|
130
|
-
timestamp: fixture.timestamp,
|
|
131
|
-
contractVersion: fixture.contractVersion,
|
|
132
|
-
contractType: fixture.contractType,
|
|
133
|
-
}),
|
|
134
|
-
).toBe(fixture.expected);
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
it('produces a 0x-prefixed hex string', () => {
|
|
139
|
-
const out = encodeDepositData({
|
|
140
|
-
signature: SIG_65,
|
|
141
|
-
timestamp: 1_700_000_000_000,
|
|
142
|
-
contractVersion: 1,
|
|
143
|
-
contractType: 'retail',
|
|
144
|
-
});
|
|
145
|
-
expect(out).toMatch(/^0x[0-9a-f]+$/i);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('round-trips through the same ABI tuple', () => {
|
|
149
|
-
const out = encodeDepositData({
|
|
150
|
-
signature: SIG_65,
|
|
151
|
-
timestamp: 1_700_000_000_000,
|
|
152
|
-
contractVersion: 1,
|
|
153
|
-
contractType: 'exempt',
|
|
154
|
-
});
|
|
155
|
-
const [sigOut, tsOut, vtOut] = ethers.utils.defaultAbiCoder.decode(
|
|
156
|
-
['bytes', 'uint256', 'uint256'],
|
|
157
|
-
out,
|
|
158
|
-
) as [string, ethers.BigNumber, ethers.BigNumber];
|
|
159
|
-
expect(sigOut).toBe(SIG_65);
|
|
160
|
-
expect(tsOut.toString()).toBe('1700000000000');
|
|
161
|
-
expect(vtOut.toString()).toBe('257'); // version 1 exempt
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('encodes retail with low-byte 0 and exempt with low-byte 1', () => {
|
|
165
|
-
const vt = (contractType: ContractType): string => {
|
|
166
|
-
const [, , v] = ethers.utils.defaultAbiCoder.decode(
|
|
167
|
-
['bytes', 'uint256', 'uint256'],
|
|
168
|
-
encodeDepositData({
|
|
169
|
-
signature: SIG_65,
|
|
170
|
-
timestamp: 1,
|
|
171
|
-
contractVersion: 1,
|
|
172
|
-
contractType,
|
|
173
|
-
}),
|
|
174
|
-
) as [string, ethers.BigNumber, ethers.BigNumber];
|
|
175
|
-
return v.toString();
|
|
176
|
-
};
|
|
177
|
-
expect(vt('retail')).toBe('256');
|
|
178
|
-
expect(vt('exempt')).toBe('257');
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
describe('formatSignTimestampUtc', () => {
|
|
183
|
-
// 29 July 2026, 08:22:00 UTC.
|
|
184
|
-
const ms = 1785313320000; // 13 digits → milliseconds
|
|
185
|
-
const seconds = 1785313320; // 10 digits → seconds
|
|
186
|
-
|
|
187
|
-
it('formats a millisecond timestamp (>= 13 digits)', () => {
|
|
188
|
-
expect(formatSignTimestampUtc(ms)).toBe('29 July 2026, 08:22');
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('formats a second timestamp (< 13 digits) to the same instant', () => {
|
|
192
|
-
expect(formatSignTimestampUtc(seconds)).toBe('29 July 2026, 08:22');
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it('pads hour/minute but not the day, at a month-boundary midnight', () => {
|
|
196
|
-
// 1 August 2026, 00:05:00 UTC — day non-padded ("1"), minute padded.
|
|
197
|
-
const midnight = Date.UTC(2026, 7, 1, 0, 5, 0);
|
|
198
|
-
expect(formatSignTimestampUtc(midnight)).toBe('1 August 2026, 00:05');
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
describe('buildLoanAgreementSignMessage', () => {
|
|
203
|
-
it('builds the exact 4-line message from a millisecond timestamp', () => {
|
|
204
|
-
expect(
|
|
205
|
-
buildLoanAgreementSignMessage({
|
|
206
|
-
strategyName: 'Taxation Funding (Tax Pay)',
|
|
207
|
-
region: 'Australia',
|
|
208
|
-
optionName: 'Upper Mezzanine',
|
|
209
|
-
amountLabel: '500 AUDD',
|
|
210
|
-
timestamp: 1785313320000,
|
|
211
|
-
}),
|
|
212
|
-
).toBe(
|
|
213
|
-
'Generate my Loan Agreement for review:\n' +
|
|
214
|
-
'Taxation Funding (Tax Pay) · Australia · Upper Mezzanine · 500 AUDD.\n' +
|
|
215
|
-
'Request made 29 July 2026, 08:22 UTC.\n' +
|
|
216
|
-
'This request does not commit me to lend.',
|
|
217
|
-
);
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('builds the identical message from the equivalent second timestamp', () => {
|
|
221
|
-
expect(
|
|
222
|
-
buildLoanAgreementSignMessage({
|
|
223
|
-
strategyName: 'Whole Ledger Funding',
|
|
224
|
-
region: 'Australia',
|
|
225
|
-
optionName: 'Mezzanine',
|
|
226
|
-
amountLabel: '1,260.37 USDC',
|
|
227
|
-
timestamp: 1785313320, // seconds form of the same instant
|
|
228
|
-
}),
|
|
229
|
-
).toBe(
|
|
230
|
-
'Generate my Loan Agreement for review:\n' +
|
|
231
|
-
'Whole Ledger Funding · Australia · Mezzanine · 1,260.37 USDC.\n' +
|
|
232
|
-
'Request made 29 July 2026, 08:22 UTC.\n' +
|
|
233
|
-
'This request does not commit me to lend.',
|
|
234
|
-
);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it('formats a month-boundary/midnight request line', () => {
|
|
238
|
-
expect(
|
|
239
|
-
buildLoanAgreementSignMessage({
|
|
240
|
-
strategyName: 'Professional Fee Funding',
|
|
241
|
-
region: 'Australia',
|
|
242
|
-
optionName: 'Junior',
|
|
243
|
-
amountLabel: '10 USDC',
|
|
244
|
-
timestamp: Date.UTC(2026, 7, 1, 0, 5, 0),
|
|
245
|
-
}),
|
|
246
|
-
).toBe(
|
|
247
|
-
'Generate my Loan Agreement for review:\n' +
|
|
248
|
-
'Professional Fee Funding · Australia · Junior · 10 USDC.\n' +
|
|
249
|
-
'Request made 1 August 2026, 00:05 UTC.\n' +
|
|
250
|
-
'This request does not commit me to lend.',
|
|
251
|
-
);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('separates the line-2 fields with U+00B7 surrounded by single spaces', () => {
|
|
255
|
-
const message = buildLoanAgreementSignMessage({
|
|
256
|
-
strategyName: 'A',
|
|
257
|
-
region: 'B',
|
|
258
|
-
optionName: 'C',
|
|
259
|
-
amountLabel: 'D',
|
|
260
|
-
timestamp: 1785313320000,
|
|
261
|
-
});
|
|
262
|
-
expect(message.split('\n')[1]).toBe('A · B · C · D.');
|
|
263
|
-
expect(message.split('\n')).toHaveLength(4);
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
describe('buildLegacyContractRequestMessage', () => {
|
|
268
|
-
const ADDRESS = '0x4c0d92e9c862B58b0FFeAAD031004A049d2c360D';
|
|
269
|
-
|
|
270
|
-
it('builds the exact legacy template with a lowercased address', () => {
|
|
271
|
-
expect(buildLegacyContractRequestMessage(ADDRESS, 1785313320000)).toBe(
|
|
272
|
-
'I request contract content for ' +
|
|
273
|
-
'0x4c0d92e9c862b58b0ffeaad031004a049d2c360d at 1785313320000.',
|
|
274
|
-
);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
it('is insensitive to the casing the caller hands over', () => {
|
|
278
|
-
expect(buildLegacyContractRequestMessage(ADDRESS, 1)).toBe(
|
|
279
|
-
buildLegacyContractRequestMessage(ADDRESS.toLowerCase(), 1),
|
|
280
|
-
);
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
it('prints the timestamp verbatim — no seconds/ms normalisation', () => {
|
|
284
|
-
// The backend echoes the body's `timestamp` into the string it
|
|
285
|
-
// verifies, so whatever is signed must be what is sent.
|
|
286
|
-
expect(buildLegacyContractRequestMessage(ADDRESS, 1785313320)).toBe(
|
|
287
|
-
'I request contract content for ' +
|
|
288
|
-
'0x4c0d92e9c862b58b0ffeaad031004a049d2c360d at 1785313320.',
|
|
289
|
-
);
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
describe('buildFullNameRequestMessage', () => {
|
|
294
|
-
const ADDRESS = '0x26b5b8060A704b0420734d5Ccd657384fb1366C2';
|
|
295
|
-
|
|
296
|
-
it('builds the exact full-name template with a lowercased address', () => {
|
|
297
|
-
expect(buildFullNameRequestMessage(ADDRESS, 1785313320000)).toBe(
|
|
298
|
-
'I request my full name for ' +
|
|
299
|
-
'0x26b5b8060a704b0420734d5ccd657384fb1366c2 at 1785313320000.',
|
|
300
|
-
);
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
it('is a different message from the contract-content one', () => {
|
|
304
|
-
expect(buildFullNameRequestMessage(ADDRESS, 1)).not.toBe(
|
|
305
|
-
buildLegacyContractRequestMessage(ADDRESS, 1),
|
|
306
|
-
);
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
describe('parseFormattedMessage', () => {
|
|
311
|
-
it('parses the server’s JSON-encoded tree', () => {
|
|
312
|
-
const parsed = parseFormattedMessage(
|
|
313
|
-
JSON.stringify({ intro: 'x', 'subheader-1': { title: 't' } }),
|
|
314
|
-
);
|
|
315
|
-
expect(parsed?.intro).toBe('x');
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
it('returns null on malformed JSON so a renderer can fall back', () => {
|
|
319
|
-
expect(parseFormattedMessage('not json')).toBeNull();
|
|
320
|
-
expect(parseFormattedMessage('')).toBeNull();
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
it('returns null for a JSON scalar, which is not a contract tree', () => {
|
|
324
|
-
expect(parseFormattedMessage('42')).toBeNull();
|
|
325
|
-
expect(parseFormattedMessage('null')).toBeNull();
|
|
326
|
-
expect(parseFormattedMessage('"a string"')).toBeNull();
|
|
327
|
-
});
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
describe('asContractType', () => {
|
|
331
|
-
it('narrows the wire string to the two encoded types', () => {
|
|
332
|
-
expect(asContractType('exempt')).toBe('exempt');
|
|
333
|
-
expect(asContractType('retail')).toBe('retail');
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
it('falls back to retail for anything else', () => {
|
|
337
|
-
// Retail is the stricter contract; an unrecognised type must not be
|
|
338
|
-
// silently treated as the exempt one.
|
|
339
|
-
expect(asContractType('')).toBe('retail');
|
|
340
|
-
expect(asContractType('Exempt')).toBe('retail');
|
|
341
|
-
expect(asContractType('whatever')).toBe('retail');
|
|
342
|
-
});
|
|
343
|
-
});
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
APXIUM,
|
|
3
|
-
getCreditOriginator,
|
|
4
|
-
getInstitutionalLender,
|
|
5
|
-
INVOICEMATE,
|
|
6
|
-
RIXON_CAPITAL,
|
|
7
|
-
} from './partners';
|
|
8
|
-
|
|
9
|
-
// Ported from kasu-ui `src/features/lending/lib/strategy-partners.test.ts`.
|
|
10
|
-
|
|
11
|
-
describe('getCreditOriginator', () => {
|
|
12
|
-
it('maps "Payment Finance (PayFi)" to InvoiceMate', () => {
|
|
13
|
-
expect(getCreditOriginator({ poolName: 'Payment Finance (PayFi)' })).toBe(
|
|
14
|
-
INVOICEMATE,
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('keeps Apxium receivables pools as Apxium (regression: do not match "invoice")', () => {
|
|
19
|
-
// The bug: matching the asset class ("invoice financing") wrongly
|
|
20
|
-
// classified Apxium receivables pools as InvoiceMate. Name-only
|
|
21
|
-
// matching fixes it — none of these names contain payfi/payment
|
|
22
|
-
// finance.
|
|
23
|
-
expect(getCreditOriginator({ poolName: 'Professional Fee Funding' })).toBe(
|
|
24
|
-
APXIUM,
|
|
25
|
-
);
|
|
26
|
-
expect(getCreditOriginator({ poolName: 'Whole Ledger Funding' })).toBe(
|
|
27
|
-
APXIUM,
|
|
28
|
-
);
|
|
29
|
-
expect(
|
|
30
|
-
getCreditOriginator({ poolName: 'Taxation Funding (Tax Pay)' }),
|
|
31
|
-
).toBe(APXIUM);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('is case-insensitive and matches the "payfi" / "payment finance" name', () => {
|
|
35
|
-
expect(getCreditOriginator({ poolName: 'payment finance' })).toBe(
|
|
36
|
-
INVOICEMATE,
|
|
37
|
-
);
|
|
38
|
-
expect(getCreditOriginator({ poolName: 'PAYFI Strategy' })).toBe(
|
|
39
|
-
INVOICEMATE,
|
|
40
|
-
);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('defaults to Apxium for empty / missing names', () => {
|
|
44
|
-
expect(getCreditOriginator({ poolName: '' })).toBe(APXIUM);
|
|
45
|
-
expect(getCreditOriginator({})).toBe(APXIUM);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe('getCreditOriginator — the widened PoolNameSignal', () => {
|
|
50
|
-
it('reads the facade Strategy shape (`name`)', () => {
|
|
51
|
-
expect(getCreditOriginator({ name: 'Payment Finance (PayFi)' })).toBe(
|
|
52
|
-
INVOICEMATE,
|
|
53
|
-
);
|
|
54
|
-
expect(getCreditOriginator({ name: 'Taxation Funding' })).toBe(APXIUM);
|
|
55
|
-
expect(getCreditOriginator({ name: null })).toBe(APXIUM);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('reads a bare string', () => {
|
|
59
|
-
expect(getCreditOriginator('Payment Finance (PayFi)')).toBe(INVOICEMATE);
|
|
60
|
-
expect(getCreditOriginator('Whole Ledger Funding')).toBe(APXIUM);
|
|
61
|
-
expect(getCreditOriginator('')).toBe(APXIUM);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('prefers poolName when an object carries both', () => {
|
|
65
|
-
const both = { poolName: 'Taxation Funding', name: 'Payment Finance' };
|
|
66
|
-
expect(getCreditOriginator(both)).toBe(APXIUM);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('treats an explicitly null poolName as missing, not as a match', () => {
|
|
70
|
-
expect(getCreditOriginator({ poolName: null })).toBe(APXIUM);
|
|
71
|
-
expect(getCreditOriginator({ poolName: undefined })).toBe(APXIUM);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('getInstitutionalLender', () => {
|
|
76
|
-
it('gives Apxium pools Rixon Capital', () => {
|
|
77
|
-
expect(getInstitutionalLender(APXIUM)).toBe(RIXON_CAPITAL);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('gives InvoiceMate pools no senior lender', () => {
|
|
81
|
-
expect(getInstitutionalLender(INVOICEMATE)).toBeNull();
|
|
82
|
-
});
|
|
83
|
-
});
|
package/src/domain/pools.test.ts
DELETED
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
import { PoolOverview, TrancheData } from '../services/DataService/types';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
maxNetRateCeiling,
|
|
5
|
-
pickHighestYieldTranche,
|
|
6
|
-
poolMaxApy,
|
|
7
|
-
selectVisiblePools,
|
|
8
|
-
} from './pools';
|
|
9
|
-
import { netEffectiveApy } from './rates';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Ported from kasu-ui `select-visible-pools.test.ts` and the
|
|
13
|
-
* `pickHighestYieldTranche` / `formatMaxNetRate` cases of
|
|
14
|
-
* `pick-best-tranche.test.ts`. The `formatMaxNetRate` assertions are on the
|
|
15
|
-
* ceiling NUMBER here; their rendered strings stay in kasu-ui.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
function tranche(
|
|
19
|
-
name: string,
|
|
20
|
-
apy: string,
|
|
21
|
-
poolCapacity: string,
|
|
22
|
-
maxApy?: string,
|
|
23
|
-
): TrancheData {
|
|
24
|
-
return { id: name, name, apy, poolCapacity, maxApy } as unknown as TrancheData;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function pool(over: Partial<PoolOverview>): PoolOverview {
|
|
28
|
-
return {
|
|
29
|
-
id: 'p',
|
|
30
|
-
poolName: 'p',
|
|
31
|
-
isActive: true,
|
|
32
|
-
isOversubscribed: false,
|
|
33
|
-
tranches: [tranche('Senior', '0.09', '250000', '0.10')],
|
|
34
|
-
...over,
|
|
35
|
-
} as unknown as PoolOverview;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const withCapacity = (): TrancheData[] => [
|
|
39
|
-
tranche('Senior', '0.09', '250000', '0.10'),
|
|
40
|
-
];
|
|
41
|
-
const noCapacity = (): TrancheData[] => [tranche('Senior', '0.09', '0', '0.10')];
|
|
42
|
-
|
|
43
|
-
/** The live performance fee on all deployments. */
|
|
44
|
-
const FEE = 10;
|
|
45
|
-
|
|
46
|
-
describe('poolMaxApy', () => {
|
|
47
|
-
it('takes the highest usable maxApy across tranches', () => {
|
|
48
|
-
expect(
|
|
49
|
-
poolMaxApy(
|
|
50
|
-
pool({
|
|
51
|
-
tranches: [
|
|
52
|
-
tranche('Senior', '0.09', '1', '0.10'),
|
|
53
|
-
tranche('Junior', '0.12', '1', '0.18'),
|
|
54
|
-
],
|
|
55
|
-
}),
|
|
56
|
-
),
|
|
57
|
-
).toBe(0.18);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('is 0 when nothing is usable', () => {
|
|
61
|
-
expect(poolMaxApy(pool({ tranches: [] }))).toBe(0);
|
|
62
|
-
expect(
|
|
63
|
-
poolMaxApy(pool({ tranches: [tranche('Senior', '0.09', '1', 'x')] })),
|
|
64
|
-
).toBe(0);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe('selectVisiblePools', () => {
|
|
69
|
-
it('drops inactive pools', () => {
|
|
70
|
-
const pools = [
|
|
71
|
-
pool({ id: 'active', isActive: true }),
|
|
72
|
-
pool({ id: 'inactive', isActive: false }),
|
|
73
|
-
];
|
|
74
|
-
expect(selectVisiblePools(pools).map((p) => p.id)).toEqual(['active']);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('drops oversubscribed pools', () => {
|
|
78
|
-
const pools = [
|
|
79
|
-
pool({ id: 'open', isOversubscribed: false }),
|
|
80
|
-
pool({ id: 'full', isOversubscribed: true }),
|
|
81
|
-
];
|
|
82
|
-
expect(selectVisiblePools(pools).map((p) => p.id)).toEqual(['open']);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('sorts pools with capacity ahead of pools without', () => {
|
|
86
|
-
const pools = [
|
|
87
|
-
pool({ id: 'empty', tranches: noCapacity() }),
|
|
88
|
-
pool({ id: 'has-cap', tranches: withCapacity() }),
|
|
89
|
-
];
|
|
90
|
-
expect(selectVisiblePools(pools).map((p) => p.id)).toEqual([
|
|
91
|
-
'has-cap',
|
|
92
|
-
'empty',
|
|
93
|
-
]);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('sorts by highest max APY within the same capacity bucket', () => {
|
|
97
|
-
const pools = [
|
|
98
|
-
pool({
|
|
99
|
-
id: 'low',
|
|
100
|
-
tranches: [tranche('Senior', '0.08', '250000', '0.08')],
|
|
101
|
-
}),
|
|
102
|
-
pool({
|
|
103
|
-
id: 'high',
|
|
104
|
-
tranches: [tranche('Senior', '0.15', '250000', '0.15')],
|
|
105
|
-
}),
|
|
106
|
-
];
|
|
107
|
-
expect(selectVisiblePools(pools).map((p) => p.id)).toEqual([
|
|
108
|
-
'high',
|
|
109
|
-
'low',
|
|
110
|
-
]);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('does not mutate the input array', () => {
|
|
114
|
-
const pools = [
|
|
115
|
-
pool({ id: 'a', tranches: noCapacity() }),
|
|
116
|
-
pool({ id: 'b', tranches: withCapacity() }),
|
|
117
|
-
];
|
|
118
|
-
const before = pools.map((p) => p.id);
|
|
119
|
-
selectVisiblePools(pools);
|
|
120
|
-
expect(pools.map((p) => p.id)).toEqual(before);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
describe('pickHighestYieldTranche', () => {
|
|
125
|
-
const named = (poolName: string, tranches: TrancheData[]): PoolOverview =>
|
|
126
|
-
pool({ id: poolName, poolName, tranches });
|
|
127
|
-
|
|
128
|
-
it('returns null for empty / nullish input', () => {
|
|
129
|
-
expect(pickHighestYieldTranche(undefined)).toBeNull();
|
|
130
|
-
expect(pickHighestYieldTranche(null)).toBeNull();
|
|
131
|
-
expect(pickHighestYieldTranche([])).toBeNull();
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('picks the highest base APY across all pools with capacity', () => {
|
|
135
|
-
const best = pickHighestYieldTranche([
|
|
136
|
-
named('A', [tranche('Junior', '0.12', '5000')]),
|
|
137
|
-
named('B', [
|
|
138
|
-
tranche('Senior', '0.18', '5000'),
|
|
139
|
-
tranche('Mezz', '0.15', '5000'),
|
|
140
|
-
]),
|
|
141
|
-
]);
|
|
142
|
-
expect(best?.pool.poolName).toBe('B');
|
|
143
|
-
expect(best?.tranche.name).toBe('Senior');
|
|
144
|
-
expect(best?.apy).toBeCloseTo(0.18);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('skips tranches without capacity (< 1 unit)', () => {
|
|
148
|
-
const best = pickHighestYieldTranche([
|
|
149
|
-
named('Full', [tranche('Junior', '0.30', '0')]),
|
|
150
|
-
named('Live', [tranche('Senior', '0.10', '2000')]),
|
|
151
|
-
]);
|
|
152
|
-
expect(best?.pool.poolName).toBe('Live');
|
|
153
|
-
expect(best?.apy).toBeCloseTo(0.1);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('breaks APY ties toward more remaining capacity', () => {
|
|
157
|
-
const best = pickHighestYieldTranche([
|
|
158
|
-
named('Small', [tranche('Junior', '0.15', '1000')]),
|
|
159
|
-
named('Big', [tranche('Junior', '0.15', '9000')]),
|
|
160
|
-
]);
|
|
161
|
-
expect(best?.pool.poolName).toBe('Big');
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('ignores zero / non-finite APY values', () => {
|
|
165
|
-
const best = pickHighestYieldTranche([
|
|
166
|
-
named('Zero', [tranche('Junior', '0', '5000')]),
|
|
167
|
-
named('NaN', [tranche('Junior', 'not-a-number', '5000')]),
|
|
168
|
-
named('Real', [tranche('Junior', '0.09', '5000')]),
|
|
169
|
-
]);
|
|
170
|
-
expect(best?.pool.poolName).toBe('Real');
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('reads the BASE rate, not the FTD-widened maxApy', () => {
|
|
174
|
-
// A ceiling claim and a named tranche's rate are different statements.
|
|
175
|
-
const best = pickHighestYieldTranche([
|
|
176
|
-
named('A', [tranche('Junior', '0.12', '5000', '0.30')]),
|
|
177
|
-
named('B', [tranche('Senior', '0.18', '5000', '0.18')]),
|
|
178
|
-
]);
|
|
179
|
-
expect(best?.pool.poolName).toBe('B');
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
describe('maxNetRateCeiling', () => {
|
|
184
|
-
const named = (poolName: string, tranches: TrancheData[]): PoolOverview =>
|
|
185
|
-
pool({ id: poolName, poolName, tranches });
|
|
186
|
-
|
|
187
|
-
it('returns the highest ceiling across all pools, net of the fee', () => {
|
|
188
|
-
const rate = maxNetRateCeiling(
|
|
189
|
-
[
|
|
190
|
-
named('A', [tranche('Junior', '0.12', '5000', '0.18')]),
|
|
191
|
-
named('B', [tranche('Senior', '0.10', '5000', '0.22')]),
|
|
192
|
-
],
|
|
193
|
-
FEE,
|
|
194
|
-
);
|
|
195
|
-
// 0.22 gross → 19.60% net, the same arithmetic as everywhere else.
|
|
196
|
-
expect(rate).toBe(netEffectiveApy(0.22, FEE));
|
|
197
|
-
expect(rate).toBeCloseTo(0.196, 4);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it('prefers the FTD-inclusive maxApy over the base rate', () => {
|
|
201
|
-
// The strategies card's range tops out at maxApy; an "up to" claim
|
|
202
|
-
// quoting the base rate would contradict it on the same screen.
|
|
203
|
-
expect(
|
|
204
|
-
maxNetRateCeiling(
|
|
205
|
-
[named('A', [tranche('Junior', '0.10', '5000', '0.22')])],
|
|
206
|
-
FEE,
|
|
207
|
-
),
|
|
208
|
-
).toBe(netEffectiveApy(0.22, FEE));
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it('falls back to the base rate when a tranche carries no maxApy', () => {
|
|
212
|
-
expect(
|
|
213
|
-
maxNetRateCeiling(
|
|
214
|
-
[named('A', [tranche('Junior', '0.22', '5000')])],
|
|
215
|
-
FEE,
|
|
216
|
-
),
|
|
217
|
-
).toBe(netEffectiveApy(0.22, FEE));
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('skips tranches without capacity — an unreachable rate is not a claim', () => {
|
|
221
|
-
const rate = maxNetRateCeiling(
|
|
222
|
-
[
|
|
223
|
-
named('Full', [tranche('Junior', '0.30', '0', '0.30')]),
|
|
224
|
-
named('Live', [tranche('Senior', '0.10', '5000', '0.10')]),
|
|
225
|
-
],
|
|
226
|
-
FEE,
|
|
227
|
-
);
|
|
228
|
-
expect(rate).toBe(netEffectiveApy(0.1, FEE));
|
|
229
|
-
expect(rate).toBeCloseTo(0.0896, 4);
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it('returns null rather than a gross figure when the fee is out of domain', () => {
|
|
233
|
-
const pools = [named('A', [tranche('Junior', '0.22', '5000', '0.22')])];
|
|
234
|
-
expect(maxNetRateCeiling(pools, 1000)).toBeNull();
|
|
235
|
-
expect(maxNetRateCeiling(pools, -1)).toBeNull();
|
|
236
|
-
expect(maxNetRateCeiling(pools, NaN)).toBeNull();
|
|
237
|
-
// A 100% fee leaves nothing to claim.
|
|
238
|
-
expect(maxNetRateCeiling(pools, 100)).toBeNull();
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it('returns null for empty, nullish or rate-less input', () => {
|
|
242
|
-
expect(maxNetRateCeiling(undefined, FEE)).toBeNull();
|
|
243
|
-
expect(maxNetRateCeiling(null, FEE)).toBeNull();
|
|
244
|
-
expect(maxNetRateCeiling([], FEE)).toBeNull();
|
|
245
|
-
expect(
|
|
246
|
-
maxNetRateCeiling(
|
|
247
|
-
[named('Zero', [tranche('Junior', '0', '5000', '0')])],
|
|
248
|
-
FEE,
|
|
249
|
-
),
|
|
250
|
-
).toBeNull();
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it('agrees with the top of the tranche range it must sit alongside', () => {
|
|
254
|
-
// Both read maxApy through netEffectiveApy; they must not disagree.
|
|
255
|
-
const tranches = [tranche('Senior', '0.14', '5000', '0.22')];
|
|
256
|
-
expect(maxNetRateCeiling([named('A', tranches)], FEE)).toBe(
|
|
257
|
-
netEffectiveApy(0.22, FEE),
|
|
258
|
-
);
|
|
259
|
-
});
|
|
260
|
-
});
|