UNPKG

@orderly.network/default-evm-adapter

Version:

2 lines 5.08 kB
var S=Object.defineProperty,E=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var O=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var I=(s,a,e)=>a in s?S(s,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[a]=e,c=(s,a)=>{for(var e in a||(a={}))O.call(a,e)&&I(s,e,a[e]);if(M)for(var e of M(a))A.call(a,e)&&I(s,e,a[e]);return s},p=(s,a)=>E(s,_(a));var l=(s,a,e)=>(I(s,typeof a!="symbol"?a+"":a,e),e);var g=(s,a,e)=>new Promise((t,n)=>{var i=o=>{try{d(e.next(o))}catch(m){n(m)}},r=o=>{try{d(e.throw(o))}catch(m){n(m)}},d=o=>o.done?t(o.value):Promise.resolve(o.value).then(i,r);d((e=e.apply(s,a)).next())});typeof window!="undefined"&&(window.__ORDERLY_VERSION__=window.__ORDERLY_VERSION__||{},window.__ORDERLY_VERSION__["@orderly.network/default-evm-adapter"]="2.5.3");var R="2.5.3";import{BaseWalletAdapter as T}from"@orderly.network/core";import*as C from"@noble/ed25519";import{encode as N}from"bs58";import{ChainNamespace as K}from"@orderly.network/types";import{definedTypes as u}from"@orderly.network/types";function v(s){return g(this,null,function*(){let{chainId:a,receiver:e,token:t,amount:n,nonce:i,brokerId:r,domain:d}=s,o="Withdraw",m=Date.now(),y={EIP712Domain:u.EIP712Domain,[o]:u[o]},h={brokerId:r,chainId:a,receiver:e,token:t,amount:n,timestamp:m,withdrawNonce:i};return[h,{domain:d,message:h,primaryType:o,types:y}]})}function b(s){return g(this,null,function*(){let{publicKey:a,chainId:e,brokerId:t,expiration:n=365,timestamp:i=Date.now(),scope:r,tag:d,domain:o,subAccountId:m}=s,y="AddOrderlyKey",h=c(c({brokerId:t,orderlyKey:a,scope:r||"read,trading,asset",chainId:e,timestamp:i,expiration:i+1e3*60*60*24*n},typeof d!="undefined"?{tag:d}:{}),typeof m!="undefined"?{subAccountId:m}:{}),f={EIP712Domain:u.EIP712Domain,[y]:u[y]};return[h,{domain:o,message:h,primaryType:y,types:f}]})}function D(s){return g(this,null,function*(){let{chainId:a,domain:e,registrationNonce:t,brokerId:n,timestamp:i}=s,r="Registration",d={brokerId:n,chainId:a,timestamp:i,registrationNonce:t},o={EIP712Domain:u.EIP712Domain,[r]:u[r]};return[d,{domain:e,message:d,primaryType:r,types:o}]})}function P(s){return g(this,null,function*(){let{settlePnlNonce:a,brokerId:e,chainId:t,timestamp:n,domain:i}=s,r="SettlePnl",d={EIP712Domain:u.EIP712Domain,[r]:u[r]},o={brokerId:e,chainId:t,timestamp:n,settleNonce:a};return[o,{domain:i,message:o,primaryType:r,types:d}]})}var w=class extends T{constructor(e){super();this.web3Provider=e;l(this,"chainNamespace",K.evm);l(this,"_address");l(this,"_chainId");l(this,"contractManager")}get address(){return this._address}get chainId(){return this._chainId}set chainId(e){this._chainId=e}setConfig(e){if(this._address=e.address,this._chainId=e.chain.id,e.provider&&(this.web3Provider.provider=e.provider),e.contractManager)this.contractManager=e.contractManager;else throw new Error("Please provide contract manager class")}active(e){this.setConfig(e),this.lifecycleName("active",e)}deactivate(){this.lifecycleName("deactivate",{})}update(e){this.lifecycleName("update",e),this.setConfig(e)}generateSecretKey(){let e,t;do e=C.utils.randomPrivateKey(),t=N(e);while(t.length!==44);return t}lifecycleName(e,t){console.log("lifecycle",e,t)}signTypedData(e){return g(this,null,function*(){return console.log("toSignatureMessage",this.address),yield this.web3Provider.signTypedData(this.address,JSON.stringify(e))})}generateRegisterAccountMessage(e){return g(this,null,function*(){let[t,n]=yield D(p(c({},e),{chainId:this.chainId,domain:this.getDomain()})),i=yield this.signTypedData(n);return{message:p(c({},t),{chainType:"EVM"}),signatured:i}})}generateAddOrderlyKeyMessage(e){return g(this,null,function*(){let[t,n]=yield b(p(c({},e),{chainId:this.chainId,domain:this.getDomain()})),i=yield this.signTypedData(n);return{message:p(c({},t),{chainType:"EVM"}),signatured:i}})}generateWithdrawMessage(e){return g(this,null,function*(){let t=this.getDomain(!0),[n,i]=yield v(p(c({},e),{chainId:this.chainId,domain:t})),r=yield this.signTypedData(i);return{message:p(c({},n),{chainType:"EVM"}),signatured:r,domain:t}})}generateSettleMessage(e){return g(this,null,function*(){let t=this.getDomain(!0),[n,i]=yield P(p(c({},e),{chainId:this.chainId,domain:t})),r=yield this.signTypedData(i);return{message:p(c({},n),{chainType:"EVM"}),signatured:r,domain:t}})}getBalance(){return this.web3Provider.getBalance(this.address)}call(e,t,n,i){return this.web3Provider.call(e,t,n,i)}sendTransaction(e,t,n,i){return this.web3Provider.sendTransaction(e,t,n,i)}callOnChain(e,t,n,i,r){return this.web3Provider.callOnChain(e,t,n,i,r)}getDomain(e){if(!this.web3Provider)throw new Error("web3Provider is undefined");return{name:"Orderly",version:"1",chainId:this.chainId,verifyingContract:e?this.contractManager.getContractInfoByEnv().verifyContractAddress:"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}pollTransactionReceiptWithBackoff(e,t,n,i){return this.web3Provider.pollTransactionReceiptWithBackoff(e,t,n,i)}};export{w as DefaultEVMWalletAdapter,R as version}; //# sourceMappingURL=index.mjs.map