@totemsdk/omnia-lsp-provider 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/NOTICE +60 -0
- package/README.md +85 -2
- package/dist/cjs/host.d.ts +22 -0
- package/dist/cjs/host.js +98 -0
- package/dist/cjs/index.d.ts +8 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/policy.d.ts +39 -0
- package/dist/cjs/policy.js +65 -0
- package/dist/cjs/provider.d.ts +76 -0
- package/dist/cjs/provider.js +64 -0
- package/dist/cjs/quote.d.ts +20 -0
- package/dist/cjs/quote.js +92 -0
- package/dist/host.d.ts +22 -0
- package/dist/host.js +95 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +4 -0
- package/dist/policy.d.ts +39 -0
- package/dist/policy.js +62 -0
- package/dist/provider.d.ts +76 -0
- package/dist/provider.js +61 -0
- package/dist/quote.d.ts +20 -0
- package/dist/quote.js +88 -0
- package/package.json +64 -3
package/dist/quote.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { hashCanonical } from '@totemsdk/core';
|
|
2
|
+
const DECIMAL_SCALE = 18n;
|
|
3
|
+
const DECIMAL_FACTOR = 10n ** DECIMAL_SCALE;
|
|
4
|
+
function decimalKey(value) {
|
|
5
|
+
const [whole = '0', fraction = ''] = value.split('.');
|
|
6
|
+
return (BigInt(whole) * DECIMAL_FACTOR +
|
|
7
|
+
BigInt(fraction.padEnd(Number(DECIMAL_SCALE), '0').slice(0, Number(DECIMAL_SCALE))));
|
|
8
|
+
}
|
|
9
|
+
function formatScaled(value) {
|
|
10
|
+
const negative = value < 0n;
|
|
11
|
+
const absolute = negative ? -value : value;
|
|
12
|
+
const whole = absolute / DECIMAL_FACTOR;
|
|
13
|
+
const fraction = absolute % DECIMAL_FACTOR;
|
|
14
|
+
const fractionText = fraction
|
|
15
|
+
.toString()
|
|
16
|
+
.padStart(Number(DECIMAL_SCALE), '0')
|
|
17
|
+
.replace(/0+$/, '');
|
|
18
|
+
return `${negative ? '-' : ''}${whole.toString()}${fractionText ? `.${fractionText}` : ''}`;
|
|
19
|
+
}
|
|
20
|
+
function applyBps(amount, bps) {
|
|
21
|
+
return formatScaled((decimalKey(amount) * BigInt(bps)) / 10000n);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Build the provider's unsigned open quote. The provider host signs it before
|
|
25
|
+
* returning it to the consumer; a quote without a signature is not authoritative.
|
|
26
|
+
*/
|
|
27
|
+
export function createUnsignedOpenQuote(options) {
|
|
28
|
+
const { manifest, request } = options;
|
|
29
|
+
const now = options.now ?? Date.now();
|
|
30
|
+
const ttlMs = options.ttlMs ?? 60000;
|
|
31
|
+
const expiresAt = now + ttlMs;
|
|
32
|
+
const openFee = manifest.fees.openFlat ??
|
|
33
|
+
(manifest.fees.openBps ? applyBps(request.localAmount, manifest.fees.openBps) : '0');
|
|
34
|
+
const leaseFee = request.lease === true && manifest.fees.leaseBps
|
|
35
|
+
? applyBps(request.localAmount, manifest.fees.leaseBps)
|
|
36
|
+
: undefined;
|
|
37
|
+
const terms = {
|
|
38
|
+
version: 'omnia-lsp/open-terms/v1',
|
|
39
|
+
providerId: manifest.providerId,
|
|
40
|
+
consumerAddress: request.consumerAddress,
|
|
41
|
+
consumerPartyId: request.consumerPartyId,
|
|
42
|
+
consumerPublicKeyDigest: request.consumerPublicKeyDigest,
|
|
43
|
+
consumerSettlementAddress: request.consumerSettlementAddress ?? null,
|
|
44
|
+
consumerTransportPubkey: request.consumerTransportPubkey ?? null,
|
|
45
|
+
tokenId: request.tokenId,
|
|
46
|
+
localAmount: request.localAmount,
|
|
47
|
+
remoteAmount: request.remoteAmount,
|
|
48
|
+
openFee,
|
|
49
|
+
leaseFee: leaseFee ?? null,
|
|
50
|
+
providerPartyId: manifest.channel.partyId,
|
|
51
|
+
providerPublicKeyDigest: manifest.channel.publicKeyDigest,
|
|
52
|
+
providerSettlementAddress: manifest.channel.settlementAddress,
|
|
53
|
+
expiresAt,
|
|
54
|
+
};
|
|
55
|
+
const rawTermsHash = hashCanonical('omnia-lsp:open-terms:v1', terms);
|
|
56
|
+
const termsHash = rawTermsHash.startsWith('0x') ? rawTermsHash : `0x${rawTermsHash}`;
|
|
57
|
+
return {
|
|
58
|
+
version: 'omnia-lsp/open-quote/v1',
|
|
59
|
+
quoteId: options.quoteId ?? `quote-${termsHash.slice(2, 18)}-${now.toString(36)}`,
|
|
60
|
+
providerId: manifest.providerId,
|
|
61
|
+
consumerAddress: request.consumerAddress,
|
|
62
|
+
consumerPartyId: request.consumerPartyId,
|
|
63
|
+
consumerPublicKeyDigest: request.consumerPublicKeyDigest,
|
|
64
|
+
...(request.consumerSettlementAddress
|
|
65
|
+
? { consumerSettlementAddress: request.consumerSettlementAddress }
|
|
66
|
+
: {}),
|
|
67
|
+
...(request.consumerTransportPubkey
|
|
68
|
+
? { consumerTransportPubkey: request.consumerTransportPubkey }
|
|
69
|
+
: {}),
|
|
70
|
+
tokenId: request.tokenId,
|
|
71
|
+
localAmount: request.localAmount,
|
|
72
|
+
remoteAmount: request.remoteAmount,
|
|
73
|
+
openFee,
|
|
74
|
+
...(leaseFee !== undefined ? { leaseFee } : {}),
|
|
75
|
+
providerPartyId: manifest.channel.partyId,
|
|
76
|
+
providerPublicKeyDigest: manifest.channel.publicKeyDigest,
|
|
77
|
+
providerSettlementAddress: manifest.channel.settlementAddress,
|
|
78
|
+
termsHash,
|
|
79
|
+
expiresAt,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Sign an unsigned quote with a provider identity signer. The signer is injected
|
|
84
|
+
* so the package stays runtime-neutral and never holds a private key.
|
|
85
|
+
*/
|
|
86
|
+
export function signOpenQuote(quote, sign) {
|
|
87
|
+
return Promise.resolve(sign(quote)).then((signature) => ({ ...quote, signature }));
|
|
88
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@totemsdk/omnia-lsp-provider",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Reference Omnia Liquidity Service Provider — policy, signed quotes and host adapter",
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
|
+
"types": "dist/cjs/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/cjs/index.d.ts",
|
|
15
|
+
"default": "./dist/cjs/index.js"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"NOTICE"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@totemsdk/core": "^1.6.1",
|
|
27
|
+
"@totemsdk/omnia-lsp": "^0.1.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^20.0.0",
|
|
31
|
+
"typescript": "^7.0.2"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18.0.0"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"license": "Apache-2.0",
|
|
40
|
+
"author": "Totem SDK",
|
|
41
|
+
"homepage": "https://docs.totem.ing",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/Totem-Edge/totem-sdk/issues"
|
|
44
|
+
},
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/Totem-Edge/totem-sdk.git",
|
|
48
|
+
"directory": "packages/omnia-lsp-provider"
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"totem",
|
|
52
|
+
"totemsdk",
|
|
53
|
+
"minima",
|
|
54
|
+
"omnia",
|
|
55
|
+
"lsp",
|
|
56
|
+
"liquidity",
|
|
57
|
+
"provider",
|
|
58
|
+
"channel",
|
|
59
|
+
"onboarding"
|
|
60
|
+
],
|
|
61
|
+
"type": "module",
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "tsc && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', JSON.stringify({type:'commonjs'})+'\\n')\"",
|
|
64
|
+
"clean": "rm -rf dist",
|
|
65
|
+
"test": "jest --config ../../tests/jest/omnia-lsp-provider.cjs"
|
|
66
|
+
}
|
|
6
67
|
}
|